Uh oh!
There was an error while loading. Please reload this page.
Relax nanosecond datetime restriction in CF time decoding - #9618
Conversation
kmuehlbauer
commented
Oct 14, 2024
Nice, mypy 1.12 is out and breaks our typing, 😭. |
TomNicholas
commented
Oct 14, 2024
Can we pin it in the CI temporarily? |
kmuehlbauer
commented
Oct 14, 2024
Yes, 1.11.2 was the last version. |
ca5050d to
f7396cfComparekmuehlbauer
commented
Oct 14, 2024
This is now ready for a first round of review. I think this is already in a quite usable state. But no rush, this should be thoroughly tested. |
spencerkclark
commented
Oct 18, 2024
Sounds good @kmuehlbauer! I’ll try and take an initial look this weekend. |
…ore/variable.py to use any-precision datetime/timedelta with autmatic inferring of resolution
…ocessing, raise now early
…t resolution, fix code and tests to allow this
* Fix timedelta encoding overflow issue; always decode to ns resolution * Implement time_unit for decode_cf_timedelta * Reduce diff
kmuehlbauer
commented
Jan 13, 2025
Thanks again @spencerkclark! I've merged your kmuehlbauer#3 as it is essential for this PR to keep consistency and backwards compatibility. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Kai Mühlbauer <kmuehlbauer@wradlib.org>
kmuehlbauer
commented
Jan 15, 2025
Failing CI looks unrelated. Decision in the dev meeting was to merge fast to have a bit of time to test before release later this month. |
kmuehlbauer
commented
Jan 15, 2025
Thanks All! 🚀 |
spencerkclark
commented
Jan 16, 2025
Awesome, congrats @kmuehlbauer—thank you! |
ilan-gold
commented
Jan 16, 2025
Yes @kmuehlbauer - monumental effort!!! |
dcherian
commented
Jan 16, 2025
Amazing! 👏 👏 👏 |
* main: (79 commits) fix mean for datetime-like using the respective time resolution unit (#9977) Add `time_unit` argument to `CFTimeIndex.to_datetimeindex` (#9965) remove gate and add a test (#9958) Remove repetitive that (replace it with the) (#9994) add shxarray to the xarray ecosystem list (#9995) Add `shards` to `valid_encodings` to enable sharded Zarr writing (#9948) Use flox for grouped first, last (#9986) Bump the actions group with 2 updates (#9989) Fix some typing (#9988) Remove unnecessary a article (#9980) Fix test_doc_example on big-endian systems (#9949) fix weighted polyfit for arrays with more than 2 dimensions (#9974) Use zarr-fixture to prevent thread leakage errors (#9967) remove dask-expr from CI runs, fix related tests (#9971) Update time coding tests to assert exact equality (#9961) cast type to PDDatetimeUnitOptions (#9963) Suggest the correct name when no key matches in the dataset (#9943) fix upstream dev issues (#9953) Relax nanosecond datetime restriction in CF time decoding (#9618) Remove outdated quantile test. (#9945) ...
* main: (79 commits) fix mean for datetime-like using the respective time resolution unit (#9977) Add `time_unit` argument to `CFTimeIndex.to_datetimeindex` (#9965) remove gate and add a test (#9958) Remove repetitive that (replace it with the) (#9994) add shxarray to the xarray ecosystem list (#9995) Add `shards` to `valid_encodings` to enable sharded Zarr writing (#9948) Use flox for grouped first, last (#9986) Bump the actions group with 2 updates (#9989) Fix some typing (#9988) Remove unnecessary a article (#9980) Fix test_doc_example on big-endian systems (#9949) fix weighted polyfit for arrays with more than 2 dimensions (#9974) Use zarr-fixture to prevent thread leakage errors (#9967) remove dask-expr from CI runs, fix related tests (#9971) Update time coding tests to assert exact equality (#9961) cast type to PDDatetimeUnitOptions (#9963) Suggest the correct name when no key matches in the dataset (#9943) fix upstream dev issues (#9953) Relax nanosecond datetime restriction in CF time decoding (#9618) Remove outdated quantile test. (#9945) ...
In #9618 we allowed encoding `np.datetime64` values prior to 1582-10-15 using a `"standard"` or `"gregorian"` calendar through cftime. While technically possible, this implicitly introduces a calendar change, and means the values can no longer be round tripped as `np.datetime64`—xarray will choose `cftime.DatetimeGregorian` instances when decoding instead. I am not sure how often this will come up and the behavior may not be the user's intent. This PR switches to raising a `ValueError` in this circumstance, and recommends encoding with a `"proleptic_gregorian"` calendar instead (the calendar that xarray automatically chooses for `np.datetime64` values if provided no user input).
* main: (79 commits) fix mean for datetime-like using the respective time resolution unit (pydata#9977) Add `time_unit` argument to `CFTimeIndex.to_datetimeindex` (pydata#9965) remove gate and add a test (pydata#9958) Remove repetitive that (replace it with the) (pydata#9994) add shxarray to the xarray ecosystem list (pydata#9995) Add `shards` to `valid_encodings` to enable sharded Zarr writing (pydata#9948) Use flox for grouped first, last (pydata#9986) Bump the actions group with 2 updates (pydata#9989) Fix some typing (pydata#9988) Remove unnecessary a article (pydata#9980) Fix test_doc_example on big-endian systems (pydata#9949) fix weighted polyfit for arrays with more than 2 dimensions (pydata#9974) Use zarr-fixture to prevent thread leakage errors (pydata#9967) remove dask-expr from CI runs, fix related tests (pydata#9971) Update time coding tests to assert exact equality (pydata#9961) cast type to PDDatetimeUnitOptions (pydata#9963) Suggest the correct name when no key matches in the dataset (pydata#9943) fix upstream dev issues (pydata#9953) Relax nanosecond datetime restriction in CF time decoding (pydata#9618) Remove outdated quantile test. (pydata#9945) ...
whats-new.rstThis is another attempt to resolve#7493. This goes a step further than #9580.
The idea of this PR is to automatically infer the needed resolutions for decoding/
encodingand only keep the constraints pandas imposes ("s" - lowest resolution, "ns" - highest resolution). There is still the idea of adefault resolution, but this should only take precedence if it doesn't clash with the automatic inference. This can be discussed, though. Update: I've implementedtime-unit-kwarga first try to have default resolutionon decode, which will override the current inferred resolution only to higher resolution (eg.'s'->'ns'). To work towards #4490 the time decoding options (decode_timeanduse_cftimeare bundled withinCFDatetimeCoderwhich is distributed viadecode_timeskwarg.use_cftime-kwarg is deprecated.For sanity checking, and also for my own good, I've created a documentation page on time-coding in the internal dev section. Any suggestions (especially grammar) or ideas for enhancements are much appreciated.
There still might be room for consolidation of functions/methods (mostly in coding/times.py), but I have to leave it alone for some days. I went down that rabbit hole and need to relax, too 😬.
Looking forward to get your insights here, @spencerkclark, @ChrisBarker-NOAA, @pydata/xarray.
Todo:
time_units(where appropriate)CFDatetimeCoderas input fordecode_timeskwarg