[Numpy-svn] r6353 - in branches/1.2.x/numpy/ma: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Feb 9 19:49:42 EST 2009
Author: pierregm
Date: 2009-02-09 18:49:40 -0600 (Mon, 09 Feb 2009)
New Revision: 6353
Modified:
branches/1.2.x/numpy/ma/core.py
branches/1.2.x/numpy/ma/tests/test_core.py
Log:
*backporting bugfix r6352
Modified: branches/1.2.x/numpy/ma/core.py
===================================================================
--- branches/1.2.x/numpy/ma/core.py 2009-02-10 00:42:40 UTC (rev 6352)
+++ branches/1.2.x/numpy/ma/core.py 2009-02-10 00:49:40 UTC (rev 6353)
@@ -1598,7 +1598,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: branches/1.2.x/numpy/ma/tests/test_core.py
===================================================================
--- branches/1.2.x/numpy/ma/tests/test_core.py 2009-02-10 00:42:40 UTC (rev 6352)
+++ branches/1.2.x/numpy/ma/tests/test_core.py 2009-02-10 00:49:40 UTC (rev 6353)
@@ -825,6 +825,25 @@
self.failUnless(result is output)
self.failUnless(output[0] is masked)
+
+
+ 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