Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore datetime units #241

Merged
merged 7 commits into from
Jan 31, 2024
Merged

Conversation

keewis
Copy link
Collaborator

@keewis keewis commented Jan 31, 2024

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
Copy link

Very nice. Thanks!

@keewis keewis merged commit ddec6ea into xarray-contrib:main Jan 31, 2024
15 checks passed
@keewis keewis deleted the ignore-datetime-units branch January 31, 2024 18:49
@jbusecke
Copy link

jbusecke commented Feb 1, 2024

Ah fantastic. Thanks a lot for implementing this @keewis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

correct_units fails on CMIP6 historical tos data Pint issue for undecoded times
3 participants