Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: Adding __array_ufunc__ capability to MaskedArrays #21977

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 4 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/release/upcoming_changes/16022.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MaskedArray gains a ``__array_ufunc__`` method to better handle ufuncs
----------------------------------------------------------------------
The MaskedArray class now has an implementation of `__array_ufunc__` that
handles deferrals to the desired implementations of the ufunc. If a masked
implementation of a ufunc exists, that implementation will take priority.
This means that code called with MaskedArray ma as ``np.ufunc(ma)`` will
behave the same as ``np.ma.ufunc(ma)``. Additionally, adding this helps with
dispatching to subclasses and preserving the proper types when another
implementation should take priority.
2 changes: 1 addition & 1 deletion numpy/lib/tests/test_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def test_subclass(self):
mask=[[False, False], [True, False],
[False, True], [True, True], [False, False]])
out = diff(x)
assert_array_equal(out.data, [[1], [1], [1], [1], [1]])
assert_array_equal(out.data, [[1], [4], [6], [8], [1]])
assert_array_equal(out.mask, [[False], [True],
[True], [True], [False]])
assert_(type(out) is type(x))
Expand Down
Loading