[Numpy-svn] r6352 - in trunk/numpy/ma: . tests

numpy-svn@scip... numpy-svn@scip...
Mon Feb 9 18:42:43 CST 2009


Author: pierregm
Date: 2009-02-09 18:42:40 -0600 (Mon, 09 Feb 2009)
New Revision: 6352

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
* prevent modifications to the mask to be back-propagated w/ __array_wrap__

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2009-02-09 20:18:08 UTC (rev 6351)
+++ trunk/numpy/ma/core.py	2009-02-10 00:42:40 UTC (rev 6352)
@@ -1817,7 +1817,8 @@
                     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

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2009-02-09 20:18:08 UTC (rev 6351)
+++ trunk/numpy/ma/tests/test_core.py	2009-02-10 00:42:40 UTC (rev 6352)
@@ -1025,6 +1025,23 @@
         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):



More information about the Numpy-svn mailing list