[Numpy-svn] r5606 - in branches/1.1.x/numpy/ma: . tests

numpy-svn@scip... numpy-svn@scip...
Mon Aug 4 13:06:18 CDT 2008


Author: pierregm
Date: 2008-08-04 13:06:12 -0500 (Mon, 04 Aug 2008)
New Revision: 5606

Modified:
   branches/1.1.x/numpy/ma/core.py
   branches/1.1.x/numpy/ma/tests/test_core.py
Log:
core
MaskedArray.__new__: prevents data.mask to change shape and force a copy of _data.mask (cf r5605 on 1.2)

Modified: branches/1.1.x/numpy/ma/core.py
===================================================================
--- branches/1.1.x/numpy/ma/core.py	2008-08-04 18:05:11 UTC (rev 5605)
+++ branches/1.1.x/numpy/ma/core.py	2008-08-04 18:06:12 UTC (rev 5606)
@@ -1197,6 +1197,10 @@
         _data = np.array(data, dtype=dtype, copy=copy, subok=True, ndmin=ndmin)
         _baseclass = getattr(data, '_baseclass', type(_data))
         _basedict = getattr(data, '_basedict', getattr(data, '__dict__', {}))
+        # Check that we'ew not erasing the mask..........
+        if isinstance(data,MaskedArray) and (data.shape != _data.shape):
+            copy = True
+        # Careful, cls might not always be MaskedArray...
         if not isinstance(data, MaskedArray) or not subok:
             _data = _data.view(cls)
         else:
@@ -1215,6 +1219,9 @@
             if copy:
                 _data._mask = _data._mask.copy()
                 _data._sharedmask = False
+                # Reset the shape of the original mask
+                if getmask(data) is not nomask:
+                    data._mask.shape = data.shape
             else:
                 _data._sharedmask = True
         else:

Modified: branches/1.1.x/numpy/ma/tests/test_core.py
===================================================================
--- branches/1.1.x/numpy/ma/tests/test_core.py	2008-08-04 18:05:11 UTC (rev 5605)
+++ branches/1.1.x/numpy/ma/tests/test_core.py	2008-08-04 18:06:12 UTC (rev 5606)
@@ -839,6 +839,14 @@
         assert_equal(x._data,[[1,2,3]])
         assert_equal(x._mask,[[1,0,0]])
     #
+    def test_creation_ndmin_from_maskedarray(self):
+        "Make sure we're not losing the original mask w/ ndmin"
+        x = array([1,2,3])
+        x[-1] = masked
+        xx = array(x, ndmin=2, dtype=float)
+        assert_equal(x.shape, x._mask.shape)
+        assert_equal(xx.shape, xx._mask.shape)
+    #
     def test_record(self):
         "Check record access"
         mtype = [('f',float_),('s','|S3')]



More information about the Numpy-svn mailing list