diff options
author | David Cournapeau <cournape@gmail.com> | 2009-07-27 08:07:48 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-07-27 08:07:48 +0000 |
commit | e8b88c2d0529f2dac153e04537cf05d435a27a07 (patch) | |
tree | 5066d19d50bb9bb7c023d8f2c79a88e2f91940dd /numpy/testing/utils.py | |
parent | 56caa44161152ffd4f354757c8d4d42007413f79 (diff) | |
download | numpy-e8b88c2d0529f2dac153e04537cf05d435a27a07.tar.gz |
BUG: handle nan/inf in assert_approx_equal.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 9928bbb90..b3a9cebcf 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -384,6 +384,20 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True): header='Items are not equal to %d significant digits:' % significant, verbose=verbose) + try: + # If one of desired/actual is not finite, handle it specially here: + # check that both are nan if any is a nan, and test for equality + # otherwise + if not (gisfinite(desired) and gisfinite(actual)): + if gisnan(desired) or gisnan(actual): + if not (gisnan(desired) and gisnan(actual)): + raise AssertionError(msg) + else: + if not desired == actual: + raise AssertionError(msg) + return + except TypeError: + pass if math.fabs(sc_desired - sc_actual) >= pow(10.,-(significant-1)) : raise AssertionError(msg) |