[Scipy-svn] r2892 - in trunk/Lib/sandbox/maskedarray: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Thu Mar 29 15:08:17 EDT 2007


Author: pierregm
Date: 2007-03-29 14:08:14 -0500 (Thu, 29 Mar 2007)
New Revision: 2892

Modified:
   trunk/Lib/sandbox/maskedarray/core.py
   trunk/Lib/sandbox/maskedarray/tests/test_core.py
Log:
core : prevents collapsing an array to masked when all the data are masked

Modified: trunk/Lib/sandbox/maskedarray/core.py
===================================================================
--- trunk/Lib/sandbox/maskedarray/core.py	2007-03-29 13:05:42 UTC (rev 2891)
+++ trunk/Lib/sandbox/maskedarray/core.py	2007-03-29 19:08:14 UTC (rev 2892)
@@ -1067,6 +1067,7 @@
         """Special hook for ufuncs.
 Wraps the numpy array and sets the mask according to context.
         """
+        #TODO : Should we check for type result 
         result = obj.view(type(self))
         #..........
         if context is not None:
@@ -1085,11 +1086,15 @@
                         m = d
                 else:
                     m |= d
-            result._mask = m
-        if (not m.ndim) and m:
-            return masked
+            if not m.ndim and m:
+                if m:
+                    if result.shape == ():
+                        return masked
+                    result._mask = numeric.ones(result.shape, bool_)
+            else:
+                result._mask = m
         #....
-        result._mask = m
+#        result._mask = m
         result._fill_value = self._fill_value
         result._hardmask = self._hardmask
         result._smallmask = self._smallmask
@@ -2626,33 +2631,42 @@
     from maskedarray.testutils import assert_equal, assert_array_equal
     marray = masked_array
     #
-    if 0:
-        a = arange(10)
-        a[::3] = masked
-        a.fill_value = 999
-        a_pickled = cPickle.loads(a.dumps())
-        assert_equal(a_pickled._mask, a._mask)
-        assert_equal(a_pickled._data, a._data)
-        assert_equal(a_pickled.fill_value, 999)
-        #
-        a = array(numpy.matrix(range(10)), mask=[1,0,1,0,0]*2)
-        a_pickled = cPickle.loads(a.dumps())
-        assert_equal(a_pickled._mask, a._mask)
-        assert_equal(a_pickled, a)
-        assert(isinstance(a_pickled._data,numpy.matrix))
-    #
-    
-    #
     if 1:
-        x = marray(numpy.linspace(-1.,1.,31),)
-        x[:10] = x[-10:] = masked
-        z = marray(numpy.empty((len(x),3), dtype=numpy.float_))
-        z[:,0] = x[:]
-        for i in range(1,3):
-            idx = numpy.arange(len(x))
-            numpy.random.shuffle(idx)
-            z[:,i] = x[idx]
-        #
-        z.sort(0)
-        
+        x = masked_array([1,2])
+        y = x * masked
+        print y
+        assert_equal(y.shape, x.shape)
+        assert_equal(y._mask, [True, True])
+        y = x + masked
+        assert_equal(y.shape, x.shape)
+        assert_equal(y._mask, [True, True])
+#    if 0:
+#        a = arange(10)
+#        a[::3] = masked
+#        a.fill_value = 999
+#        a_pickled = cPickle.loads(a.dumps())
+#        assert_equal(a_pickled._mask, a._mask)
+#        assert_equal(a_pickled._data, a._data)
+#        assert_equal(a_pickled.fill_value, 999)
+#        #
+#        a = array(numpy.matrix(range(10)), mask=[1,0,1,0,0]*2)
+#        a_pickled = cPickle.loads(a.dumps())
+#        assert_equal(a_pickled._mask, a._mask)
+#        assert_equal(a_pickled, a)
+#        assert(isinstance(a_pickled._data,numpy.matrix))
+#    #
+#    
+#    #
+#    if 1:
+#        x = marray(numpy.linspace(-1.,1.,31),)
+#        x[:10] = x[-10:] = masked
+#        z = marray(numpy.empty((len(x),3), dtype=numpy.float_))
+#        z[:,0] = x[:]
+#        for i in range(1,3):
+#            idx = numpy.arange(len(x))
+#            numpy.random.shuffle(idx)
+#            z[:,i] = x[idx]
+#        #
+#        z.sort(0)
+#        
     

Modified: trunk/Lib/sandbox/maskedarray/tests/test_core.py
===================================================================
--- trunk/Lib/sandbox/maskedarray/tests/test_core.py	2007-03-29 13:05:42 UTC (rev 2891)
+++ trunk/Lib/sandbox/maskedarray/tests/test_core.py	2007-03-29 19:08:14 UTC (rev 2892)
@@ -612,6 +612,17 @@
         #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)
         #self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)
     #........................
+    def check_usingmasked(self):
+        "Checks that there's no collapsing to masked"        
+        x = masked_array([1,2])
+        y = x * masked
+        assert_equal(y.shape, x.shape)
+        assert_equal(y._mask, [True, True])
+        y = x + masked
+        assert_equal(y.shape, x.shape)
+        assert_equal(y._mask, [True, True])
+        
+    #........................
     def check_topython(self):
         "Tests some communication issues with Python."
         assert_equal(1, int(array(1)))




More information about the Scipy-svn mailing list