[Numpy-svn] r4974 - trunk/numpy/testing
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Apr 7 17:23:12 EDT 2008
Author: cdavid
Date: 2008-04-07 16:23:10 -0500 (Mon, 07 Apr 2008)
New Revision: 4974
Modified:
trunk/numpy/testing/utils.py
Log:
Handling nan values for assert_ functions.
Modified: trunk/numpy/testing/utils.py
===================================================================
--- trunk/numpy/testing/utils.py 2008-04-07 18:12:09 UTC (rev 4973)
+++ trunk/numpy/testing/utils.py 2008-04-07 21:23:10 UTC (rev 4974)
@@ -186,7 +186,7 @@
def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
header=''):
- from numpy.core import asarray
+ from numpy.core import asarray, isnan
x = asarray(x)
y = asarray(y)
try:
@@ -199,7 +199,24 @@
verbose=verbose, header=header,
names=('x', 'y'))
assert cond, msg
- val = comparison(x,y)
+ if isnan(x) or isnan(y):
+ # Handling nan: we first check that x and y have the nan at the
+ # same locations, and then we mask the nan and do the comparison as
+ # usual.
+ xnanid = isnan(x)
+ ynanid = isnan(y)
+ try:
+ assert_array_equal(xnanid, ynanid)
+ except AssertionError:
+ msg = build_err_msg([x, y],
+ err_msg
+ + '\n(x and y nan location mismatch %s, '
+ + '%s mismatch)' % (xnanid, ynanid),
+ verbose=verbose, header=header,
+ names=('x', 'y'))
+ val = comparison(x[~xnanid], y[~ynanid])
+ else:
+ val = comparison(x,y)
if isinstance(val, bool):
cond = val
reduced = [0]
More information about the Numpy-svn
mailing list