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

numpy-svn@scip... numpy-svn@scip...
Tue Feb 10 19:52:32 CST 2009


Author: pierregm
Date: 2009-02-10 19:51:28 -0600 (Tue, 10 Feb 2009)
New Revision: 6356

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
* MaskedArray.__array_wrap__ : forces the domain (if any) to a ndarray (fill with True)

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2009-02-10 10:57:41 UTC (rev 6355)
+++ trunk/numpy/ma/core.py	2009-02-11 01:51:28 UTC (rev 6356)
@@ -1796,10 +1796,11 @@
             # Get the domain mask................
             domain = ufunc_domain.get(func, None)
             if domain is not None:
+                # Take the domain, and make sure it's a ndarray
                 if len(args) > 2:
-                    d = reduce(domain, args)
+                    d = filled(reduce(domain, args), True)
                 else:
-                    d = domain(*args)
+                    d = filled(domain(*args), True)
                 # Fill the result where the domain is wrong
                 try:
                     # Binary domain: take the last value

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2009-02-10 10:57:41 UTC (rev 6355)
+++ trunk/numpy/ma/tests/test_core.py	2009-02-11 01:51:28 UTC (rev 6356)
@@ -1040,7 +1040,6 @@
         assert_equal(test, control)
         assert_equal(test.mask, control.mask)
         assert_equal(a.mask, [0, 0, 0, 0, 1])
-        #
 
 #------------------------------------------------------------------------------
 
@@ -1375,7 +1374,17 @@
         self.failUnless(amask.max(1)[0].mask)
         self.failUnless(amask.min(1)[0].mask)
 
+    def test_ndarray_mask(self):
+        "Check that the mask of the result is a ndarray (not a MaskedArray...)"
+        a = masked_array([-1, 0, 1, 2, 3], mask=[0, 0, 0, 0, 1])
+        test = np.sqrt(a)
+        control = masked_array([-1, 0, 1, np.sqrt(2), -1],
+                          mask=[1, 0, 0, 0, 1])
+        assert_equal(test, control)
+        assert_equal(test.mask, control.mask)
+        self.failUnless(not isinstance(test.mask, MaskedArray))
 
+
 #------------------------------------------------------------------------------
 
 class TestMaskedArrayInPlaceArithmetics(TestCase):



More information about the Numpy-svn mailing list