diff options
author | David Cournapeau <cournape@gmail.com> | 2008-04-07 21:23:10 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2008-04-07 21:23:10 +0000 |
commit | 51f83997e34aedc774a505dc7e3d9980dd1362f2 (patch) | |
tree | 2b872b99929f394f9ca13a1c2e495c6ee619a618 /numpy/testing/utils.py | |
parent | a5574c3dfef52b36e50dc060c46fbb491f2b2aa2 (diff) | |
download | numpy-51f83997e34aedc774a505dc7e3d9980dd1362f2.tar.gz |
Handling nan values for assert_ functions.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 4f4c3496c..cd0ec9781 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -186,7 +186,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True): 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 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, 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] |