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

Use to_numpy in time decoding #10081

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

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
@@ -102,6 +102,10 @@ def to_numpy(
from xarray.core.indexing import ExplicitlyIndexed
from xarray.namedarray.parallelcompat import get_chunked_array_type

if hasattr(data, "to_numpy"):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the ugly bit. It's only to test that we are using the to_numpy method instead of np.asarray which would fail for cupy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@keewis does this seem OK to you?

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
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.

2 participants