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

Enable passing a CFTimedeltaCoder to decode_timedelta #9966

Merged
merged 18 commits into from
Jan 29, 2025

Conversation

spencerkclark
Copy link
Member

I had some time this weekend so I worked on enabling passing a CFTimedeltaCoder to decode_timedelta in open_dataset et al.

@kmuehlbauer I didn't realize until this morning that you had started on this too in your fork (branch)—I was able to make a simplification to the dtype inference code I originally had based on looking at your initial work. I'm posting this here, since it seems a little further along than your branch, but feel free to supersede this PR with one of your own if you have un-pushed progress. I listed this PR in the same what's new entry as #9618, since it seemed natural, and gives us both credit.

It looks like we were fairly aligned though in terms of inheriting the time_unit from decode_times if nothing was explicitly passed to decode_timedelta, which is good.

  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst

@kmuehlbauer
Copy link
Contributor

Yes, I was just playing around a bit. Please go ahead, @spencerkclark. I'll catch up tomorrow.

Copy link
Contributor

@kmuehlbauer kmuehlbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @spencerkclark! One suggestion for adding a FutureWarning and explicit mention of decode_times=False in the docs.

doc/internals/time-coding.rst Show resolved Hide resolved
@@ -171,7 +173,10 @@ def decode_cf_variable(
original_dtype = var.dtype

if decode_timedelta is None:
decode_timedelta = True if decode_times else False
if isinstance(decode_times, CFDatetimeCoder):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we could add a FutureWarning, that decode_timedelta=None will default to decode_timedelta=False. See #1621.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the one thing that is kind of awkward about this is that it will warn when anyone calls open_dataset, even if there are no timedelta-like variables in the dataset. Would it make sense to limit the warning to only when timedelta variables are decoded and decode_timedelta was None?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, It would be reasonable to reduce the noise for unaffected users. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a try in 3a96c8a—let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for the quick response!

@kmuehlbauer
Copy link
Contributor

@spencerkclark Any chance to get this over the finish line until Friday? Otherwise we should think about postponing the release date of the non-nanosecond refactoring into February.

@dcherian beside this PR there is one more PR (#9999) which is connected to non-nanosecond and should go in before a release. WDYT, is it manageable to release until Friday?

xarray/conventions.py Outdated Show resolved Hide resolved
@dcherian
Copy link
Contributor

@kmuehlbauer I think you should handle the release :)

beside this PR there is one more PR (#9999) which is connected to non-nanosecond and should go in before a release.

For this kind of coordination it's nice to open a release tracking issue so that anyone who isn't paying attention to this PR knows about it.

@kmuehlbauer
Copy link
Contributor

Thanks @spencerkclark! Merging as needed for #10002-

@kmuehlbauer kmuehlbauer merged commit d475036 into pydata:main Jan 29, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants