Skip to content

Use to_numpy in time decoding #10081

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

Merged
merged 10 commits into from
Mar 13, 2025
Merged

Conversation

dcherian
Copy link
Contributor

@dcherian dcherian commented Feb 27, 2025

This is the smallest set of changes I could find to make our time decoding handle duck arrays. Really we just explicitly convert to numpy arrays using to_numpy. Note that the cftime code path uses Cython, and so, it requires numpy

The second (now-reverted) commit makes more invasive changes to avoid the numpy conversion if we can. I think it's best saved for a different PR.

cc @TomAugspurger

  • Closes #xxxx
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

@dcherian dcherian force-pushed the duck-datetime-decoding branch from c911894 to f69ba29 Compare February 27, 2025 17:25
Copy link
Member

@spencerkclark spencerkclark left a comment

Choose a reason for hiding this comment

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

Nice, thanks @dcherian—not sure if you were looking for a review yet, but these changes look reasonable to me.

@dcherian dcherian changed the title Use to_numpy in time decoding Use to_numpy in time decoding Mar 3, 2025
@dcherian
Copy link
Contributor Author

dcherian commented Mar 3, 2025

Thanks for the review @spencerkclark

This just makes explicitly convert to numpy. Fully migrating to using duck arrays was more invasive and would conflict with existing PRs, so let's do that later.

@dcherian dcherian requested a review from keewis March 4, 2025 17:52
@dcherian dcherian enabled auto-merge (squash) March 13, 2025 13:20
@dcherian dcherian merged commit 1e1938f into pydata:main Mar 13, 2025
30 checks passed
@dcherian dcherian deleted the duck-datetime-decoding branch March 18, 2025 13:25
@dcherian dcherian restored the duck-datetime-decoding branch March 18, 2025 13:25
dcherian added a commit to dcherian/xarray that referenced this pull request Mar 19, 2025
* main: (67 commits)
  Refactor datetime and timedelta encoding for increased robustness (pydata#9498)
  Fix test_distributed::test_async (pydata#10138)
  Refactor concat / combine / merge into `xarray/structure` (pydata#10134)
  Split `apply_ufunc` out of `computation.py` (pydata#10133)
  Refactor modules from `core` into `xarray.computation` (pydata#10132)
  Refactor compatibility modules into xarray.compat package (pydata#10131)
  Fix type issues from pandas stubs (pydata#10128)
  Don't skip tests when on a `mypy` branch (pydata#10129)
  Change `python_files` in `pyproject.toml` to a list (pydata#10127)
  Better `uv` compatibility (pydata#10124)
  explicitly cast the dtype of `where`'s condition parameter to `bool` (pydata#10087)
  Use `to_numpy` in time decoding (pydata#10081)
  Pin pandas stubs (pydata#10119)
  Fix broken Zarr test (pydata#10109)
  Update asv badge url in README.md (pydata#10113)
  fix and supress some test warnings (pydata#10104)
  Improve handling of dtype and NaT when encoding/decoding masked and packaged datetimes and timedeltas (pydata#10050)
  Ensure KeyError raised for zarr datasets missing dim names (pydata#10025)
  Add typos check to pre-commit hooks (pydata#10040)
  Bump codecov/codecov-action from 5.3.1 to 5.4.0 in the actions group (pydata#10090)
  ...
dcherian added a commit to dcherian/xarray that referenced this pull request Mar 19, 2025
* main: (85 commits)
  Adds open_datatree and load_datatree to the tutorial module (pydata#10082)
  Fix version in requires_zarr_v3 fixture (pydata#10145)
  Fix `open_datatree` when `decode_cf=False` (pydata#10141)
  [docs] `DataTree` cannot be constructed from `DataArray` (pydata#10142)
  Refactor datetime and timedelta encoding for increased robustness (pydata#9498)
  Fix test_distributed::test_async (pydata#10138)
  Refactor concat / combine / merge into `xarray/structure` (pydata#10134)
  Split `apply_ufunc` out of `computation.py` (pydata#10133)
  Refactor modules from `core` into `xarray.computation` (pydata#10132)
  Refactor compatibility modules into xarray.compat package (pydata#10131)
  Fix type issues from pandas stubs (pydata#10128)
  Don't skip tests when on a `mypy` branch (pydata#10129)
  Change `python_files` in `pyproject.toml` to a list (pydata#10127)
  Better `uv` compatibility (pydata#10124)
  explicitly cast the dtype of `where`'s condition parameter to `bool` (pydata#10087)
  Use `to_numpy` in time decoding (pydata#10081)
  Pin pandas stubs (pydata#10119)
  Fix broken Zarr test (pydata#10109)
  Update asv badge url in README.md (pydata#10113)
  fix and supress some test warnings (pydata#10104)
  ...
weiji14 added a commit to xarray-contrib/cupy-xarray that referenced this pull request Mar 21, 2025
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.

3 participants