summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorStephan Hoyer <shoyer@google.com>2019-05-13 08:09:26 -0700
committerStephan Hoyer <shoyer@google.com>2019-05-13 08:09:26 -0700
commit07452c86c78a1cf213a764d17f060b4887ec3681 (patch)
tree12c7ae7b14552bd28334277e7e244b603ca4300a /numpy/testing/_private/utils.py
parent804f71bb42fef775a85a52366dc4bd1a22c130a8 (diff)
parent4ad33d21b1a30f931e23307e9f9355b70f633bed (diff)
downloadnumpy-07452c86c78a1cf213a764d17f060b4887ec3681.tar.gz
Merge branch 'master' into implement-numpy-implementation
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index 24e26d65c..ee8eac9e8 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -20,7 +20,7 @@ from warnings import WarningMessage
import pprint
from numpy.core import(
- float32, empty, arange, array_repr, ndarray, isnat, array)
+ intp, float32, empty, arange, array_repr, ndarray, isnat, array)
from numpy.lib.utils import deprecate
if sys.version_info[0] >= 3:
@@ -301,6 +301,11 @@ def assert_equal(actual, desired, err_msg='', verbose=True):
check that all elements of these objects are equal. An exception is raised
at the first conflicting values.
+ This function handles NaN comparisons as if NaN was a "normal" number.
+ That is, no assertion is raised if both objects have NaNs in the same
+ positions. This is in contrast to the IEEE standard on NaNs, which says
+ that NaN compared to anything must return False.
+
Parameters
----------
actual : array_like
@@ -328,6 +333,11 @@ def assert_equal(actual, desired, err_msg='', verbose=True):
ACTUAL: 5
DESIRED: 6
+ The following comparison does not raise an exception. There are NaNs
+ in the inputs, but they are in the same positions.
+
+ >>> np.testing.assert_equal(np.array([1.0, 2.0, np.nan]), [1, 2, np.nan])
+
"""
__tracebackhide__ = True # Hide traceback for py.test
if isinstance(desired, dict):
@@ -784,18 +794,17 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
if isinstance(val, bool):
cond = val
- reduced = [0]
+ reduced = array([val])
else:
reduced = val.ravel()
cond = reduced.all()
- reduced = reduced.tolist()
# The below comparison is a hack to ensure that fully masked
# results, for which val.ravel().all() returns np.ma.masked,
# do not trigger a failure (np.ma.masked != True evaluates as
# np.ma.masked, which is falsy).
if cond != True:
- mismatch = 100.0 * reduced.count(0) / ox.size
+ mismatch = 100. * (reduced.size - reduced.sum(dtype=intp)) / ox.size
remarks = ['Mismatch: {:.3g}%'.format(mismatch)]
with errstate(invalid='ignore', divide='ignore'):
@@ -1441,9 +1450,9 @@ def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True,
Raises an AssertionError if two objects are not equal up to desired
tolerance.
- The test is equivalent to ``allclose(actual, desired, rtol, atol)``.
- It compares the difference between `actual` and `desired` to
- ``atol + rtol * abs(desired)``.
+ The test is equivalent to ``allclose(actual, desired, rtol, atol)`` (note
+ that ``allclose`` has different default values). It compares the difference
+ between `actual` and `desired` to ``atol + rtol * abs(desired)``.
.. versionadded:: 1.5.0