diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-07-11 17:16:42 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-07-11 17:16:42 -0700 |
commit | a053a4372aba0af0bd63ffd5e207baf469cfc7bf (patch) | |
tree | afcdad0da5b29ce832528474246dcb66bc1491cf /numpy/core/arrayprint.py | |
parent | e1c4806b649933383fb610205fb612c438360472 (diff) | |
parent | 2f1174dee44e901b7d028beb86f4a8ea324bd74f (diff) | |
download | numpy-a053a4372aba0af0bd63ffd5e207baf469cfc7bf.tar.gz |
Merge pull request #3518 from charris/use-errstate-context-manager
MAINT: Use np.errstate context manager.
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: |