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

Enable clip broadcasting, with apply_ufunc #5184

Merged
merged 11 commits into from
Apr 21, 2021
Merged

Conversation

max-sixty
Copy link
Collaborator

@max-sixty max-sixty commented Apr 18, 2021

  • Closes Clip broadcasts min or max array input #5173
  • Tests added
  • Passes pre-commit run --all-files
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • Add docstring
  • Confirm apply_ufunc args, like join

I think this is the right approach — we may need to confirm the appropriate args to apply_ufunc — probably we want the same as .where?

Tests are OK but a bit lacking atm.

xarray/core/variable.py Outdated Show resolved Hide resolved
xarray/core/common.py Outdated Show resolved Hide resolved
xarray/tests/test_dataarray.py Show resolved Hide resolved
@max-sixty
Copy link
Collaborator Author

The tests are in a reasonable state — not perfect — but maybe good enough to proceed. Are there any cases that are missing currently?

@@ -1665,6 +1665,11 @@ def fillna(self, value):
def where(self, cond, other=dtypes.NA):
return ops.where_method(self, cond, other)

def clip(self, min=None, max=None):
Copy link
Collaborator Author

@max-sixty max-sixty Apr 19, 2021

Choose a reason for hiding this comment

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

I wonder whether there should be a class that DataArray & Variable should inherit from (but not AbstractArray) where they share methods.

I don't think there's enough overlap to justify it at the moment, but worth considering. That may mean we could unify the tests, which are currently highly duplicated for clip for example.

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.

Looks good to me though dask tests are missing. We can add them in a future PR if you don't want to do it now.

xarray/tests/test_dataarray.py Show resolved Hide resolved
xarray/tests/test_dataarray.py Outdated Show resolved Hide resolved
Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
@pep8speaks
Copy link

pep8speaks commented Apr 19, 2021

Hello @max-sixty! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-04-19 18:17:58 UTC

@max-sixty
Copy link
Collaborator Author

Looks good to me though dask tests are missing. We can add them in a future PR if you don't want to do it now.

They're there! The magic of fixtures is da is attempted with both a dask and numpy backend: https://github.com/pydata/xarray/pull/5184/files#diff-ca5c2de2fe6e9e25fbf22bd53e4976c15da74900dfb14deb7e6e87f5377230e3R6438

Does that make sense, assuming I'm not missing anything? Too magical?

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