diff options
author | seberg <sebastian@sipsolutions.net> | 2017-01-10 11:04:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 11:04:37 +0100 |
commit | 124c3d809d5b2cca79957299ed126efd1300dffe (patch) | |
tree | a0d4683c78934680ec4fc53a140f3863f985a0ab /numpy/testing/utils.py | |
parent | 83fe06df889c2c3166969bf9615018cb2f239cad (diff) | |
parent | fe46cd691cde2a707ea727d65414cf7285969bbe (diff) | |
download | numpy-124c3d809d5b2cca79957299ed126efd1300dffe.tar.gz |
Merge pull request #8452 from mhvk/testing-avoid-subclass-bool-arrays
BUG: assert_almost_equal fails on subclasses that cannot handle bool
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 7858eefac..a44a51c81 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -669,8 +669,7 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True): __tracebackhide__ = True # Hide traceback for py.test - from numpy.core import array, isnan, isinf, any, all, inf, zeros_like - from numpy.core.numerictypes import bool_ + from numpy.core import array, isnan, isinf, any, inf x = array(x, copy=False, subok=True) y = array(y, copy=False, subok=True) @@ -726,14 +725,13 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, raise AssertionError(msg) if isnumber(x) and isnumber(y): - x_id, y_id = zeros_like(x, dtype=bool_), zeros_like(y, dtype=bool_) if equal_nan: x_isnan, y_isnan = isnan(x), isnan(y) # Validate that NaNs are in the same place if any(x_isnan) or any(y_isnan): chk_same_position(x_isnan, y_isnan, hasval='nan') - x_id |= x_isnan - y_id |= y_isnan + x = x[~x_isnan] + y = y[~y_isnan] if equal_inf: x_isinf, y_isinf = isinf(x), isinf(y) @@ -742,19 +740,14 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, # Check +inf and -inf separately, since they are different chk_same_position(x == +inf, y == +inf, hasval='+inf') chk_same_position(x == -inf, y == -inf, hasval='-inf') - x_id |= x_isinf - y_id |= y_isinf + x = x[~x_isinf] + y = y[~y_isinf] # Only do the comparison if actual values are left - if all(x_id): + if x.size == 0: return - if any(x_id): - val = safe_comparison(x[~x_id], y[~y_id]) - else: - val = safe_comparison(x, y) - else: - val = safe_comparison(x, y) + val = safe_comparison(x, y) if isinstance(val, bool): cond = val |