diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-07-11 16:49:04 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-07-11 16:49:04 -0600 |
commit | 2f1174dee44e901b7d028beb86f4a8ea324bd74f (patch) | |
tree | 8f09dc2bd35e2631f5821fe2e998f6ea46e254b8 /numpy/testing | |
parent | 49a587cd786242b05fcfd22d5cda961d733b68d4 (diff) | |
download | numpy-2f1174dee44e901b7d028beb86f4a8ea324bd74f.tar.gz |
MAINT: Use np.errstate context manager.
Now that Python < 2.6 is no longer supported we can use the errstate
context manager in places where constructs like
```
old = seterr(invalid='ignore')
try:
blah
finally:
seterr(**old)
```
were used.
Diffstat (limited to 'numpy/testing')
-rw-r--r-- | numpy/testing/utils.py | 20 |
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: |