diff options
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r-- | numpy/testing/utils.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index 2a99fe5cb..4905898d2 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -793,7 +793,7 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): y: array([ 1. , 2.33333, 5. ]) """ - from numpy.core import around, number, float_ + from numpy.core import around, number, float_, result_type, array from numpy.core.numerictypes import issubdtype from numpy.core.fromnumeric import any as npany def compare(x, y): @@ -810,13 +810,22 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): y = y[~yinfid] except (TypeError, NotImplementedError): pass + + # make sure y is an inexact type to avoid abs(MIN_INT); will cause + # casting of x later. + dtype = result_type(y, 1.) + y = array(y, dtype=dtype, copy=False) 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 to %d decimals' % decimal)) + def assert_array_less(x, y, err_msg='', verbose=True): """ Raise an assertion if two array_like objects are not ordered by less than. @@ -1147,6 +1156,8 @@ def assert_allclose(actual, desired, rtol=1e-7, atol=0, It compares the difference between `actual` and `desired` to ``atol + rtol * abs(desired)``. + .. versionadded:: 1.5.0 + Parameters ---------- actual : array_like @@ -1456,6 +1467,7 @@ class WarningManager(object): self._module.filters = self._filters self._module.showwarning = self._showwarning + def assert_warns(warning_class, func, *args, **kw): """ Fail unless the given callable throws the specified warning. @@ -1465,6 +1477,8 @@ def assert_warns(warning_class, func, *args, **kw): If a different type of warning is thrown, it will not be caught, and the test case will be deemed to have suffered an error. + .. versionadded:: 1.4.0 + Parameters ---------- warning_class : class @@ -1496,6 +1510,8 @@ def assert_no_warnings(func, *args, **kw): """ Fail if the given callable produces any warnings. + .. versionadded:: 1.7.0 + Parameters ---------- func : callable |