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

numpy-svn at scipy.org numpy-svn at scipy.org
Sun Apr 20 18:58:25 EDT 2008


Author: pierregm
Date: 2008-04-20 17:58:22 -0500 (Sun, 20 Apr 2008)
New Revision: 5056

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/mrecords.py
   trunk/numpy/ma/tests/test_core.py
Log:
mrecords: clean-up
core: MaskedArray.__setitem__ : when hardmask is False, force the data to be updated before the mask.
core: MaskedArray.round_ : fixed to keep the dates on TimeSeries
core: round : simplified

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2008-04-20 11:49:35 UTC (rev 5055)
+++ trunk/numpy/ma/core.py	2008-04-20 22:58:22 UTC (rev 5056)
@@ -1363,17 +1363,22 @@
             return
         #....
         dval = narray(value, copy=False, dtype=self.dtype)
-        valmask = getmask(value)
+        valmask = getmask(value)        
         if self._mask is nomask:
+            # Set the data, then the mask
+            ndarray.__setitem__(self._data,indx,dval)
             if valmask is not nomask:
                 self._mask = numpy.zeros(self.shape, dtype=MaskType)
                 self._mask[indx] = valmask
         elif not self._hardmask:
             # Unshare the mask if necessary to avoid propagation
             self.unshare_mask()
+            # Set the data, then the mask
+            ndarray.__setitem__(self._data,indx,dval)
             self._mask[indx] = valmask
         elif hasattr(indx, 'dtype') and (indx.dtype==bool_):
             indx = indx * umath.logical_not(self._mask)
+            ndarray.__setitem__(self._data,indx,dval)
         else:
             mindx = mask_or(self._mask[indx], valmask, copy=True)
             dindx = self._data[indx]
@@ -1381,10 +1386,8 @@
                 dindx[~mindx] = dval
             elif mindx is nomask:
                 dindx = dval
-            dval = dindx
+            ndarray.__setitem__(self._data,indx,dindx)
             self._mask[indx] = mindx
-        # Set data ..........
-        ndarray.__setitem__(self._data,indx,dval)
     #............................................
     def __getslice__(self, i, j):
         """x.__getslice__(i, j) <==> x[i:j]
@@ -2228,6 +2231,7 @@
     def round(self, decimals=0, out=None):
         result = self._data.round(decimals).view(type(self))
         result._mask = self._mask
+        result._update_from(self)
         if out is None:
             return result
         out[:] = result
@@ -3174,13 +3178,7 @@
 
     """
     if out is None:
-        result = numpy.round_(getdata(a), decimals, out)
-        if isinstance(a,MaskedArray):
-            result = result.view(type(a))
-            result._mask = a._mask
-        else:
-            result = result.view(MaskedArray)
-        return result
+        return numpy.round_(a, decimals, out)
     else:
         numpy.round_(getdata(a), decimals, out)
         if hasattr(out, '_mask'):

Modified: trunk/numpy/ma/mrecords.py
===================================================================
--- trunk/numpy/ma/mrecords.py	2008-04-20 11:49:35 UTC (rev 5055)
+++ trunk/numpy/ma/mrecords.py	2008-04-20 22:58:22 UTC (rev 5056)
@@ -789,19 +789,4 @@
     return newdata
 
 ###############################################################################
-#
-if 1:
-    import numpy.ma as ma
-    from numpy.ma.testutils import *
-    if 1:
-        ilist = [1,2,3,4,5]
-        flist = [1.1,2.2,3.3,4.4,5.5]
-        slist = ['one','two','three','four','five']
-        ddtype = [('a',int),('b',float),('c','|S8')]
-        mask = [0,1,0,0,1]
-        self_base = ma.array(zip(ilist,flist,slist), mask=mask, dtype=ddtype)
-    if 1:
-        mbase = self_base.copy().view(mrecarray)
-        import cPickle
-        _ = cPickle.dumps(mbase)
-        mrec_ = cPickle.loads(_)
+

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2008-04-20 11:49:35 UTC (rev 5055)
+++ trunk/numpy/ma/tests/test_core.py	2008-04-20 22:58:22 UTC (rev 5056)
@@ -609,6 +609,14 @@
     #........................
     def test_oddfeatures_3(self):
         """Tests some generic features."""
+        atest = array([10], mask=True)
+        btest = array([20])
+        idx = atest.mask
+        atest[idx] = btest[idx]
+        assert_equal(atest,[20])
+    #........................
+    def test_oddfeatures_4(self):
+        """Tests some generic features."""
         atest = ones((10,10,10), dtype=float_)
         btest = zeros(atest.shape, MaskType)
         ctest = masked_where(btest,atest)




More information about the Numpy-svn mailing list