8000 MAINT: Make assert_array_compare more generic. by charris · Pull Request #11756 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Make assert_array_compare more generic. #11756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
equal_inf=True):
__tracebackhide__ = True # Hide traceback for py.test
from numpy.core import array, isnan, inf, bool_
from numpy.core.fromnumeric import all as npall

x = array(x, copy=False, subok=True)
y = array(y, copy=False, subok=True)

Expand All @@ -697,14 +699,21 @@ def istime(x):
return x.dtype.char in "Mm"

def func_assert_same_pos(x, y, func=isnan, hasval='nan'):
"""Handling nan/inf: combine results of running func on x and y,
checking that they are True at the same locations."""
# Both the != True comparison here and the cast to bool_ at
# the end are done to deal with `masked`, which cannot be
# compared usefully, and for which .all() yields masked.
"""Handling nan/inf.

Combine results of running func on x and y, checking that they are True
at the same locations.

"""
# Both the != True comparison here and the cast to bool_ at the end are
# done to deal with `masked`, which cannot be compared usefully, and
# for which np.all yields masked. The use of the function np.all is
# for back compatibility with ndarray subclasses that changed the
# return values of the all method. We are not committed to supporting
# such subclasses, but some used to work.
x_id = func(x)
y_id = func(y)
if (x_id == y_id).all() != True:
if npall(x_id == y_id) != True:
msg = build_err_msg([x, y],
err_msg + '\nx and y %s location mismatch:'
% (hasval), verbose=verbose, header=header,
Expand Down
0