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

numpy-svn at scipy.org numpy-svn at scipy.org
Tue Mar 18 18:03:37 EDT 2008


Author: pierregm
Date: 2008-03-18 17:03:34 -0500 (Tue, 18 Mar 2008)
New Revision: 4886

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
- fixed masked_where (bug #703)
- simplified 'masked_invalid' and added it to __all__
- added the 'out' optional parameter to .mean

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2008-03-18 18:02:31 UTC (rev 4885)
+++ trunk/numpy/ma/core.py	2008-03-18 22:03:34 UTC (rev 4886)
@@ -39,11 +39,11 @@
            'logical_and', 'logical_not', 'logical_or', 'logical_xor',
            'make_mask', 'make_mask_none', 'mask_or', 'masked',
            'masked_array', 'masked_equal', 'masked_greater',
-           'masked_greater_equal', 'masked_inside', 'masked_less',
-           'masked_less_equal', 'masked_not_equal', 'masked_object',
-           'masked_outside', 'masked_print_option', 'masked_singleton',
-           'masked_values', 'masked_where', 'max', 'maximum', 'mean', 'min',
-           'minimum', 'multiply',
+           'masked_greater_equal', 'masked_inside', 'masked_invalid',
+           'masked_less','masked_less_equal', 'masked_not_equal', 
+           'masked_object','masked_outside', 'masked_print_option', 
+           'masked_singleton','masked_values', 'masked_where', 'max', 'maximum', 
+           'mean', 'min', 'minimum', 'multiply',
            'negative', 'nomask', 'nonzero', 'not_equal',
            'ones', 'outer', 'outerproduct',
            'power', 'product', 'ptp', 'put', 'putmask',
@@ -830,7 +830,7 @@
         Whether to return a copy of a (True) or modify a in place.
 
     """
-    cond = filled(condition,1)
+    cond = make_mask(condition)
     a = narray(a, copy=copy, subok=True)
     if hasattr(a, '_mask'):
         cond = mask_or(cond, a._mask)
@@ -967,7 +967,7 @@
 
     """
     a = narray(a, copy=copy, subok=True)
-    condition = (numpy.isnan(a) | numpy.isinf(a))
+    condition = ~(numpy.isfinite(a))
     if hasattr(a, '_mask'):
         condition = mask_or(condition, a._mask)
         cls = type(a)
@@ -1306,7 +1306,7 @@
         m = self._mask
         if not getattr(dout,'ndim', False):
             # Just a scalar............
-            if m is not nomask and m[indx]:
+            if (not m.ndim and not m) or m[indx]:
                 return masked
         else:
             # Force dout to MA ........
@@ -2103,7 +2103,7 @@
         result.__setmask__(self.mask)
         return result
 
-    def mean(self, axis=None, dtype=None):
+    def mean(self, axis=None, dtype=None, out=None):
         """Average the array over the given axis.  Equivalent to
 
         a.sum(axis, dtype) / a.size(axis).
@@ -2119,11 +2119,14 @@
 
         """
         if self._mask is nomask:
-            return super(MaskedArray, self).mean(axis=axis, dtype=dtype)
+            result = super(MaskedArray, self).mean(axis=axis, dtype=dtype)
         else:
             dsum = self.sum(axis=axis, dtype=dtype)
             cnt = self.count(axis=axis)
-            return dsum*1./cnt
+            result = dsum*1./cnt
+        if out is not None:
+            out.flat = result.ravel()
+        return result
 
     def anom(self, axis=None, dtype=None):
         """Return the anomalies (deviations from the average) along
@@ -3307,14 +3310,3 @@
 
 ################################################################################
 
-if 1:
-    from testutils import assert_equal
-    if 1:
-        mtype = [('f',float_),('s','|S3')]
-        x = array([(1,'a'),(2,'b'),(numpy.pi,'pi')], dtype=mtype)
-        x[0] = (10,'A')
-        (xf, xs) = (x['f'], x['s'])
-        assert_equal(xf.data, [10,2,numpy.pi])
-        assert_equal(xf.dtype, float_)
-        assert_equal(xs.data, ['A', 'b', 'pi'])
-        assert_equal(xs.dtype, '|S3')

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2008-03-18 18:02:31 UTC (rev 4885)
+++ trunk/numpy/ma/tests/test_core.py	2008-03-18 22:03:34 UTC (rev 4886)
@@ -1451,9 +1451,18 @@
         assert_equal(b.shape, a.shape)
         assert_equal(b.fill_value, a.fill_value)
 
-
 #..............................................................................
 
+class TestMiscFunctions(NumpyTestCase):
+    "Test class for miscellaneous functions."
+    #
+    def test_masked_where(self):
+        x = [1,2]
+        y = masked_where(False,x)
+        assert_equal(y,[1,2])
+        assert_equal(y[1],2)
+
+
 ###############################################################################
 #------------------------------------------------------------------------------
 if __name__ == "__main__":




More information about the Numpy-svn mailing list