[Numpy-svn] r5326 - in branches/1.1.x/numpy/ma: . tests

numpy-svn@scip... numpy-svn@scip...
Mon Jun 30 09:55:27 CDT 2008


Author: pierregm
Date: 2008-06-30 09:55:14 -0500 (Mon, 30 Jun 2008)
New Revision: 5326

Modified:
   branches/1.1.x/numpy/ma/tests/test_core.py
   branches/1.1.x/numpy/ma/tests/test_extras.py
   branches/1.1.x/numpy/ma/testutils.py
Log:
tests:
* use the `import numpy as np` convention

testutils:
* assert_equal_records now uses getitem instead of getattr
* assert_array_compare now calls numpy.testing.utils.assert_array_compare on filled data 


Modified: branches/1.1.x/numpy/ma/tests/test_core.py
===================================================================
--- branches/1.1.x/numpy/ma/tests/test_core.py	2008-06-30 07:11:53 UTC (rev 5325)
+++ branches/1.1.x/numpy/ma/tests/test_core.py	2008-06-30 14:55:14 UTC (rev 5326)
@@ -1276,7 +1276,7 @@
         #
         x = [1,4,2,3]
         sortedx = sort(x)
-        assert(not isinstance(sorted, MaskedArray))
+        assert(not isinstance(sortedx, MaskedArray))
         #
         x = array([0,1,-1,-2,2], mask=nomask, dtype=numpy.int8)
         sortedx = sort(x, endwith=False)

Modified: branches/1.1.x/numpy/ma/tests/test_extras.py
===================================================================
--- branches/1.1.x/numpy/ma/tests/test_extras.py	2008-06-30 07:11:53 UTC (rev 5325)
+++ branches/1.1.x/numpy/ma/tests/test_extras.py	2008-06-30 14:55:14 UTC (rev 5326)
@@ -11,21 +11,15 @@
 __revision__ = "$Revision: 3473 $"
 __date__     = '$Date: 2007-10-29 17:18:13 +0200 (Mon, 29 Oct 2007) $'
 
-import numpy as N
-from numpy.testing import NumpyTest, NumpyTestCase
-from numpy.testing.utils import build_err_msg
-
-import numpy.ma.testutils
+import numpy
+from numpy.testing import *
 from numpy.ma.testutils import *
-
-import numpy.ma.core
 from numpy.ma.core import *
-import numpy.ma.extras
 from numpy.ma.extras import *
 
 class TestAverage(NumpyTestCase):
     "Several tests of average. Why so many ? Good point..."
-    def check_testAverage1(self):
+    def test_testAverage1(self):
         "Test of average."
         ott = array([0.,1.,2.,3.], mask=[1,0,0,0])
         assert_equal(2.0, average(ott,axis=0))
@@ -44,7 +38,7 @@
         result, wts = average(ott, axis=0, returned=1)
         assert_equal(wts, [1., 0.])
 
-    def check_testAverage2(self):
+    def test_testAverage2(self):
         "More tests of average."
         w1 = [0,1,1,1,1,0]
         w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]
@@ -52,12 +46,15 @@
         assert_equal(average(x, axis=0), 2.5)
         assert_equal(average(x, axis=0, weights=w1), 2.5)
         y = array([arange(6, dtype=float_), 2.0*arange(6)])
-        assert_equal(average(y, None), N.add.reduce(N.arange(6))*3./12.)
-        assert_equal(average(y, axis=0), N.arange(6) * 3./2.)
-        assert_equal(average(y, axis=1), [average(x,axis=0), average(x,axis=0) * 2.0])
+        assert_equal(average(y, None), np.add.reduce(np.arange(6))*3./12.)
+        assert_equal(average(y, axis=0), np.arange(6) * 3./2.)
+        assert_equal(average(y, axis=1), 
+                     [average(x,axis=0), average(x,axis=0) * 2.0])
         assert_equal(average(y, None, weights=w2), 20./6.)
-        assert_equal(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.])
-        assert_equal(average(y, axis=1), [average(x,axis=0), average(x,axis=0) * 2.0])
+        assert_equal(average(y, axis=0, weights=w2),
+                     [0.,1.,2.,3.,4.,10.])
+        assert_equal(average(y, axis=1),
+                     [average(x,axis=0), average(x,axis=0) * 2.0])
         m1 = zeros(6)
         m2 = [0,0,1,1,0,0]
         m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]
@@ -74,7 +71,7 @@
         assert_equal(average(z, axis=1), [2.5, 5.0])
         assert_equal(average(z,axis=0, weights=w2), [0.,1., 99., 99., 4.0, 10.0])
 
-    def check_testAverage3(self):
+    def test_testAverage3(self):
         "Yet more tests of average!"
         a = arange(6)
         b = arange(6) * 3
@@ -100,7 +97,7 @@
 
 class TestConcatenator(NumpyTestCase):
     "Tests for mr_, the equivalent of r_ for masked arrays."
-    def check_1d(self):
+    def test_1d(self):
         "Tests mr_ on 1D arrays."
         assert_array_equal(mr_[1,2,3,4,5,6],array([1,2,3,4,5,6]))
         b = ones(5)
@@ -111,30 +108,30 @@
         assert_array_equal(c,[1,1,1,1,1,0,0,1,1,1,1,1])
         assert_array_equal(c.mask, mr_[m,0,0,m])
 
-    def check_2d(self):
+    def test_2d(self):
         "Tests mr_ on 2D arrays."
         a_1 = rand(5,5)
         a_2 = rand(5,5)
-        m_1 = N.round_(rand(5,5),0)
-        m_2 = N.round_(rand(5,5),0)
+        m_1 = np.round_(rand(5,5),0)
+        m_2 = np.round_(rand(5,5),0)
         b_1 = masked_array(a_1,mask=m_1)
         b_2 = masked_array(a_2,mask=m_2)
         d = mr_['1',b_1,b_2]  # append columns
         assert(d.shape == (5,10))
         assert_array_equal(d[:,:5],b_1)
         assert_array_equal(d[:,5:],b_2)
-        assert_array_equal(d.mask, N.r_['1',m_1,m_2])
+        assert_array_equal(d.mask, np.r_['1',m_1,m_2])
         d = mr_[b_1,b_2]
         assert(d.shape == (10,5))
         assert_array_equal(d[:5,:],b_1)
         assert_array_equal(d[5:,:],b_2)
-        assert_array_equal(d.mask, N.r_[m_1,m_2])
+        assert_array_equal(d.mask, np.r_[m_1,m_2])
 
 class TestNotMasked(NumpyTestCase):
     "Tests notmasked_edges and notmasked_contiguous."
-    def check_edges(self):
+    def test_edges(self):
         "Tests unmasked_edges"
-        a = masked_array(N.arange(24).reshape(3,8),
+        a = masked_array(np.arange(24).reshape(3,8),
                          mask=[[0,0,0,0,1,1,1,0],
                                [1,1,1,1,1,1,1,1],
                                [0,0,0,0,0,0,1,0],])
@@ -149,9 +146,9 @@
         assert_equal(tmp[0], (array([0,2,]), array([0,0])))
         assert_equal(tmp[1], (array([0,2,]), array([7,7])))
 
-    def check_contiguous(self):
+    def test_contiguous(self):
         "Tests notmasked_contiguous"
-        a = masked_array(N.arange(24).reshape(3,8),
+        a = masked_array(np.arange(24).reshape(3,8),
                          mask=[[0,0,0,0,1,1,1,1],
                                [1,1,1,1,1,1,1,1],
                                [0,0,0,0,0,0,1,0],])
@@ -174,9 +171,9 @@
 
 class Test2DFunctions(NumpyTestCase):
     "Tests 2D functions"
-    def check_compress2d(self):
+    def test_compress2d(self):
         "Tests compress2d"
-        x = array(N.arange(9).reshape(3,3), mask=[[1,0,0],[0,0,0],[0,0,0]])
+        x = array(np.arange(9).reshape(3,3), mask=[[1,0,0],[0,0,0],[0,0,0]])
         assert_equal(compress_rowcols(x), [[4,5],[7,8]] )
         assert_equal(compress_rowcols(x,0), [[3,4,5],[6,7,8]] )
         assert_equal(compress_rowcols(x,1), [[1,2],[4,5],[7,8]] )
@@ -193,9 +190,9 @@
         assert_equal(compress_rowcols(x,0).size, 0 )
         assert_equal(compress_rowcols(x,1).size, 0 )
     #
-    def check_mask_rowcols(self):
+    def test_mask_rowcols(self):
         "Tests mask_rowcols."
-        x = array(N.arange(9).reshape(3,3), mask=[[1,0,0],[0,0,0],[0,0,0]])
+        x = array(np.arange(9).reshape(3,3), mask=[[1,0,0],[0,0,0],[0,0,0]])
         assert_equal(mask_rowcols(x).mask, [[1,1,1],[1,0,0],[1,0,0]] )
         assert_equal(mask_rowcols(x,0).mask, [[1,1,1],[0,0,0],[0,0,0]] )
         assert_equal(mask_rowcols(x,1).mask, [[1,0,0],[1,0,0],[1,0,0]] )
@@ -208,13 +205,16 @@
         assert_equal(mask_rowcols(x,0).mask, [[1,1,1],[1,1,1],[0,0,0]] )
         assert_equal(mask_rowcols(x,1,).mask, [[1,1,0],[1,1,0],[1,1,0]] )
         x = array(x._data, mask=[[1,0,0],[0,1,0],[0,0,1]])
-        assert(mask_rowcols(x).all())
-        assert(mask_rowcols(x,0).all())
-        assert(mask_rowcols(x,1).all())
+        assert(mask_rowcols(x).all() is masked)
+        assert(mask_rowcols(x,0).all() is masked)
+        assert(mask_rowcols(x,1).all() is masked)
+        assert(mask_rowcols(x).mask.all())
+        assert(mask_rowcols(x,0).mask.all())
+        assert(mask_rowcols(x,1).mask.all())
     #
     def test_dot(self):
         "Tests dot product"
-        n = N.arange(1,7)
+        n = np.arange(1,7)
         #
         m = [1,0,0,0,0,0]
         a = masked_array(n, mask=m).reshape(2,3)
@@ -224,9 +224,9 @@
         c = dot(b,a,True)
         assert_equal(c.mask, [[1,1,1],[1,0,0],[1,0,0]])
         c = dot(a,b,False)
-        assert_equal(c, N.dot(a.filled(0), b.filled(0)))
+        assert_equal(c, np.dot(a.filled(0), b.filled(0)))
         c = dot(b,a,False)
-        assert_equal(c, N.dot(b.filled(0), a.filled(0)))
+        assert_equal(c, np.dot(b.filled(0), a.filled(0)))
         #
         m = [0,0,0,0,0,1]
         a = masked_array(n, mask=m).reshape(2,3)
@@ -236,10 +236,10 @@
         c = dot(b,a,True)
         assert_equal(c.mask, [[0,0,1],[0,0,1],[1,1,1]])
         c = dot(a,b,False)
-        assert_equal(c, N.dot(a.filled(0), b.filled(0)))
+        assert_equal(c, np.dot(a.filled(0), b.filled(0)))
         assert_equal(c, dot(a,b))
         c = dot(b,a,False)
-        assert_equal(c, N.dot(b.filled(0), a.filled(0)))
+        assert_equal(c, np.dot(b.filled(0), a.filled(0)))
         #
         m = [0,0,0,0,0,0]
         a = masked_array(n, mask=m).reshape(2,3)
@@ -254,37 +254,37 @@
         c = dot(a,b,True)
         assert_equal(c.mask,[[1,1],[0,0]])
         c = dot(a,b,False)
-        assert_equal(c, N.dot(a.filled(0),b.filled(0)))
+        assert_equal(c, np.dot(a.filled(0),b.filled(0)))
         c = dot(b,a,True)
         assert_equal(c.mask,[[1,0,0],[1,0,0],[1,0,0]])
         c = dot(b,a,False)
-        assert_equal(c, N.dot(b.filled(0),a.filled(0)))
+        assert_equal(c, np.dot(b.filled(0),a.filled(0)))
         #
         a = masked_array(n, mask=[0,0,0,0,0,1]).reshape(2,3)
         b = masked_array(n, mask=[0,0,0,0,0,0]).reshape(3,2)
         c = dot(a,b,True)
         assert_equal(c.mask,[[0,0],[1,1]])
         c = dot(a,b)
-        assert_equal(c, N.dot(a.filled(0),b.filled(0)))
+        assert_equal(c, np.dot(a.filled(0),b.filled(0)))
         c = dot(b,a,True)
         assert_equal(c.mask,[[0,0,1],[0,0,1],[0,0,1]])
         c = dot(b,a,False)
-        assert_equal(c, N.dot(b.filled(0), a.filled(0)))
+        assert_equal(c, np.dot(b.filled(0), a.filled(0)))
         #
         a = masked_array(n, mask=[0,0,0,0,0,1]).reshape(2,3)
         b = masked_array(n, mask=[0,0,1,0,0,0]).reshape(3,2)
         c = dot(a,b,True)
         assert_equal(c.mask,[[1,0],[1,1]])
         c = dot(a,b,False)
-        assert_equal(c, N.dot(a.filled(0),b.filled(0)))
+        assert_equal(c, np.dot(a.filled(0),b.filled(0)))
         c = dot(b,a,True)
         assert_equal(c.mask,[[0,0,1],[1,1,1],[0,0,1]])
         c = dot(b,a,False)
-        assert_equal(c, N.dot(b.filled(0),a.filled(0)))
+        assert_equal(c, np.dot(b.filled(0),a.filled(0)))
 
     def test_ediff1d(self):
         "Tests mediff1d"
-        x = masked_array(N.arange(5), mask=[1,0,0,0,1])
+        x = masked_array(np.arange(5), mask=[1,0,0,0,1])
         difx_d = (x._data[1:]-x._data[:-1])
         difx_m = (x._mask[1:]-x._mask[:-1])
         dx = ediff1d(x)
@@ -292,33 +292,33 @@
         assert_equal(dx._mask, difx_m)
         #
         dx = ediff1d(x, to_begin=masked)
-        assert_equal(dx._data, N.r_[0,difx_d])
-        assert_equal(dx._mask, N.r_[1,difx_m])
+        assert_equal(dx._data, np.r_[0,difx_d])
+        assert_equal(dx._mask, np.r_[1,difx_m])
         dx = ediff1d(x, to_begin=[1,2,3])
-        assert_equal(dx._data, N.r_[[1,2,3],difx_d])
-        assert_equal(dx._mask, N.r_[[0,0,0],difx_m])
+        assert_equal(dx._data, np.r_[[1,2,3],difx_d])
+        assert_equal(dx._mask, np.r_[[0,0,0],difx_m])
         #
         dx = ediff1d(x, to_end=masked)
-        assert_equal(dx._data, N.r_[difx_d,0])
-        assert_equal(dx._mask, N.r_[difx_m,1])
+        assert_equal(dx._data, np.r_[difx_d,0])
+        assert_equal(dx._mask, np.r_[difx_m,1])
         dx = ediff1d(x, to_end=[1,2,3])
-        assert_equal(dx._data, N.r_[difx_d,[1,2,3]])
-        assert_equal(dx._mask, N.r_[difx_m,[0,0,0]])
+        assert_equal(dx._data, np.r_[difx_d,[1,2,3]])
+        assert_equal(dx._mask, np.r_[difx_m,[0,0,0]])
         #
         dx = ediff1d(x, to_end=masked, to_begin=masked)
-        assert_equal(dx._data, N.r_[0,difx_d,0])
-        assert_equal(dx._mask, N.r_[1,difx_m,1])
+        assert_equal(dx._data, np.r_[0,difx_d,0])
+        assert_equal(dx._mask, np.r_[1,difx_m,1])
         dx = ediff1d(x, to_end=[1,2,3], to_begin=masked)
-        assert_equal(dx._data, N.r_[0,difx_d,[1,2,3]])
-        assert_equal(dx._mask, N.r_[1,difx_m,[0,0,0]])
+        assert_equal(dx._data, np.r_[0,difx_d,[1,2,3]])
+        assert_equal(dx._mask, np.r_[1,difx_m,[0,0,0]])
         #
         dx = ediff1d(x._data, to_end=masked, to_begin=masked)
-        assert_equal(dx._data, N.r_[0,difx_d,0])
-        assert_equal(dx._mask, N.r_[1,0,0,0,0,1])
+        assert_equal(dx._data, np.r_[0,difx_d,0])
+        assert_equal(dx._mask, np.r_[1,0,0,0,0,1])
 
 class TestApplyAlongAxis(NumpyTestCase):
     "Tests 2D functions"
-    def check_3d(self):
+    def test_3d(self):
         a = arange(12.).reshape(2,2,3)
         def myfunc(b):
             return b[1]

Modified: branches/1.1.x/numpy/ma/testutils.py
===================================================================
--- branches/1.1.x/numpy/ma/testutils.py	2008-06-30 07:11:53 UTC (rev 5325)
+++ branches/1.1.x/numpy/ma/testutils.py	2008-06-30 14:55:14 UTC (rev 5326)
@@ -10,16 +10,18 @@
 __date__ = "$Date: 2007-11-13 10:01:14 +0200 (Tue, 13 Nov 2007) $"
 
 
-import numpy as N
-from numpy.core import ndarray
-from numpy.core.numerictypes import float_
+import operator
+
+import numpy as np
+from numpy import ndarray, float_
 import numpy.core.umath as umath
-from numpy.testing import NumpyTest, NumpyTestCase
+from numpy.testing import *
 from numpy.testing.utils import build_err_msg, rand
+import numpy.testing.utils as utils
 
 import core
 from core import mask_or, getmask, getmaskarray, masked_array, nomask, masked
-from core import filled, equal, less
+from core import fix_invalid, filled, equal, less
 
 #------------------------------------------------------------------------------
 def approx (a, b, fill_value=True, rtol=1.e-5, atol=1.e-8):
@@ -35,12 +37,13 @@
     d1 = filled(a)
     d2 = filled(b)
     if d1.dtype.char == "O" or d2.dtype.char == "O":
-        return N.equal(d1,d2).ravel()
+        return np.equal(d1,d2).ravel()
     x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)
     y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_)
-    d = N.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))
+    d = np.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))
     return d.ravel()
 
+
 def almost(a, b, decimal=6, fill_value=True):
     """Returns True if a and b are equal up to decimal places.
 If fill_value is True, masked values considered equal. Otherwise, masked values
@@ -50,10 +53,10 @@
     d1 = filled(a)
     d2 = filled(b)
     if d1.dtype.char == "O" or d2.dtype.char == "O":
-        return N.equal(d1,d2).ravel()
+        return np.equal(d1,d2).ravel()
     x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)
     y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_)
-    d = N.around(N.abs(x-y),decimal) <= 10.0**(-decimal)
+    d = np.around(np.abs(x-y),decimal) <= 10.0**(-decimal)
     return d.ravel()
 
 
@@ -69,11 +72,12 @@
     """Asserts that two records are equal. Pretty crude for now."""
     assert_equal(a.dtype, b.dtype)
     for f in a.dtype.names:
-        (af, bf) = (getattr(a,f), getattr(b,f))
+        (af, bf) = (operator.getitem(a,f), operator.getitem(b,f))
         if not (af is masked) and not (bf is masked):
-            assert_equal(getattr(a,f), getattr(b,f))
+            assert_equal(operator.getitem(a,f), operator.getitem(b,f))
     return
 
+
 def assert_equal(actual,desired,err_msg=''):
     """Asserts that two items are equal.
     """
@@ -95,16 +99,18 @@
     # 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'))
+        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":
+    actual = np.array(actual, copy=False, subok=True)
+    desired = np.array(desired, copy=False, subok=True)
+    if actual.dtype.char in "OSV" and desired.dtype.char in "OSV":
         return _assert_equal_on_sequences(actual.tolist(),
                                           desired.tolist(),
                                           err_msg='')
     return assert_array_equal(actual, desired, err_msg)
-#.............................
+
+
 def fail_if_equal(actual,desired,err_msg='',):
     """Raises an assertion error if two items are equal.
     """
@@ -120,119 +126,91 @@
         for k in range(len(desired)):
             fail_if_equal(actual[k], desired[k], 'item=%r\n%s' % (k,err_msg))
         return
-    if isinstance(actual, N.ndarray) or isinstance(desired, N.ndarray):
+    if isinstance(actual, np.ndarray) or isinstance(desired, np.ndarray):
         return fail_if_array_equal(actual, desired, err_msg)
     msg = build_err_msg([actual, desired], err_msg)
     assert desired != actual, msg
 assert_not_equal = fail_if_equal
-#............................
-def assert_almost_equal(actual,desired,decimal=7,err_msg=''):
+
+
+def assert_almost_equal(actual, desired, decimal=7, err_msg='', verbose=True):
     """Asserts that two items are almost equal.
     The test is equivalent to abs(desired-actual) < 0.5 * 10**(-decimal)
     """
-    if isinstance(actual, N.ndarray) or isinstance(desired, N.ndarray):
-        return assert_array_almost_equal(actual, desired, decimal, err_msg)
-    msg = build_err_msg([actual, desired], err_msg)
+    if isinstance(actual, np.ndarray) or isinstance(desired, np.ndarray):
+        return assert_array_almost_equal(actual, desired, decimal=decimal, 
+                                         err_msg=err_msg, verbose=verbose)
+    msg = build_err_msg([actual, desired], 
+                        err_msg=err_msg, verbose=verbose)
     assert round(abs(desired - actual),decimal) == 0, msg
-#............................
-def assert_array_compare(comparison, x, y, err_msg='', header='',
+
+
+assert_close = assert_almost_equal
+
+
+def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='',
                          fill_value=True):
     """Asserts that a comparison relation between two masked arrays is satisfied
     elementwise."""
+    # Fill the data first
     xf = filled(x)
     yf = filled(y)
+    # Allocate a common mask and refill
     m = mask_or(getmask(x), getmask(y))
-
-    x = masked_array(xf, copy=False, subok=False, mask=m).filled(fill_value)
-    y = masked_array(yf, copy=False, subok=False, mask=m).filled(fill_value)
-
+    x = masked_array(xf, copy=False, mask=m)
+    y = masked_array(yf, copy=False, mask=m)
     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'))
+        msg = build_err_msg([x, y], err_msg=err_msg, verbose=verbose, 
+                            header=header, names=('x', 'y'))
         raise ValueError(msg)
+    # OK, now run the basic tests on filled versions
+    return utils.assert_array_compare(comparison, 
+                                x.filled(fill_value), y.filled(fill_value), 
+                                err_msg=err_msg, 
+                                verbose=verbose, header=header)
 
-    if (x.dtype.char != "O") and (x.dtype.char != "S"):
-        x = x.astype(float_)
-        if isinstance(x, N.ndarray) and x.size > 1:
-            x[N.isnan(x)] = 0
-        elif N.isnan(x):
-            x = 0
-    if (y.dtype.char != "O") and (y.dtype.char != "S"):
-        y = y.astype(float_)
-        if isinstance(y, N.ndarray) and y.size > 1:
-            y[N.isnan(y)] = 0
-        elif N.isnan(y):
-            y = 0
-    try:
-        cond = (x.shape==() or y.shape==()) or x.shape == y.shape
-        if not cond:
-            msg = build_err_msg([x, y],
-                                err_msg
-                                + '\n(shapes %s, %s mismatch)' % (x.shape,
-                                                                  y.shape),
-                                header=header,
-                                names=('x', 'y'))
-            assert cond, msg
-        val = comparison(x,y)
-        if m is not nomask and fill_value:
-            val = masked_array(val, mask=m, copy=False)
-        if isinstance(val, bool):
-            cond = val
-            reduced = [0]
-        else:
-            reduced = val.ravel()
-            cond = reduced.all()
-            reduced = reduced.tolist()
-        if not cond:
-            match = 100-100.0*reduced.count(1)/len(reduced)
-            msg = build_err_msg([x, y],
-                                err_msg
-                                + '\n(mismatch %s%%)' % (match,),
-                                header=header,
-                                names=('x', 'y'))
-            assert cond, msg
-    except ValueError:
-        msg = build_err_msg([x, y], err_msg, header=header, names=('x', 'y'))
-        raise ValueError(msg)
-#............................
-def assert_array_equal(x, y, err_msg=''):
+
+def assert_array_equal(x, y, err_msg='', verbose=True):
     """Checks the elementwise equality of two masked arrays."""
-    assert_array_compare(equal, x, y, err_msg=err_msg,
+    assert_array_compare(equal, x, y, err_msg=err_msg, verbose=verbose,
                          header='Arrays are not equal')
-##............................
-def fail_if_array_equal(x, y, err_msg=''):
+
+
+def fail_if_array_equal(x, y, err_msg='', verbose=True):
     "Raises an assertion error if two masked arrays are not equal (elementwise)."
     def compare(x,y):
-
-        return (not N.alltrue(approx(x, y)))
-    assert_array_compare(compare, x, y, err_msg=err_msg,
+        return (not np.alltrue(approx(x, y)))
+    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
                          header='Arrays are not equal')
-#............................
-def assert_array_approx_equal(x, y, decimal=6, err_msg=''):
+
+
+def assert_array_approx_equal(x, y, decimal=6, err_msg='', verbose=True):
     """Checks the elementwise equality of two masked arrays, up to a given
     number of decimals."""
     def compare(x, y):
         "Returns the result of the loose comparison between x and y)."
         return approx(x,y, rtol=10.**-decimal)
-    assert_array_compare(compare, x, y, err_msg=err_msg,
+    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
                          header='Arrays are not almost equal')
-#............................
-def assert_array_almost_equal(x, y, decimal=6, err_msg=''):
+
+
+def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
     """Checks the elementwise equality of two masked arrays, up to a given
     number of decimals."""
     def compare(x, y):
         "Returns the result of the loose comparison between x and y)."
         return almost(x,y,decimal)
-    assert_array_compare(compare, x, y, err_msg=err_msg,
+    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
                          header='Arrays are not almost equal')
-#............................
-def assert_array_less(x, y, err_msg=''):
+
+
+def assert_array_less(x, y, err_msg='', verbose=True):
     "Checks that x is smaller than y elementwise."
-    assert_array_compare(less, x, y, err_msg=err_msg,
+    assert_array_compare(less, x, y, err_msg=err_msg, verbose=verbose,
                          header='Arrays are not less-ordered')
-#............................
-assert_close = assert_almost_equal
-#............................
+
+
 def assert_mask_equal(m1, m2):
     """Asserts the equality of two masks."""
     if m1 is nomask:
@@ -240,6 +218,3 @@
     if m2 is nomask:
         assert(m1 is nomask)
     assert_array_equal(m1, m2)
-
-if __name__ == '__main__':
-    pass



More information about the Numpy-svn mailing list