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/core/arrayprint.py | |
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/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index a0f2cfa63..ad6a5d074 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -546,8 +546,8 @@ class FloatFormat(object): def fillFormat(self, data): from . import numeric as _nc - errstate = _nc.seterr(all='ignore') - try: + + with _nc.errstate(all='ignore'): special = isnan(data) | isinf(data) valid = not_equal(data, 0) & ~special non_zero = absolute(data.compress(valid)) @@ -562,8 +562,6 @@ class FloatFormat(object): if not self.suppress_small and (min_val < 0.0001 or max_val/min_val > 1000.): self.exp_format = True - finally: - _nc.seterr(**errstate) if self.exp_format: self.large_exponent = 0 < min_val < 1e-99 or max_val >= 1e100 @@ -599,8 +597,8 @@ class FloatFormat(object): def __call__(self, x, strip_zeros=True): from . import numeric as _nc - err = _nc.seterr(invalid='ignore') - try: + + with _nc.errstate(invalid='ignore'): if isnan(x): if self.sign: return self.special_fmt % ('+' + _nan_str,) @@ -614,8 +612,6 @@ class FloatFormat(object): return self.special_fmt % (_inf_str,) else: return self.special_fmt % ('-' + _inf_str,) - finally: - _nc.seterr(**err) s = self.format % x if self.large_exponent: |