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

Duck array ops for all and any #9883

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

Conversation

tomwhite
Copy link
Contributor

Another change to use duck_array_ops for some instances of all and any.

  • 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
Copy link
Contributor

With a simple search I see that there's a bunch of .all and .any and the code base that need to be replaced too. Can you handle that too please?

@tomwhite
Copy link
Contributor Author

I updated this to replace more all/any usages. I haven't done all of them: all/any method calls on Dataset, DataArray, or pandas objects should not be changed, and I've left the tests and any files that do not yet use duck_array_ops unchanged.

Copy link
Contributor

@dcherian dcherian left a comment

Choose a reason for hiding this comment

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

Thanks @tomwhite

@@ -204,9 +204,9 @@ def format_items(x):
day_part = x[~pd.isnull(x)].astype("timedelta64[D]").astype("timedelta64[ns]")
time_needed = x[~pd.isnull(x)] != day_part
day_needed = day_part != np.timedelta64(0, "ns")
if np.logical_not(day_needed).all():
if array_all(np.logical_not(day_needed)):
Copy link
Contributor

Choose a reason for hiding this comment

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

surprised we haven't updated the logical_not yet

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could just use

Suggested change
if array_all(np.logical_not(day_needed)):
if array_all(~day_needed):

Or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think ~ is np.invert/xp.bitwise_invert, so possibly different? I'll leave this for a future PR if that's OK.

@dcherian dcherian added the plan to merge Final call for comments label Jan 15, 2025
xarray/core/indexing.py Outdated Show resolved Hide resolved
@@ -204,9 +204,9 @@ def format_items(x):
day_part = x[~pd.isnull(x)].astype("timedelta64[D]").astype("timedelta64[ns]")
time_needed = x[~pd.isnull(x)] != day_part
day_needed = day_part != np.timedelta64(0, "ns")
if np.logical_not(day_needed).all():
if array_all(np.logical_not(day_needed)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could just use

Suggested change
if array_all(np.logical_not(day_needed)):
if array_all(~day_needed):

Or not?

@headtr1ck headtr1ck added the array API standard Support for the Python array API standard label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array API standard Support for the Python array API standard plan to merge Final call for comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants