The cf conventions use units that follow the structure of {time_units} since {date} to encode calendar dates to numeric arrays (integers / floats). When xarraydecodes datasets, it uses these datetime units to convert the numeric arrays to datetime arrays (and the other way around when encoding).
However, these datetime units can still be on variables, for example if a user sets decode_times=False. In that case, we would pick up those units and try to parse them, only to fail immediately because pint cannot understand them (nor should it).
This PR makes extract_unit_attributes and strip_unit_attributes skip any of these units, making it seem as if the units attribute didn't exist / was None (the attribute will still be there, though).
The cf conventions use units that follow the structure of
{time_units} since {date}
to encode calendar dates to numeric arrays (integers / floats). Whenxarray
decodes datasets, it uses these datetime units to convert the numeric arrays to datetime arrays (and the other way around when encoding).However, these datetime units can still be on variables, for example if a user sets
decode_times=False
. In that case, we would pick up those units and try to parse them, only to fail immediately becausepint
cannot understand them (nor should it).This PR makes
extract_unit_attributes
andstrip_unit_attributes
skip any of these units, making it seem as if theunits
attribute didn't exist / wasNone
(the attribute will still be there, though).cc @jbusecke, @TomNicholas, @dcherian
pre-commit run --all-files
whats-new.rst