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

ENH: Adding __array_ufunc__ capability to MaskedArrays (again) #22914

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ab732d0
ENH: Adding __array_ufunc__ capability to MaskedArrays.
greglucas Apr 15, 2020
63df460
DOC: Adding improvement note for MaskedArray ufunc
greglucas Apr 14, 2021
a63e97a
nomask in nomask out
rcomer Jul 13, 2022
eca1e3c
BUG: fix ma.minimum.reduce with axis keyword
rcomer Jul 16, 2022
997d27d
TST: add a test for ma.minimum.reduce with axis keyword
rcomer Jul 16, 2022
bd091a6
MNT: Remove __add__ and other unnecessary overrides
greglucas Jul 23, 2022
b5b9ad3
ENH: Add sign ufunc to masked arrays
greglucas Jul 23, 2022
d0ac064
ENH: Remove masked ufunc power restriction
greglucas Jul 23, 2022
dd74620
ENH: Add masked invert ufunc
greglucas Jul 23, 2022
c638cdc
MNT: Remove some restrictions on masked array ufunc implementations
greglucas Jul 23, 2022
b35c309
FIX: Rearrange handling of ndarray-like ufuncs
greglucas Jul 24, 2022
de22beb
FIX: Pass kwargs through ufunc reduce
greglucas Jul 24, 2022
9564f27
MNT: Add power ufunc to masked arrays
greglucas Jul 24, 2022
a7ba76f
FIX: add back getmaskarray to __array_wrap__ of masked arrays
greglucas Jul 24, 2022
fa6c56f
FIX: view should return the type(self) rather than MaskedArray
greglucas Jul 24, 2022
cbfd86f
FIX: Revert sum and trace overrides from masked arrays
greglucas Jul 24, 2022
4a58583
ENH: Add rint and update round method
greglucas Jul 24, 2022
2acf530
FIX: Change back partition/argpartition
greglucas Jul 24, 2022
e6e80e6
FIX: Remove compress updates
greglucas Jul 24, 2022
366dfc3
MAINT: Remove unused delegate_binop code
greglucas Jan 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/release/upcoming_changes/22914.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.
6 changes: 0 additions & 6 deletions numpy/core/src/common/binop_override.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ binop_should_defer(PyObject *self, PyObject *other, int inplace)
* logic for forward binop implementations.
*/

/*
* NB: there's another copy of this code in
* numpy.ma.core.MaskedArray._delegate_binop
* which should possibly be updated when this is.
*/

PyObject *attr;
double self_prio, other_prio;
int defer;
Expand Down
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 @@ -786,7 +786,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