summaryrefslogtreecommitdiff
path: root/numpy/testing
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2023-05-03 13:06:13 +0200
committerSebastian Berg <sebastianb@nvidia.com>2023-05-03 13:11:01 +0200
commit57f5cf0501dac874dc2863e598272d7bf61f296e (patch)
tree96eb7e2dfde036665371450b3ec8174ae0581287 /numpy/testing
parentc37a577c9df74e29c97a7bb010de0b37f83870bb (diff)
downloadnumpy-57f5cf0501dac874dc2863e598272d7bf61f296e.tar.gz
MAINT: Remove gisnan, gisinf, and gisfinite from testing code
These were introduced many years ago when ufuncs were buggy and could return NotImplemented sometimes. This has been fixed for many years, though. I suspect the errstate for `isfinite` is not required so removed it. It was a 12+ year old work-around for warnings that really shouldn't happen to begin with. (The commit mentions `np.isinf(np.inf)` giving a warning, which doesn't make sense, I think.)
Diffstat (limited to 'numpy/testing')
-rw-r--r--numpy/testing/_private/utils.py81
1 files changed, 13 insertions, 68 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index f2fd9d2ae..8ef886cac 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -21,6 +21,7 @@ import sysconfig
import numpy as np
from numpy.core import (
intp, float32, empty, arange, array_repr, ndarray, isnat, array)
+from numpy import isfinite, isnan, isinf
import numpy.linalg.lapack_lite
from io import StringIO
@@ -91,62 +92,6 @@ def assert_(val, msg=''):
raise AssertionError(smsg)
-def gisnan(x):
- """like isnan, but always raise an error if type not supported instead of
- returning a TypeError object.
-
- Notes
- -----
- isnan and other ufunc sometimes return a NotImplementedType object instead
- of raising any exception. This function is a wrapper to make sure an
- exception is always raised.
-
- This should be removed once this problem is solved at the Ufunc level."""
- from numpy.core import isnan
- st = isnan(x)
- if isinstance(st, type(NotImplemented)):
- raise TypeError("isnan not supported for this type")
- return st
-
-
-def gisfinite(x):
- """like isfinite, but always raise an error if type not supported instead
- of returning a TypeError object.
-
- Notes
- -----
- isfinite and other ufunc sometimes return a NotImplementedType object
- instead of raising any exception. This function is a wrapper to make sure
- an exception is always raised.
-
- This should be removed once this problem is solved at the Ufunc level."""
- from numpy.core import isfinite, errstate
- with errstate(invalid='ignore'):
- st = isfinite(x)
- if isinstance(st, type(NotImplemented)):
- raise TypeError("isfinite not supported for this type")
- return st
-
-
-def gisinf(x):
- """like isinf, but always raise an error if type not supported instead of
- returning a TypeError object.
-
- Notes
- -----
- isinf and other ufunc sometimes return a NotImplementedType object instead
- of raising any exception. This function is a wrapper to make sure an
- exception is always raised.
-
- This should be removed once this problem is solved at the Ufunc level."""
- from numpy.core import isinf, errstate
- with errstate(invalid='ignore'):
- st = isinf(x)
- if isinstance(st, type(NotImplemented)):
- raise TypeError("isinf not supported for this type")
- return st
-
-
if os.name == 'nt':
# Code "stolen" from enthought/debug/memusage.py
def GetPerformanceAttributes(object, counter, instance=None,
@@ -390,8 +335,8 @@ def assert_equal(actual, desired, err_msg='', verbose=True):
# Inf/nan/negative zero handling
try:
- isdesnan = gisnan(desired)
- isactnan = gisnan(actual)
+ isdesnan = isnan(desired)
+ isactnan = isnan(actual)
if isdesnan and isactnan:
return # both nan, so equal
@@ -401,7 +346,7 @@ def assert_equal(actual, desired, err_msg='', verbose=True):
if (array_actual.dtype.char in 'Mm' or
array_desired.dtype.char in 'Mm'):
# version 1.18
- # until this version, gisnan failed for datetime64 and timedelta64.
+ # until this version, isnan failed for datetime64 and timedelta64.
# Now it succeeds but comparison to scalar with a different type
# emits a DeprecationWarning.
# Avoid that by skipping the next check
@@ -582,9 +527,9 @@ def assert_almost_equal(actual, desired, decimal=7, err_msg='', verbose=True):
# If one of desired/actual is not finite, handle it specially here:
# check that both are nan if any is a nan, and test for equality
# otherwise
- if not (gisfinite(desired) and gisfinite(actual)):
- if gisnan(desired) or gisnan(actual):
- if not (gisnan(desired) and gisnan(actual)):
+ if not (isfinite(desired) and isfinite(actual)):
+ if isnan(desired) or isnan(actual):
+ if not (isnan(desired) and isnan(actual)):
raise AssertionError(_build_err_msg())
else:
if not desired == actual:
@@ -683,9 +628,9 @@ def assert_approx_equal(actual, desired, significant=7, err_msg='',
# If one of desired/actual is not finite, handle it specially here:
# check that both are nan if any is a nan, and test for equality
# otherwise
- if not (gisfinite(desired) and gisfinite(actual)):
- if gisnan(desired) or gisnan(actual):
- if not (gisnan(desired) and gisnan(actual)):
+ if not (isfinite(desired) and isfinite(actual)):
+ if isnan(desired) or isnan(actual):
+ if not (isnan(desired) and isnan(actual)):
raise AssertionError(msg)
else:
if not desired == actual:
@@ -1066,9 +1011,9 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
def compare(x, y):
try:
- if npany(gisinf(x)) or npany(gisinf(y)):
- xinfid = gisinf(x)
- yinfid = gisinf(y)
+ if npany(isinf(x)) or npany(isinf(y)):
+ xinfid = isinf(x)
+ yinfid = isinf(y)
if not (xinfid == yinfid).all():
return False
# if one item, x and y is +- inf