-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Enable passing a CFTimedeltaCoder
to decode_timedelta
#9966
Conversation
Yes, I was just playing around a bit. Please go ahead, @spencerkclark. I'll catch up tomorrow. |
There was a problem hiding this 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.
.. ipython:: python | ||
|
||
coder = xr.coders.CFDatetimeCoder(time_unit="s") | ||
xr.open_dataset("test-timedeltas2.nc", decode_times=coder) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is still some unresolved issue, where we should think about a way forward. At least we could document it, like this:
xr.open_dataset("test-timedeltas2.nc", decode_times=coder) | |
xr.open_dataset("test-timedeltas2.nc", decode_times=coder) | |
To opt-out of timedelta decoding (see issue `Undesired decoding to timedelta64 <https://github.com/pydata/xarray/)issues/1621>`_) pass ``False`` to ``decode_timedelta``: | |
.. ipython:: python | |
xr.open_dataset("test-timedeltas2.nc", decode_times=False) | |
I'm not sure if it would be a good idea to change the default to decode_times=False
in this cycle of changes (as discussed in #1621), but we could at least add a future warning when decode_timedelta=None
. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that is a good idea—thanks for reminding me about that issue. I'll work on an update when I get a chance.
@@ -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): |
There was a problem hiding this comment.
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.
I had some time this weekend so I worked on enabling passing a
CFTimedeltaCoder
todecode_timedelta
inopen_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
fromdecode_times
if nothing was explicitly passed todecode_timedelta
, which is good.whats-new.rst