summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorwarren <warren.weckesser@gmail.com>2023-02-16 07:14:32 -0500
committerwarren <warren.weckesser@gmail.com>2023-02-16 07:14:32 -0500
commitabfaac73be054db5b3555315d56825d2e683e02f (patch)
tree1ea8a603cc3cf861fc1a5ad1c3bf54bf6518bb94 /numpy/testing/_private/utils.py
parent51ecf84013a6c8325f9dd0571a48794fc0e448a4 (diff)
downloadnumpy-abfaac73be054db5b3555315d56825d2e683e02f.tar.gz
MAINT: testing: Fix some whitespace and minor code issues in utils.py
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index 44092f185..6ceea5771 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -19,7 +19,7 @@ import pprint
import sysconfig
import numpy as np
-from numpy.core import(
+from numpy.core import (
intp, float32, empty, arange, array_repr, ndarray, isnat, array)
import numpy.linalg.lapack_lite
@@ -470,7 +470,7 @@ def print_assert_equal(test_string, actual, desired):
@np._no_nep50_warning()
-def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
+def assert_almost_equal(actual, desired, decimal=7, err_msg='', verbose=True):
"""
Raises an AssertionError if two items are not equal up to desired
precision.
@@ -597,7 +597,8 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
@np._no_nep50_warning()
-def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True):
+def assert_approx_equal(actual, desired, significant=7, err_msg='',
+ verbose=True):
"""
Raises an AssertionError if two items are not equal up to significant
digits.
@@ -701,7 +702,8 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='',
precision=6, equal_nan=True, equal_inf=True,
*, strict=False):
__tracebackhide__ = True # Hide traceback for py.test
- from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_
+ from numpy.core import (array2string, isnan, inf, bool_, errstate,
+ all, max, object_)
x = np.asanyarray(x)
y = np.asanyarray(y)
@@ -827,10 +829,10 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='',
max_abs_error = max(error)
if getattr(error, 'dtype', object_) == object_:
remarks.append('Max absolute difference: '
- + str(max_abs_error))
+ + str(max_abs_error))
else:
remarks.append('Max absolute difference: '
- + array2string(max_abs_error))
+ + array2string(max_abs_error))
# note: this definition of relative error matches that one
# used by assert_allclose (found in np.isclose)
@@ -842,10 +844,10 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='',
max_rel_error = max(error[nonzero] / abs(y[nonzero]))
if getattr(error, 'dtype', object_) == object_:
remarks.append('Max relative difference: '
- + str(max_rel_error))
+ + str(max_rel_error))
else:
remarks.append('Max relative difference: '
- + array2string(max_rel_error))
+ + array2string(max_rel_error))
err_msg += '\n' + '\n'.join(remarks)
msg = build_err_msg([ox, oy], err_msg,
@@ -1058,13 +1060,13 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
"""
__tracebackhide__ = True # Hide traceback for py.test
- from numpy.core import number, float_, result_type, array
+ from numpy.core import number, float_, result_type
from numpy.core.numerictypes import issubdtype
from numpy.core.fromnumeric import any as npany
def compare(x, y):
try:
- if npany(gisinf(x)) or npany( gisinf(y)):
+ if npany(gisinf(x)) or npany(gisinf(y)):
xinfid = gisinf(x)
yinfid = gisinf(y)
if not (xinfid == yinfid).all():
@@ -1106,8 +1108,6 @@ def assert_array_less(x, y, err_msg='', verbose=True):
compared, no assertion is raised if both objects have NaNs in the same
positions.
-
-
Parameters
----------
x : array_like
@@ -1129,8 +1129,6 @@ def assert_array_less(x, y, err_msg='', verbose=True):
assert_array_equal: tests objects for equality
assert_array_almost_equal: test objects for equality up to precision
-
-
Examples
--------
>>> np.testing.assert_array_less([1.0, 1.0, np.nan], [1.1, 2.0, np.nan])
@@ -1307,8 +1305,10 @@ class _Dummy(unittest.TestCase):
def nop(self):
pass
+
_d = _Dummy('nop')
+
def assert_raises(*args, **kwargs):
"""
assert_raises(exception_class, callable, *args, **kwargs)
@@ -1335,7 +1335,7 @@ def assert_raises(*args, **kwargs):
"""
__tracebackhide__ = True # Hide traceback for py.test
- return _d.assertRaises(*args,**kwargs)
+ return _d.assertRaises(*args, **kwargs)
def assert_raises_regex(exception_class, expected_regexp, *args, **kwargs):
@@ -1486,7 +1486,7 @@ def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True,
Given two array_like objects, check that their shapes and all elements
are equal (but see the Notes for the special handling of a scalar). An
- exception is raised if the shapes mismatch or any values conflict. In
+ exception is raised if the shapes mismatch or any values conflict. In
contrast to the standard usage in numpy, NaNs are compared like numbers,
no assertion is raised if both objects have NaNs in the same positions.
@@ -2408,6 +2408,7 @@ def assert_no_gc_cycles(*args, **kwargs):
with _assert_no_gc_cycles_context(name=func.__name__):
func(*args, **kwargs)
+
def break_cycles():
"""
Break reference cycles by calling gc.collect
@@ -2540,7 +2541,7 @@ def _no_tracing(func):
def _get_glibc_version():
try:
ver = os.confstr('CS_GNU_LIBC_VERSION').rsplit(' ')[1]
- except Exception as inst:
+ except Exception:
ver = '0.0'
return ver