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

numpy-svn@scip... numpy-svn@scip...
Tue Apr 27 11:55:10 CDT 2010


Author: pierregm
Date: 2010-04-27 11:55:09 -0500 (Tue, 27 Apr 2010)
New Revision: 8370

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
Fixed .var for arrays with 1 more valid value than ddofs

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2010-04-27 03:35:37 UTC (rev 8369)
+++ trunk/numpy/ma/core.py	2010-04-27 16:55:09 UTC (rev 8370)
@@ -4743,7 +4743,7 @@
         dvar = divide(danom.sum(axis), cnt).view(type(self))
         # Apply the mask if it's not a scalar
         if dvar.ndim:
-            dvar._mask = mask_or(self._mask.all(axis), (cnt <= ddof))
+            dvar._mask = mask_or(self._mask.all(axis), (cnt <= 0))
             dvar._update_from(self)
         elif getattr(dvar, '_mask', False):
         # Make sure that masked is returned when the scalar is masked.

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2010-04-27 03:35:37 UTC (rev 8369)
+++ trunk/numpy/ma/tests/test_core.py	2010-04-27 16:55:09 UTC (rev 8370)
@@ -199,7 +199,7 @@
         err_status_ini = np.geterr()
         try:
             np.seterr(invalid='ignore')
-            data = masked_array(np.sqrt([-1., 0., 1.]), mask=[0, 0, 1])
+            data = masked_array([np.nan, 0., 1.], mask=[0, 0, 1])
             data_fixed = fix_invalid(data)
             assert_equal(data_fixed._data, [data.fill_value, 0., 1.])
             assert_equal(data_fixed._mask, [1., 0., 1.])
@@ -2707,6 +2707,19 @@
             self.assertTrue(np.isnan(nout))
 
 
+    def test_varstd_ddof(self):
+        a = array([[1, 1, 0], [1, 1, 0]], mask=[[0, 0, 1], [0, 0, 1]])
+        test = a.std(axis=0, ddof=0)
+        assert_equal(test.filled(0), [0, 0, 0])
+        assert_equal(test.mask, [0, 0, 1])
+        test = a.std(axis=0, ddof=1)
+        assert_equal(test.filled(0), [0, 0, 0])
+        assert_equal(test.mask, [0, 0, 1])
+        test = a.std(axis=0, ddof=2)
+        assert_equal(test.filled(0), [0, 0, 0])
+        assert_equal(test.mask, [1, 1, 1])
+
+
     def test_diag(self):
         "Test diag"
         x = arange(9).reshape((3, 3))



More information about the Numpy-svn mailing list