summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2009-03-09 20:49:55 +0000
committerPauli Virtanen <pav@iki.fi>2009-03-09 20:49:55 +0000
commit9d6b9b91b1a93be49d46b0f4afe78c7fa3a28e3f (patch)
treecddc751dcfc518326da358dbe96545caae1af70a /numpy/testing/utils.py
parentde6264438e148882e58f5925f9176966216b940f (diff)
downloadnumpy-9d6b9b91b1a93be49d46b0f4afe78c7fa3a28e3f.tar.gz
Fixed #745: make assert_array_almost_equal work with object arrays
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index 56512364d..d0bfd11db 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -310,9 +310,13 @@ def assert_array_equal(x, y, err_msg='', verbose=True):
verbose=verbose, header='Arrays are not equal')
def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
- from numpy.core import around
+ from numpy.core import around, number, float_
+ from numpy.lib import issubdtype
def compare(x, y):
- return around(abs(x-y),decimal) <= 10.0**(-decimal)
+ z = abs(x-y)
+ if not issubdtype(z.dtype, number):
+ z = z.astype(float_) # handle object arrays
+ return around(z, decimal) <= 10.0**(-decimal)
assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
header='Arrays are not almost equal')