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

numpy-svn@scip... numpy-svn@scip...
Sat Sep 13 16:17:11 CDT 2008


Author: pierregm
Date: 2008-09-13 16:17:09 -0500 (Sat, 13 Sep 2008)
New Revision: 5824

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
MaskedArray.__new__ : make sure that we inherit the _hardmask from data (if any) instead of reverting to default.

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2008-09-13 18:15:38 UTC (rev 5823)
+++ trunk/numpy/ma/core.py	2008-09-13 21:17:09 UTC (rev 5824)
@@ -1234,7 +1234,7 @@
 
     def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,
                 subok=True, ndmin=0, fill_value=None,
-                keep_mask=True, hard_mask=False, flag=None, shrink=True,
+                keep_mask=True, hard_mask=None, flag=None, shrink=True,
                 **options):
         """Create a new masked array from scratch.
 
@@ -1338,7 +1338,10 @@
         if fill_value is not None:
             _data._fill_value = _check_fill_value(fill_value, _data.dtype)
         # Process extra options ..
-        _data._hardmask = hard_mask
+        if hard_mask is None:
+            _data._hardmask = getattr(data, '_hardmask', False)
+        else:
+            _data._hardmask = hard_mask
         _data._baseclass = _baseclass
         return _data
     #

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2008-09-13 18:15:38 UTC (rev 5823)
+++ trunk/numpy/ma/tests/test_core.py	2008-09-13 21:17:09 UTC (rev 5824)
@@ -173,10 +173,12 @@
     def test_asarray(self):
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         xm.fill_value = -9999
+        xm._hardmask = True
         xmm = asarray(xm)
         assert_equal(xmm._data, xm._data)
         assert_equal(xmm._mask, xm._mask)
         assert_equal(xmm.fill_value, xm.fill_value)
+        assert_equal(xmm._hardmask, xm._hardmask)
 
     def test_fix_invalid(self):
         "Checks fix_invalid."



More information about the Numpy-svn mailing list