[Scipy-svn] r2985 - in trunk/Lib/sandbox/maskedarray: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Fri May 11 18:30:03 EDT 2007


Author: pierregm
Date: 2007-05-11 17:29:57 -0500 (Fri, 11 May 2007)
New Revision: 2985

Modified:
   trunk/Lib/sandbox/maskedarray/core.py
   trunk/Lib/sandbox/maskedarray/extras.py
   trunk/Lib/sandbox/maskedarray/tests/test_extras.py
   trunk/Lib/sandbox/maskedarray/testutils.py
Log:
testutils   : comparing a scalar/array to masked fails.
core        : fixed a couple of docstring
test_extras : fixed the notmasked_contiguous test
extras      : added the hsplit function

Modified: trunk/Lib/sandbox/maskedarray/core.py
===================================================================
--- trunk/Lib/sandbox/maskedarray/core.py	2007-05-11 20:24:55 UTC (rev 2984)
+++ trunk/Lib/sandbox/maskedarray/core.py	2007-05-11 22:29:57 UTC (rev 2985)
@@ -1722,7 +1722,7 @@
     `axis` : Integer *[None]*
         Axis to be indirectly sorted (default -1)
     `fill_value` : var *[None]*
-        Default filling value. If None, uses the data type default.
+        Default filling value. If None, uses the minimum default for the data type.
         """
         if fill_value is None:
             fill_value = minimum_fill_value(self)
@@ -1733,7 +1733,7 @@
         """Returns the array of indices for the maximum values of `a` along the
     specified axis.
     Masked values are treated as if they had the value `fill_value`.
-    If `fill_value` is None, the default for the data type is used.
+    If `fill_value` is None, the maximum default for the data type is used.
     Returns a numpy array.
 
 :Keywords:
@@ -2632,20 +2632,6 @@
 ################################################################################
 
 if __name__ == '__main__':
-    import numpy as N
-    from maskedarray.testutils import assert_equal, assert_array_equal
-    marray = masked_array
-    #
-    if 0:
-        x = masked_array([1,2])
-        y = x * masked
-        print y
-        assert_equal(y.shape, x.shape)
-        assert_equal(y._mask, [True, True])
-        y = x + masked
-        assert_equal(y.shape, x.shape)
-        assert_equal(y._mask, [True, True])
-    #
     if 1:
-        x = arange(64).reshape(8,8)
-        z = maximum(x)
+        x = arange(10)
+        assert(x.ctypes.data == x.filled().ctypes.data)
\ No newline at end of file

Modified: trunk/Lib/sandbox/maskedarray/extras.py
===================================================================
--- trunk/Lib/sandbox/maskedarray/extras.py	2007-05-11 20:24:55 UTC (rev 2984)
+++ trunk/Lib/sandbox/maskedarray/extras.py	2007-05-11 22:29:57 UTC (rev 2985)
@@ -15,7 +15,7 @@
 'apply_along_axis', 'atleast_1d', 'atleast_2d', 'atleast_3d', 'average',
 'vstack', 'hstack', 'dstack', 'row_stack', 'column_stack',
 'compress_rowcols', 'compress_rows', 'compress_cols', 'count_masked', 
-'dot', 
+'dot', 'hsplit',
 'mask_rowcols','mask_rows','mask_cols','masked_all','masked_all_like', 
 'mediff1d', 'mr_',
 'notmasked_edges','notmasked_contiguous',
@@ -155,6 +155,8 @@
 column_stack = _fromnxfunction('column_stack')
 dstack = _fromnxfunction('dstack')
 
+hsplit = _fromnxfunction('hsplit')
+
 #####--------------------------------------------------------------------------
 #---- 
 #####--------------------------------------------------------------------------

Modified: trunk/Lib/sandbox/maskedarray/tests/test_extras.py
===================================================================
--- trunk/Lib/sandbox/maskedarray/tests/test_extras.py	2007-05-11 20:24:55 UTC (rev 2984)
+++ trunk/Lib/sandbox/maskedarray/tests/test_extras.py	2007-05-11 22:29:57 UTC (rev 2985)
@@ -156,8 +156,9 @@
                                [1,1,1,1,1,1,1,1],
                                [0,0,0,0,0,0,1,0],])
         tmp = notmasked_contiguous(a, None)
-        assert_equal(tmp[-1], (6, (16,21)))
-        assert_equal(tmp[-2], (4, (0,3)))
+        assert_equal(tmp[-1], slice(23,23,None))
+        assert_equal(tmp[-2], slice(16,21,None))
+        assert_equal(tmp[-3], slice(0,3,None))
         #
         tmp = notmasked_contiguous(a, 0)
         assert(len(tmp[-1]) == 1)
@@ -166,9 +167,10 @@
         assert(len(tmp[0]) == 2)
         #
         tmp = notmasked_contiguous(a, 1)
-        assert_equal(tmp[0][-1], (4, (0,3)))
+        assert_equal(tmp[0][-1], slice(0,3,None))
         assert(tmp[1] is None)
-        assert_equal(tmp[2][-1], (6, (0,5)))
+        assert_equal(tmp[2][-1], slice(7,7,None))
+        assert_equal(tmp[2][-2], slice(0,5,None))
         
 class test_2dfunctions(NumpyTestCase):
     "Tests 2D functions"

Modified: trunk/Lib/sandbox/maskedarray/testutils.py
===================================================================
--- trunk/Lib/sandbox/maskedarray/testutils.py	2007-05-11 20:24:55 UTC (rev 2984)
+++ trunk/Lib/sandbox/maskedarray/testutils.py	2007-05-11 22:29:57 UTC (rev 2985)
@@ -18,7 +18,7 @@
 from numpy.testing.utils import build_err_msg, rand
 
 import core
-from core import mask_or, getmask, getmaskarray, masked_array, nomask
+from core import mask_or, getmask, getmaskarray, masked_array, nomask, masked
 from core import filled, equal, less
 
 #------------------------------------------------------------------------------
@@ -67,6 +67,10 @@
         assert desired == actual, msg
         return
     # Case #4. arrays or equivalent
+    if ((actual is masked) and not (desired is masked)) or \
+        ((desired is masked) and not (actual is masked)):
+        msg = build_err_msg([actual, desired], err_msg, header='', names=('x', 'y'))
+        raise ValueError(msg)    
     actual = N.array(actual, copy=False, subok=True)
     desired = N.array(desired, copy=False, subok=True)
     if actual.dtype.char in "OS" and desired.dtype.char in "OS":
@@ -115,6 +119,12 @@
     
     x = masked_array(xf, copy=False, mask=m).filled(fill_value)
     y = masked_array(yf, copy=False, mask=m).filled(fill_value)
+    
+    if ((x is masked) and not (y is masked)) or \
+        ((y is masked) and not (x is masked)):
+        msg = build_err_msg([x, y], err_msg, header=header, names=('x', 'y'))
+        raise ValueError(msg)
+    
     if (x.dtype.char != "O") and (x.dtype.char != "S"):
         x = x.astype(float_)
         if isinstance(x, N.ndarray) and x.size > 1:
@@ -195,4 +205,8 @@
         assert(m2 is nomask)
     if m2 is nomask:
         assert(m1 is nomask)
-    assert_array_equal(m1, m2)
\ No newline at end of file
+    assert_array_equal(m1, m2)
+    
+if __name__ == '__main__':
+    a = 12
+    assert_equal(a, masked)
\ No newline at end of file




More information about the Scipy-svn mailing list