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

numpy-svn@scip... numpy-svn@scip...
Mon Feb 23 11:33:18 CST 2009


Author: pierregm
Date: 2009-02-23 11:33:11 -0600 (Mon, 23 Feb 2009)
New Revision: 6463

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
* MaskedArray.__setstate__ : fixed for structured array

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2009-02-23 17:10:02 UTC (rev 6462)
+++ trunk/numpy/ma/core.py	2009-02-23 17:33:11 UTC (rev 6463)
@@ -3846,7 +3846,7 @@
         """
         (ver, shp, typ, isf, raw, msk, flv) = state
         ndarray.__setstate__(self, (shp, typ, isf, raw))
-        self._mask.__setstate__((shp, np.dtype(bool), isf, msk))
+        self._mask.__setstate__((shp, make_mask_descr(typ), isf, msk))
         self.fill_value = flv
     #
     def __reduce__(self):

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2009-02-23 17:10:02 UTC (rev 6462)
+++ trunk/numpy/ma/tests/test_core.py	2009-02-23 17:33:11 UTC (rev 6463)
@@ -369,14 +369,26 @@
         assert_equal(a_pickled._mask, a._mask)
         assert_equal(a_pickled._data, a._data)
         assert_equal(a_pickled.fill_value, 999)
-        #
+
+    def test_pickling_subbaseclass(self):
+        "Test pickling w/ a subclass of ndarray"
+        import cPickle
         a = array(np.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)
         self.failUnless(isinstance(a_pickled._data,np.matrix))
 
+    def test_pickling_wstructured(self):
+        "Tests pickling w/ structured array"
+        import cPickle
+        a = array([(1, 1.), (2, 2.)], mask=[(0, 0), (0, 1)],
+                  dtype=[('a', int), ('b', float)])
+        a_pickled = cPickle.loads(a.dumps())
+        assert_equal(a_pickled._mask, a._mask)
+        assert_equal(a_pickled, a)
 
+
     def test_single_element_subscript(self):
         "Tests single element subscripts of Maskedarrays."
         a = array([1,3,2])



More information about the Numpy-svn mailing list