From 2e58804fe546bf6d476d09ba186c36a69bc577c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoshiki=20V=C3=A1zquez=20Baeza?= Date: Tue, 25 Mar 2014 22:19:03 -0600 Subject: ENH: Add check for ndarray/scalar in build_err_msg This check is needed now that build_err_msg takes a precision argument, which is only relevant if the things being compared are ndarrays. --- numpy/testing/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'numpy/testing/utils.py') diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index b3bb17e61..930900bf2 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -9,8 +9,9 @@ import sys import re import operator import warnings +from functools import partial from .nosetester import import_nose -from numpy.core import float32, empty, arange, array_repr +from numpy.core import float32, empty, arange, array_repr, ndarray if sys.version_info[0] >= 3: from io import StringIO @@ -199,8 +200,15 @@ def build_err_msg(arrays, err_msg, header='Items are not equal:', msg.append(err_msg) if verbose: for i, a in enumerate(arrays): + + if isinstance(a, ndarray): + # precision argument is only needed if the objects are ndarrays + r_func = partial(array_repr, precision=precision) + else: + r_func = repr + try: - r = array_repr(a, precision=precision) + r = r_func(a) except: r = '[repr failed]' if r.count('\n') > 3: -- cgit v1.2.1