Skip to content

Backport 1.7 3900 #3904

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 3 commits into from
Oct 13, 2013
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 numpy/ma/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,9 @@ def __call__ (self, a, b, *args, **kwargs):
result = self.f(da, db, *args, **kwargs)
finally:
np.seterr(**err_status_ini)
# check it worked
if result is NotImplemented:
return NotImplemented
# Case 1. : scalar
if not result.ndim:
if m:
Expand Down Expand Up @@ -1005,6 +1008,9 @@ def outer (self, a, b):
return masked
(da, db) = (getdata(a), getdata(b))
d = self.f.outer(da, db)
# check it worked
if d is NotImplemented:
return NotImplemented
if m is not nomask:
np.copyto(d, da, where=m)
if d.shape:
Expand Down Expand Up @@ -1074,6 +1080,9 @@ def __call__(self, a, b, *args, **kwargs):
result = self.f(da, db, *args, **kwargs)
finally:
np.seterr(**err_status_ini)
# check it worked
if result is NotImplemented:
return NotImplemented
# Get the mask as a combination of ma, mb and invalid
m = ~umath.isfinite(result)
m |= ma
Expand Down
21 changes: 21 additions & 0 deletions numpy/ma/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,27 @@ def test_ndarray_mask(self):
assert_equal(test.mask, control.mask)
self.assertTrue(not isinstance(test.mask, MaskedArray))

def test_treatment_of_NotImplemented(self):
"Check any NotImplemented returned by umath.<ufunc> is passed on"
a = masked_array([1., 2.], mask=[1, 0])
# basic tests for _MaskedBinaryOperation
assert_(a.__mul__('abc') is NotImplemented)
assert_(multiply.outer(a, 'abc') is NotImplemented)
# and for _DomainedBinaryOperation
assert_(a.__div__('abc') is NotImplemented)

# also check explicitly that rmul of another class can be accessed
class MyClass(str):
def __mul__(self, other):
return "My mul"

def __rmul__(self, other):
return "My rmul"

me = MyClass()
assert_(me * a == "My mul")
assert_(a * me == "My rmul")

#------------------------------------------------------------------------------

class TestMaskedArrayInPlaceArithmetics(TestCase):
Expand Down