[Numpy-svn] r4718 - in branches/maskedarray/numpy/ma: . tests

numpy-svn@scip... numpy-svn@scip...
Thu Jan 10 09:52:42 CST 2008


Author: stefan
Date: 2008-01-10 09:52:25 -0600 (Thu, 10 Jan 2008)
New Revision: 4718

Modified:
   branches/maskedarray/numpy/ma/core.py
   branches/maskedarray/numpy/ma/tests/test_core.py
Log:
Apply patch by Pierre.  Move tests from __main__ to the tests directory.

fix_invalid - change the default to copy=True

_MaskedUnaryOperation - make sure the result gets updated from the
input (for subclasses)

_MaskedBinaryOperation - make sure the result gets updated from the
inputs (for subclasses)

_DomainedBinaryOperation - make sure the result gets updated from the
inputs (for subclasses)

MaskedArray.__new__ - added the ndmin keyword
MaskedArray.__getitem__ - works with fields, using the global mask

MaskedArray.__setitem__ - works with fields. The global mask is NOT
updated

MaskedArray.ids - fixed when nomask

MaskedArray.min/.max - force masked to be returned when the whole
array is masked

array - added the ndmin keyword


Modified: branches/maskedarray/numpy/ma/core.py
===================================================================
--- branches/maskedarray/numpy/ma/core.py	2008-01-08 23:59:54 UTC (rev 4717)
+++ branches/maskedarray/numpy/ma/core.py	2008-01-10 15:52:25 UTC (rev 4718)
@@ -14,47 +14,42 @@
 
 :author: Pierre Gerard-Marchant
 :contact: pierregm_at_uga_dot_edu
-:version: $Id: core.py 3639 2007-12-13 03:39:17Z pierregm $
 """
-__author__ = "Pierre GF Gerard-Marchant ($Author: pierregm $)"
-__version__ = '1.0'
-__revision__ = "$Revision: 3639 $"
-__date__     = '$Date: 2007-12-13 05:39:17 +0200 (Thu, 13 Dec 2007) $'
-
+__author__ = "Pierre GF Gerard-Marchant"
 __docformat__ = "restructuredtext en"
 
 __all__ = ['MAError', 'MaskType', 'MaskedArray',
            'bool_', 'complex_', 'float_', 'int_', 'object_',
            'abs', 'absolute', 'add', 'all', 'allclose', 'allequal', 'alltrue',
-               'amax', 'amin', 'anom', 'anomalies', 'any', 'arange',
-               'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2',
-               'arctanh', 'argmax', 'argmin', 'argsort', 'around',
-               'array', 'asarray','asanyarray',
+           'amax', 'amin', 'anom', 'anomalies', 'any', 'arange',
+           'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2',
+           'arctanh', 'argmax', 'argmin', 'argsort', 'around',
+           'array', 'asarray','asanyarray',
            'bitwise_and', 'bitwise_or', 'bitwise_xor',
            'ceil', 'choose', 'compressed', 'concatenate', 'conjugate',
-               'cos', 'cosh', 'count',
+           'cos', 'cosh', 'count',
            'default_fill_value', 'diagonal', 'divide', 'dump', 'dumps',
            'empty', 'empty_like', 'equal', 'exp',
            'fabs', 'fmod', 'filled', 'floor', 'floor_divide','fix_invalid',
            'getmask', 'getmaskarray', 'greater', 'greater_equal', 'hypot',
            'ids', 'inner', 'innerproduct',
-               'isMA', 'isMaskedArray', 'is_mask', 'is_masked', 'isarray',
+           'isMA', 'isMaskedArray', 'is_mask', 'is_masked', 'isarray',
            'left_shift', 'less', 'less_equal', 'load', 'loads', 'log', 'log10',
-               'logical_and', 'logical_not', 'logical_or', 'logical_xor',
+           '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_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',
            'negative', 'nomask', 'nonzero', 'not_equal',
            'ones', 'outer', 'outerproduct',
            'power', 'product', 'ptp', 'put', 'putmask',
            'rank', 'ravel', 'remainder', 'repeat', 'reshape', 'resize',
-               'right_shift', 'round_',
+           'right_shift', 'round_',
            'shape', 'sin', 'sinh', 'size', 'sometrue', 'sort', 'sqrt', 'std',
-               'subtract', 'sum', 'swapaxes',
+           'subtract', 'sum', 'swapaxes',
            'take', 'tan', 'tanh', 'transpose', 'true_divide',
            'var', 'where',
            'zeros']
@@ -63,7 +58,7 @@
 import types
 import cPickle
 import operator
-#
+
 import numpy
 from numpy.core import bool_, complex_, float_, int_, object_, str_
 
@@ -76,22 +71,9 @@
 from numpy import array as narray
 import warnings
 
-class NoMask(ndarray):
-    def __new__(subtype):
-        narray(False)
-        return narray(False).view(subtype)
 
-    def no_op(self,*args,**kwargs):
-        return self
-
-    def __array_finalize__(self,obj):
-        obj.flags['WRITEABLE'] = False
-
-    def copy(self):
-        return self
-
 MaskType = bool_
-nomask = NoMask()
+nomask = MaskType(0)
 
 divide_tolerance = 1.e-35
 numpy.seterr(all='ignore')
@@ -417,8 +399,10 @@
     #
     def __call__ (self, a, *args, **kwargs):
         "Execute the call behavior."
+        #
         m = getmask(a)
         d1 = get_data(a)
+        #        
         if self.domain is not None:
             dm = narray(self.domain(d1), copy=False)
             m = numpy.logical_or(m, dm)
@@ -429,14 +413,17 @@
         # Take care of the masked singletong first ...
         if not m.ndim and m:
             return masked
-        # Get the result..............................
+        # Get the result class .......................
         if isinstance(a, MaskedArray):
-            result = self.f(d1, *args, **kwargs).view(type(a))
+            subtype = type(a)
         else:
-            result = self.f(d1, *args, **kwargs).view(MaskedArray)
+            subtype = MaskedArray
+        # Get the result  as a view of the subtype ...
+        result = self.f(d1, *args, **kwargs).view(subtype)
         # Fix the mask if we don't have a scalar
         if result.ndim > 0:
             result._mask = m
+            result._update_from(a)
         return result
     #
     def __str__ (self):
@@ -475,6 +462,10 @@
             if m is not nomask:
                 result._mask = make_mask_none(result.shape)
                 result._mask.flat = m
+            if isinstance(a,MaskedArray):
+                result._update_from(a)
+            if isinstance(b,MaskedArray):
+                result._update_from(b)
         elif m:
             return masked
         return result
@@ -586,6 +577,10 @@
         result =  self.f(d1, d2).view(get_masked_subclass(a,b))
         if result.ndim > 0:
             result._mask = m
+            if isinstance(a,MaskedArray):
+                result._update_from(a)
+            if isinstance(b,MaskedArray):
+                result._update_from(b)
         return result
 
     def __str__ (self):
@@ -1020,7 +1015,6 @@
         cls = type(self.obj)
         result = getattr(data, methodname)(*args, **params).view(cls)
         result._update_from(self.obj)
-        #result._shrinkmask = self.obj._shrinkmask
         if result.ndim:
             if not self._onmask:
                 result.__setmask__(mask)
@@ -1064,7 +1058,7 @@
 
     Construction:
         x = MaskedArray(data, mask=nomask, dtype=None, copy=True,
-        fill_value=None, mask = nomask, fill_value=None, shrink=True)
+        fill_value=None, keep_mask=True, hard_mask=False, shrink=True)
 
     *Parameters*:
         data : {var}
@@ -1080,6 +1074,11 @@
         copy : {boolean}
             Whether to copy the input data (True), or to use a
             reference instead.  Note: data are NOT copied by default.
+        subok : {True, boolean}
+            Whether to return a subclass of MaskedArray (if possible)
+            or a plain MaskedArray.
+        ndmin : {0, int}
+            Minimum number of dimensions
         fill_value : {var}
             Value used to fill in the masked values when necessary. If
             None, a default based on the datatype is used.
@@ -1089,9 +1088,9 @@
         hard_mask : {False, boolean}
             Whether to use a hard mask or not. With a hard mask,
             masked values cannot be unmasked.
-        subok : {True, boolean}
-            Whether or not to return a subclass of MaskedArray (if
-            possible) or a plain MaskedArray.
+        shrink : {True, boolean}
+            Whether to force compression of an empty mask.
+        
 
     """
 
@@ -1101,8 +1100,9 @@
     _baseclass =  numeric.ndarray
 
     def __new__(cls, data=None, mask=nomask, dtype=None, copy=False,
-                fill_value=None, keep_mask=True, hard_mask=False, flag=None,
-                subok=True, **options):
+                subok=True, ndmin=0, fill_value=None, 
+                keep_mask=True, hard_mask=False, flag=None,shrink=True, 
+                **options):
         """Create a new masked array from scratch.
 
         Note: you can also create an array with the .view(MaskedArray)
@@ -1114,7 +1114,7 @@
                           DeprecationWarning)
             shrink = flag
         # Process data............
-        _data = narray(data, dtype=dtype, copy=copy, subok=True)
+        _data = narray(data, dtype=dtype, copy=copy, subok=True, ndmin=ndmin)
         _baseclass = getattr(data, '_baseclass', type(_data))
         _basedict = getattr(data, '_basedict', getattr(data, '__dict__', None))
         if not isinstance(data, MaskedArray) or not subok:
@@ -1128,7 +1128,10 @@
         # Process mask ...........
         if mask is nomask:
             if not keep_mask:
-                _data._mask = nomask
+                if shrink:
+                    _data._mask = nomask
+                else:
+                    _data._mask = make_mask_none(_data)
             if copy:
                 _data._mask = _data._mask.copy()
                 _data._sharedmask = False
@@ -1183,7 +1186,7 @@
         return
     #........................
     def __array_finalize__(self,obj):
-        """Finalize the masked array.
+        """Finalizes the masked array.
         """
         # Get main attributes .........
         self._mask = getattr(obj, '_mask', nomask)
@@ -1195,7 +1198,6 @@
         # Finalize the mask ...........
         if self._mask is not nomask:
             self._mask.shape = self.shape
-#        self._data = self.view(self._baseclass)
         return
     #..................................
     def __array_wrap__(self, obj, context=None):
@@ -1266,7 +1268,10 @@
             dout._update_from(self)
             # Update the mask if needed
             if m is not nomask:
-                dout._mask = ndarray.__getitem__(m, indx).reshape(dout.shape)
+                if isinstance(indx, basestring):
+                    dout._mask = m.reshape(dout.shape)
+                else:
+                    dout._mask = ndarray.__getitem__(m, indx).reshape(dout.shape)
 #               Note: Don't try to check for m.any(), that'll take too long...
 #                mask = ndarray.__getitem__(m, indx).reshape(dout.shape)
 #                if self._shrinkmask and not m.any():
@@ -1287,6 +1292,10 @@
 #        if getmask(indx) is not nomask:
 #            msg = "Masked arrays must be filled before they can be used as indices!"
 #            raise IndexError, msg
+        if isinstance(indx, basestring):
+            ndarray.__setitem__(self._data,indx, getdata(value))
+            warnings.warn("The mask is NOT affected!")
+            return
         #....
         if value is masked:
             m = self._mask
@@ -1794,6 +1803,8 @@
     #............................................
     def ids (self):
         """Return the addresses of the data and mask areas."""
+        if self._mask is nomask:
+            return (self.ctypes.data, id(nomask))        
         return (self.ctypes.data, self._mask.ctypes.data)
     #............................................
     def all(self, axis=None, out=None):
@@ -2282,7 +2293,10 @@
             mask = umath.logical_and.reduce(mask.flat)
         else:
             mask = umath.logical_and.reduce(mask, axis=axis)
-        # Get the fil value ...........
+        # Skip if all masked ..........
+        if not mask.ndim and mask:
+            return masked
+        # Get the fill value ...........
         if fill_value is None:
             fill_value = minimum_fill_value(self)
         # Get the data ................
@@ -2290,6 +2304,13 @@
         if result.ndim > 0:
             result._mask = mask
         return result
+    
+    def mini(self, axis=None):    
+        if axis is None:
+            return minimum(self)
+        else:
+            return minimum.reduce(self, axis)
+    
     #........................
     def max(self, axis=None, fill_value=None):
         """Return the maximum/a along the given axis.
@@ -2315,6 +2336,9 @@
             mask = umath.logical_and.reduce(mask.flat)
         else:
             mask = umath.logical_and.reduce(mask, axis=axis)
+        # Skip if all masked ..........
+        if not mask.ndim and mask:
+            return masked
         # Get the fill value ..........
         if fill_value is None:
             fill_value = maximum_fill_value(self)
@@ -2469,10 +2493,13 @@
 
 masked_array = MaskedArray
 
-def array(data, dtype=None, copy=False, order=False, mask=nomask, subok=True,
-          keep_mask=True, hard_mask=False, fill_value=None, shrink=True):
-    """array(data, dtype=None, copy=True, order=False, mask=nomask,
-             keep_mask=True, shrink=True, fill_value=None)
+def array(data, dtype=None, copy=False, order=False, 
+          mask=nomask, fill_value=None, 
+          keep_mask=True, hard_mask=False, shrink=True, subok=True, ndmin=0, 
+          ):
+    """array(data, dtype=None, copy=False, order=False, mask=nomask,
+             fill_value=None, keep_mask=True, hard_mask=False, shrink=True,
+             subok=True, ndmin=0)
 
     Acts as shortcut to MaskedArray, with options in a different order
     for convenience.  And backwards compatibility...
@@ -2481,7 +2508,7 @@
     #TODO: we should try to put 'order' somwehere
     return MaskedArray(data, mask=mask, dtype=dtype, copy=copy, subok=subok,
                        keep_mask=keep_mask, hard_mask=hard_mask,
-                       fill_value=fill_value)
+                       fill_value=fill_value, ndmin=ndmin, shrink=shrink)
 array.__doc__ = masked_array.__doc__
 
 def is_masked(x):
@@ -2745,8 +2772,9 @@
         return data
     # OK, so we have to concatenate the masks
     dm = numpy.concatenate([getmaskarray(a) for a in arrays], axis)
-    shrink = numpy.logical_or.reduce([getattr(a,'_shrinkmask',True) for a in arrays])
-    if shrink and not 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():
         data._mask = nomask
     else:
         data._mask = dm.reshape(d.shape)
@@ -3179,42 +3207,3 @@
     "Load a pickle from the current string."""
     return cPickle.loads(strg)
 
-
-
-
-###############################################################################
-#
-if __name__ == '__main__':
-    from maskedarray.testutils import assert_equal, assert_almost_equal
-
-    if 1:
-        x = array([1,2,3,4,5,6])
-        mx = array(x, mask=[0,0,0,1,1,1])
-        mask = [0,0,1,0,0,1]
-    if 1:
-        # w/o mask, w/o masked values
-        xx = x.copy()
-        putmask(xx, mask, 99)
-        assert_equal(xx, [1,2,99,4,5,99])
-        # w/ mask, w/o masked values
-        mxx = mx.copy()
-        putmask(mxx, mask, 99)
-        assert_equal(mxx._data, [1,2,99,4,5,99])
-        assert_equal(mxx._mask, [0,0,0,1,1,0])
-        # w/o mask, w/ masked values
-        values = array([10,20,30,40,50,60],mask=[1,1,1,0,0,0])
-        xx = x.copy()
-        putmask(xx, mask, values)
-        assert_equal(xx._data, [1,2,30,4,5,60])
-        assert_equal(xx._mask, [0,0,1,0,0,0])
-        # w/ mask, w/ masked values
-        mxx = mx.copy()
-        putmask(mxx, mask, values)
-        assert_equal(mxx._data, [1,2,30,4,5,60])
-        assert_equal(mxx._mask, [0,0,1,1,1,0])
-        # w/ mask, w/ masked values + hardmask
-        mxx = mx.copy()
-        mxx.harden_mask()
-        putmask(mxx, mask, values)
-        assert_equal(mxx, [1,2,30,4,5,60])
-

Modified: branches/maskedarray/numpy/ma/tests/test_core.py
===================================================================
--- branches/maskedarray/numpy/ma/tests/test_core.py	2008-01-08 23:59:54 UTC (rev 4717)
+++ branches/maskedarray/numpy/ma/tests/test_core.py	2008-01-10 15:52:25 UTC (rev 4718)
@@ -16,6 +16,7 @@
 import numpy
 import numpy.core.fromnumeric  as fromnumeric
 from numpy.testing import NumpyTest, NumpyTestCase
+from numpy.testing import set_local_path, restore_path
 from numpy.testing.utils import build_err_msg
 from numpy import array as narray
 
@@ -27,7 +28,9 @@
 
 pi = numpy.pi
 
+set_local_path()
 from test_old_ma import *
+restore_path()
 
 class TestNoMask(NumpyTestCase):
     def test_no_inplace(self):
@@ -63,7 +66,7 @@
         xm.set_fill_value(1.e+20)
         self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf)
     #........................
-    def check_basic1d(self):
+    def test_basic1d(self):
         "Test of basic array creation and properties in 1 dimension."
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         assert(not isMaskedArray(x))
@@ -81,7 +84,7 @@
         assert_array_equal(filled(xm, 1.e20), xf)
         assert_array_equal(x, xm)
     #........................
-    def check_basic2d(self):
+    def test_basic2d(self):
         "Test of basic array creation and properties in 2 dimensions."
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         for s in [(4,3), (6,2)]:
@@ -101,7 +104,7 @@
             assert_equal(filled(xm, 1.e20), xf)
             assert_equal(x, xm)
     #........................
-    def check_basic_arithmetic (self):
+    def test_basic_arithmetic (self):
         "Test of basic arithmetic."
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         a2d = array([[1,2],[0,4]])
@@ -136,14 +139,14 @@
             assert_equal(numpy.multiply(x,y), multiply(xm, ym))
             assert_equal(numpy.divide(x,y), divide(xm, ym))
     #........................
-    def check_mixed_arithmetic(self):
+    def test_mixed_arithmetic(self):
         "Tests mixed arithmetics."
         na = narray([1])
         ma = array([1])
         self.failUnless(isinstance(na + ma, MaskedArray))
         self.failUnless(isinstance(ma + na, MaskedArray))
     #........................
-    def check_inplace_arithmetic(self):
+    def test_inplace_arithmetic(self):
         """Test of inplace operations and rich comparisons"""
         # addition
         x = arange(10)
@@ -256,7 +259,7 @@
 
 
     #..........................
-    def check_scalararithmetic(self):
+    def test_scalararithmetic(self):
         "Tests some scalar arithmetics on MaskedArrays."
         xm = array(0, mask=1)
         assert((1/array(0)).mask)
@@ -270,7 +273,7 @@
         assert_equal(x.filled().ctypes.data, x.ctypes.data)
         assert_equal(str(xm), str(masked_print_option))
     #.........................
-    def check_basic_ufuncs (self):
+    def test_basic_ufuncs (self):
         "Test various functions such as sin, cos."
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         assert_equal(numpy.cos(x), cos(xm))
@@ -296,7 +299,7 @@
         assert_equal(numpy.greater_equal(x,y), greater_equal(xm, ym))
         assert_equal(numpy.conjugate(x), conjugate(xm))
     #........................
-    def check_count_func (self):
+    def test_count_func (self):
         "Tests count"
         ott = array([0.,1.,2.,3.], mask=[1,0,0,0])
         assert( isinstance(count(ott), int))
@@ -310,7 +313,7 @@
         assert getmask(count(ott,0)) is nomask
         assert_equal([1,2],count(ott,0))
     #........................
-    def check_minmax_func (self):
+    def test_minmax_func (self):
         "Tests minimum and maximum."
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         xr = numpy.ravel(x) #max doesn't work if shaped
@@ -333,7 +336,7 @@
         x[-1,-1] = masked
         assert_equal(maximum(x), 2)
 
-    def check_minmax_methods(self):
+    def test_minmax_methods(self):
         "Additional tests on max/min"
         (_, _, _, _, _, xm, _, _, _, _) = self.d
         xm.shape = (xm.size,)
@@ -350,7 +353,7 @@
         assert(xm[0].ptp(0) is masked)
         assert(xm[0].ptp(-1) is masked)
     #........................
-    def check_addsumprod (self):
+    def test_addsumprod (self):
         "Tests add, sum, product."
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         assert_equal(numpy.add.reduce(x), add.reduce(x))
@@ -371,7 +374,7 @@
             assert_equal(numpy.sum(x,1), sum(x,1))
             assert_equal(numpy.product(x,1), product(x,1))
     #.........................
-    def check_concat(self):
+    def test_concat(self):
         "Tests concatenations."
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         # basic concatenation
@@ -388,7 +391,7 @@
         assert_equal(numpy.concatenate((x,y),1), xmym)
         assert_equal(numpy.concatenate((xm.mask,ym.mask),1), xmym._mask)
     #........................
-    def check_indexing(self):
+    def test_indexing(self):
         "Tests conversions and indexing"
         x1 = numpy.array([1,2,4,3])
         x2 = array(x1, mask=[1,0,0,0])
@@ -438,7 +441,7 @@
         assert_equal(s1, s2)
         assert x1[1:1].shape == (0,)
     #........................
-    def check_copy(self):
+    def test_copy(self):
         "Tests of some subtle points of copying and sizing."
         n = [0,0,1,0,0]
         m = make_mask(n)
@@ -506,7 +509,7 @@
         assert_not_equal(y._data.ctypes.data, x._data.ctypes.data)
         assert_not_equal(y._mask.ctypes.data, x._mask.ctypes.data)
     #........................
-    def check_where(self):
+    def test_where(self):
         "Test the where function"
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         d = where(xm>2,xm,-9)
@@ -547,7 +550,7 @@
         assert z[9] is masked
 
     #........................
-    def check_oddfeatures_1(self):
+    def test_oddfeatures_1(self):
         "Test of other odd features"
         x = arange(20)
         x = x.reshape(4,5)
@@ -576,7 +579,7 @@
         assert_equal(x,z)
         #
     #........................
-    def check_oddfeatures_2(self):
+    def test_oddfeatures_2(self):
         "Tests some more features."
         x = array([1.,2.,3.,4.,5.])
         c = array([1,1,1,0,0])
@@ -606,14 +609,14 @@
         z = where(c, 1, masked)
         assert_equal(z, [99, 1, 1, 99, 99, 99])
     #........................
-    def check_oddfeatures_3(self):
+    def test_oddfeatures_3(self):
         """Tests some generic features."""
         atest = ones((10,10,10), dtype=float_)
         btest = zeros(atest.shape, MaskType)
         ctest = masked_where(btest,atest)
         assert_equal(atest,ctest)
     #........................
-    def check_maskingfunctions(self):
+    def test_maskingfunctions(self):
         "Tests masking functions."
         x = array([1.,2.,3.,4.,5.])
         x[2] = masked
@@ -632,7 +635,7 @@
         assert_equal(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])
         assert_equal(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])
     #........................
-    def check_TakeTransposeInnerOuter(self):
+    def test_TakeTransposeInnerOuter(self):
         "Test of take, transpose, inner, outer products"
         x = arange(24)
         y = numpy.arange(24)
@@ -652,7 +655,7 @@
         assert t[1] == 2
         assert t[2] == 3
     #.......................
-    def check_maskedelement(self):
+    def test_maskedelement(self):
         "Test of masked element"
         x = arange(6)
         x[1] = masked
@@ -665,7 +668,7 @@
         #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)
         #self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)
     #........................
-    def check_scalar(self):
+    def test_scalar(self):
         "Checks masking a scalar"
         x = masked_array(0)
         assert_equal(str(x), '0')
@@ -674,7 +677,7 @@
         x = masked_array(0, mask=False)
         assert_equal(str(x), '0')
     #........................
-    def check_usingmasked(self):
+    def test_usingmasked(self):
         "Checks that there's no collapsing to masked"
         x = masked_array([1,2])
         y = x * masked
@@ -687,7 +690,7 @@
         assert_equal(y._mask, [True, True])
 
     #........................
-    def check_topython(self):
+    def test_topython(self):
         "Tests some communication issues with Python."
         assert_equal(1, int(array(1)))
         assert_equal(1.0, float(array(1)))
@@ -704,7 +707,7 @@
 #TODO:        self.failIf(bool(array([0,0])))
 #TODO:        self.failIf(bool(array([0,0],mask=[0,0])))
     #........................
-    def check_arraymethods(self):
+    def test_arraymethods(self):
         "Tests some MaskedArray methods."
         a = array([1,3,2])
         b = array([1,3,2], mask=[1,0,1])
@@ -723,7 +726,7 @@
         assert_equal(a.take([1,2]), a.data.take([1,2]))
         assert_equal(m.transpose(), m.data.transpose())
     #........................
-    def check_basicattributes(self):
+    def test_basicattributes(self):
         "Tests some basic array attributes."
         a = array([1,3,2])
         b = array([1,3,2], mask=[1,0,1])
@@ -734,7 +737,7 @@
         assert_equal(a.shape, (3,))
         assert_equal(b.shape, (3,))
     #........................
-    def check_single_element_subscript(self):
+    def test_single_element_subscript(self):
         "Tests single element subscripts of Maskedarrays."
         a = array([1,3,2])
         b = array([1,3,2], mask=[1,0,1])
@@ -742,7 +745,7 @@
         assert_equal(b[0].shape, ())
         assert_equal(b[1].shape, ())
     #........................
-    def check_maskcreation(self):
+    def test_maskcreation(self):
         "Tests how masks are initialized at the creation of Maskedarrays."
         data = arange(24, dtype=float_)
         data[[3,6,15]] = masked
@@ -753,7 +756,7 @@
         dma_3 = MaskedArray(dma_1, mask=[1,0,0,0]*6)
         fail_if_equal(dma_3.mask, dma_1.mask)
 
-    def check_pickling(self):
+    def test_pickling(self):
         "Tests pickling"
         import cPickle
         a = arange(10)
@@ -770,26 +773,26 @@
         assert_equal(a_pickled, a)
         assert(isinstance(a_pickled._data,numpy.matrix))
     #
-    def check_fillvalue(self):
+    def test_fillvalue(self):
         "Check that we don't lose the fill_value"
         data = masked_array([1,2,3],fill_value=-999)
         series = data[[0,2,1]]
         assert_equal(series._fill_value, data._fill_value)
     #
-    def check_asarray(self):
+    def test_asarray(self):
         (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
         xmm = asarray(xm)
         assert_equal(xmm._data, xm._data)
         assert_equal(xmm._mask, xm._mask)
     #
-    def check_fix_invalid(self):
+    def test_fix_invalid(self):
         "Checks fix_invalid."
         data = masked_array(numpy.sqrt([-1., 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.])
     #
-    def check_imag_real(self):
+    def test_imag_real(self):
         xx = array([1+10j,20+2j], mask=[1,0])
         assert_equal(xx.imag,[10,2])
         assert_equal(xx.imag.filled(), [1e+20,2])
@@ -807,7 +810,7 @@
         self.d = (array([1.0, 0, -1, pi/2]*2, mask=[0,1]+[0]*6),
                   array([1.0, 0, -1, pi/2]*2, mask=[1,0]+[0]*6),)
 
-    def check_testUfuncRegression(self):
+    def test_testUfuncRegression(self):
         "Tests new ufuncs on MaskedArrays."
         for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',
                   'sin', 'cos', 'tan',
@@ -897,7 +900,7 @@
         self.d =  (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX)
 
     #------------------------------------------------------
-    def check_trace(self):
+    def test_trace(self):
         "Tests trace on MaskedArrays."
         (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d
         mXdiag = mX.diagonal()
@@ -905,7 +908,7 @@
         assert_almost_equal(mX.trace(),
                             X.trace() - sum(mXdiag.mask*X.diagonal(),axis=0))
 
-    def check_clip(self):
+    def test_clip(self):
         "Tests clip on MaskedArrays."
         (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d
         clipped = mx.clip(2,8)
@@ -913,7 +916,7 @@
         assert_equal(clipped.data,x.clip(2,8))
         assert_equal(clipped.data,mx.data.clip(2,8))
 
-    def check_ptp(self):
+    def test_ptp(self):
         "Tests ptp on MaskedArrays."
         (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d
         (n,m) = X.shape
@@ -927,7 +930,7 @@
         assert_equal(mX.ptp(0),cols)
         assert_equal(mX.ptp(1),rows)
 
-    def check_swapaxes(self):
+    def test_swapaxes(self):
         "Tests swapaxes on MaskedArrays."
         (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d
         mXswapped = mX.swapaxes(0,1)
@@ -935,7 +938,7 @@
         mXXswapped = mXX.swapaxes(0,2)
         assert_equal(mXXswapped.shape,(2,2,3,3))
 
-    def check_cumsumprod(self):
+    def test_cumsumprod(self):
         "Tests cumsum & cumprod on MaskedArrays."
         (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d
         mXcp = mX.cumsum(0)
@@ -948,7 +951,7 @@
         mXcp = mX.cumprod(1)
         assert_equal(mXcp.data,mX.filled(1).cumprod(1))
 
-    def check_varstd(self):
+    def test_varstd(self):
         "Tests var & std on MaskedArrays."
         (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d
         assert_almost_equal(mX.var(axis=None),mX.compressed().var())
@@ -961,7 +964,7 @@
             assert_almost_equal(mXvar0[k],mX[:,k].compressed().var())
             assert_almost_equal(numpy.sqrt(mXvar0[k]), mX[:,k].compressed().std())
 
-    def check_argmin(self):
+    def test_argmin(self):
         "Tests argmin & argmax on MaskedArrays."
         (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d
         #
@@ -984,7 +987,7 @@
         assert_equal(mX.argmax(1), [2,4,1,1,4,1])
         assert_equal(m2X.argmax(1), [2,4,1,1,1,1])
 
-    def check_put(self):
+    def test_put(self):
         "Tests put."
         d = arange(5)
         n = [0,0,0,1,1]
@@ -1015,7 +1018,7 @@
         assert_array_equal(x, [0,1,2,3,4,5,6,7,8,9,])
         assert_equal(x.mask, [1,0,0,0,1,1,0,0,0,0])
 
-    def check_put_hardmask(self):
+    def test_put_hardmask(self):
         "Tests put on hardmask"
         d = arange(5)
         n = [0,0,0,1,1]
@@ -1024,7 +1027,7 @@
         xh.put([4,2,0,1,3],[1,2,3,4,5])
         assert_equal(xh._data, [3,4,2,4,5])
 
-    def check_take(self):
+    def test_take(self):
         "Tests take"
         x = masked_array([10,20,30,40],[0,1,0,1])
         assert_equal(x.take([0,0,3]), masked_array([10, 10, 40], [0,0,1]) )
@@ -1038,7 +1041,7 @@
         assert_equal(take(x, [0,2], axis=1),
                       array([[10,30],[40,60]], mask=[[0,1],[1,0]]))
         #........................
-    def check_anyall(self):
+    def test_anyall(self):
         """Checks the any/all methods/functions."""
         x = numpy.array([[ 0.13,  0.26,  0.90],
                      [ 0.28,  0.33,  0.63],
@@ -1086,7 +1089,7 @@
         assert_equal(mXsmall.any(0), numpy.matrix([True,   True, False]))
         assert_equal(mXsmall.any(1), numpy.matrix([True,   True, False]).T)
 
-    def check_keepmask(self):
+    def test_keepmask(self):
         "Tests the keep mask flag"
         x = masked_array([1,2,3], mask=[1,0,0])
         mx = masked_array(x)
@@ -1099,7 +1102,7 @@
         mx = masked_array(x, mask=[0,1,0])
         assert_equal(mx.mask, [1,1,0])
 
-    def check_hardmask(self):
+    def test_hardmask(self):
         "Test hard_mask"
         d = arange(5)
         n = [0,0,0,1,1]
@@ -1166,7 +1169,7 @@
         xh[0:1] = 999
         assert_equal(xh._data,[999,1,2,3,4])
 
-    def check_smallmask(self):
+    def test_smallmask(self):
         "Checks the behaviour of _smallmask"
         a = arange(10)
         a[1] = masked
@@ -1179,7 +1182,7 @@
         assert_equal(a._mask, zeros(10))
 
 
-    def check_sort(self):
+    def test_sort(self):
         "Test sort"
         x = array([1,4,2,3],mask=[0,1,0,0],dtype=numpy.uint8)
         #
@@ -1212,7 +1215,7 @@
         assert_equal(sortedx._data, [1,2,-2,-1,0])
         assert_equal(sortedx._mask, [1,1,0,0,0])
 
-    def check_sort_2d(self):
+    def test_sort_2d(self):
         "Check sort of 2D array."
         # 2D array w/o mask
         a = masked_array([[8,4,1],[2,0,9]])
@@ -1253,7 +1256,7 @@
         assert_equal(am, an)
 
 
-    def check_ravel(self):
+    def test_ravel(self):
         "Tests ravel"
         a = array([[1,2,3,4,5]], mask=[[0,1,0,0,0]])
         aravel = a.ravel()
@@ -1269,7 +1272,7 @@
         a = array([1,2,3,4],mask=[0,0,0,0],shrink=False)
         assert_equal(a.ravel()._mask, [0,0,0,0])
 
-    def check_reshape(self):
+    def test_reshape(self):
         "Tests reshape"
         x = arange(4)
         x[0] = masked
@@ -1279,7 +1282,7 @@
         assert_equal(x.shape, (4,))
         assert_equal(x._mask.shape, (4,))
 
-    def check_compressed(self):
+    def test_compressed(self):
         "Tests compressed"
         a = array([1,2,3,4],mask=[0,0,0,0])
         b = a.compressed()
@@ -1290,7 +1293,7 @@
         assert_equal(b._data, [2,3,4])
         assert_equal(b._mask, nomask)
 
-    def check_tolist(self):
+    def test_tolist(self):
         "Tests to list"
         x = array(numpy.arange(12))
         x[[1,-2]] = masked
@@ -1305,7 +1308,7 @@
         assert_equal(xlist[1],[4,5,6,7])
         assert_equal(xlist[2],[8,9,None,11])
 
-    def check_squeeze(self):
+    def test_squeeze(self):
         "Check squeeze"
         data = masked_array([[1,2,3]])
         assert_equal(data.squeeze(), [1,2,3])
@@ -1315,7 +1318,7 @@
         data = masked_array([[1]], mask=True)
         assert(data.squeeze() is masked)
 
-    def check_putmask(self):
+    def test_putmask(self):
         x = arange(6)+1
         mx = array(x, mask=[0,0,0,1,1,1])
         mask = [0,0,1,0,0,1]
@@ -1345,7 +1348,25 @@
         putmask(mxx, mask, values)
         assert_equal(mxx, [1,2,30,4,5,60])
 
+    def test_ndmin(self):
+        x = array([1,2,3],mask=[1,0,0], ndmin=2)
+        assert_equal(x.shape,(1,3))
+        assert_equal(x._data,[[1,2,3]])
+        assert_equal(x._mask,[[1,0,0]])
 
+    def test_sumprod_masked(self):
+        x = masked_array([1,2,3], mask=True)
+        z = x.min()
+        assert(x.sum() is masked)
+        assert(x.prod() is masked)
+
+    def test_fancy_dtype(self):
+        mtype = [('f',float_),('s','|S3')]
+        x = array([(1,'a'),(2,'b'),(numpy.pi,'pi')], dtype=mtype)
+        x[1] = masked
+        x['f'] = 17
+
+
 #..............................................................................
 
 ###############################################################################



More information about the Numpy-svn mailing list