diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/ma/core.py | 3 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 17 |
2 files changed, 19 insertions, 1 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 90c74d9c1..29c02573a 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -1817,7 +1817,8 @@ class MaskedArray(ndarray): if d is not nomask: m = d else: - m |= d + # Don't modify inplace, we risk back-propagation + m = (m | d) # Make sure the mask has the proper size if result.shape == () and m: return masked diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index c92c650b4..59acf6cfe 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -1025,6 +1025,23 @@ class TestMaskedArrayArithmetic(TestCase): assert_equal(test.mask, [False, False]) + def test_numpyarithmetics(self): + "Check that the mask is not back-propagated when using numpy functions" + a = masked_array([-1, 0, 1, 2, 3], mask=[0, 0, 0, 0, 1]) + control = masked_array([np.nan, np.nan, 0, np.log(2), -1], + mask=[1, 1, 0, 0, 1]) + # + test = log(a) + assert_equal(test, control) + assert_equal(test.mask, control.mask) + assert_equal(a.mask, [0, 0, 0, 0, 1]) + # + test = np.log(a) + assert_equal(test, control) + assert_equal(test.mask, control.mask) + assert_equal(a.mask, [0, 0, 0, 0, 1]) + # + #------------------------------------------------------------------------------ class TestMaskedArrayAttributes(TestCase): |