diff options
author | pierregm <pierregm@localhost> | 2009-02-10 00:42:40 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2009-02-10 00:42:40 +0000 |
commit | b3e5fdf55bb9a16f8fe78e11b2a9c5f9dd72f5c1 (patch) | |
tree | 31745b92059500adab156e2bacff541f77f7588b /numpy/ma | |
parent | 114c5c609e55f0863a30b1edff7b1c7bf783263f (diff) | |
download | numpy-b3e5fdf55bb9a16f8fe78e11b2a9c5f9dd72f5c1.tar.gz |
* prevent modifications to the mask to be back-propagated w/ __array_wrap__
Diffstat (limited to 'numpy/ma')
-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): |