xarray-contrib / pint-xarray

Interface for using pint with xarray, providing convenience accessors
https://pint-xarray.readthedocs.io/en/latest/
Apache License 2.0
99 stars 12 forks source link

ignore datetime units #241

Closed keewis closed 5 months ago

keewis commented 5 months ago

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).

cc @jbusecke, @TomNicholas, @dcherian

dcherian commented 5 months ago

Very nice. Thanks!

jbusecke commented 5 months ago

Ah fantastic. Thanks a lot for implementing this @keewis