From be5ea7d92d542e7c7eb055c5831a79850f4bfbee Mon Sep 17 00:00:00 2001 From: "wtli@Dirac" Date: Mon, 22 Oct 2018 22:30:32 +0800 Subject: BUG: Fix misleading assert message in assert_almost_equal #12200 Fixes #12200 by making a copy of the matrix before NaN's are excluded. Add a test for it. --- numpy/testing/_private/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'numpy/testing/_private') diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index a3832fcde..24b32cf00 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -692,6 +692,9 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, x = array(x, copy=False, subok=True) y = array(y, copy=False, subok=True) + # original array for output formating + ox, oy = x, y + def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' @@ -780,10 +783,10 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: - match = 100-100.0*reduced.count(1)/len(reduced) - msg = build_err_msg([x, y], + mismatch = 100.0 * reduced.count(0) / ox.size + msg = build_err_msg([ox, oy], err_msg - + '\n(mismatch %s%%)' % (match,), + + '\n(mismatch %s%%)' % (mismatch,), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) -- cgit v1.2.1