summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-07-11 17:16:42 -0700
committerCharles Harris <charlesr.harris@gmail.com>2013-07-11 17:16:42 -0700
commita053a4372aba0af0bd63ffd5e207baf469cfc7bf (patch)
treeafcdad0da5b29ce832528474246dcb66bc1491cf /numpy/testing/utils.py
parente1c4806b649933383fb610205fb612c438360472 (diff)
parent2f1174dee44e901b7d028beb86f4a8ea324bd74f (diff)
downloadnumpy-a053a4372aba0af0bd63ffd5e207baf469cfc7bf.tar.gz
Merge pull request #3518 from charris/use-errstate-context-manager
MAINT: Use np.errstate context manager.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py20
1 files changed, 5 insertions, 15 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index f58997d58..ca564721a 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -71,14 +71,11 @@ def gisfinite(x):
exception is always raised.
This should be removed once this problem is solved at the Ufunc level."""
- from numpy.core import isfinite, seterr
- err = seterr(invalid='ignore')
- try:
+ 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")
- finally:
- seterr(**err)
return st
def gisinf(x):
@@ -92,14 +89,11 @@ def gisinf(x):
exception is always raised.
This should be removed once this problem is solved at the Ufunc level."""
- from numpy.core import isinf, seterr
- err = seterr(invalid='ignore')
- try:
+ 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")
- finally:
- seterr(**err)
return st
def rand(*args):
@@ -539,13 +533,9 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True):
return
# Normalized the numbers to be in range (-10.0,10.0)
# scale = float(pow(10,math.floor(math.log10(0.5*(abs(desired)+abs(actual))))))
- err = np.seterr(invalid='ignore')
- try:
+ with np.errstate(invalid='ignore'):
scale = 0.5*(np.abs(desired) + np.abs(actual))
scale = np.power(10,np.floor(np.log10(scale)))
- finally:
- np.seterr(**err)
-
try:
sc_desired = desired/scale
except ZeroDivisionError: