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

numpy-svn@scip... numpy-svn@scip...
Sun Sep 28 12:27:41 CDT 2008


Author: pierregm
Date: 2008-09-28 12:27:37 -0500 (Sun, 28 Sep 2008)
New Revision: 5869

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
core:
* added __rmul and __radd__
* fixed concatenate for flexible-dtype

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2008-09-28 15:19:56 UTC (rev 5868)
+++ trunk/numpy/ma/core.py	2008-09-28 17:27:37 UTC (rev 5869)
@@ -1978,14 +1978,26 @@
         "Add other to self, and return a new masked array."
         return add(self, other)
     #
+    def __radd__(self, other):
+        "Add other to self, and return a new masked array."
+        return add(self, other)
+    #
     def __sub__(self, other):
         "Subtract other to self, and return a new masked array."
         return subtract(self, other)
     #
+    def __rsub__(self, other):
+        "Subtract other to self, and return a new masked array."
+        return subtract(other, self)
+    #
     def __mul__(self, other):
         "Multiply other by self, and return a new masked array."
         return multiply(self, other)
     #
+    def __rmul__(self, other):
+        "Multiply other by self, and return a new masked array."
+        return multiply(self, other)
+    #
     def __div__(self, other):
         "Divide other into self, and return a new masked array."
         return divide(self, other)
@@ -3527,7 +3539,7 @@
     # ... all of them are True, and then check for dm.any()
 #    shrink = numpy.logical_or.reduce([getattr(a,'_shrinkmask',True) for a in arrays])
 #    if shrink and not dm.any():
-    if not dm.any():
+    if not dm.dtype.fields and not dm.any():
         data._mask = nomask
     else:
         data._mask = dm.reshape(d.shape)

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2008-09-28 15:19:56 UTC (rev 5868)
+++ trunk/numpy/ma/tests/test_core.py	2008-09-28 17:27:37 UTC (rev 5869)
@@ -132,6 +132,15 @@
         assert_array_equal(z,[1,1,0,0])
         assert_array_equal(z.mask,[False,True,False,False])
 
+    def test_concatenate_flexible(self):
+        "Tests the concatenation on flexible arrays."
+        data = masked_array(zip(np.random.rand(10),
+                                np.arange(10)),
+                            dtype=[('a',float),('b',int)])
+        #
+        test = concatenate([data[:5], data[5:]])
+        assert_equal_records(test, data)
+
     def test_creation_ndmin(self):
         "Check the use of ndmin"
         x = array([1,2,3],mask=[1,0,0], ndmin=2)



More information about the Numpy-svn mailing list