summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-10-11 23:52:53 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-10-11 23:52:53 +0000
commitcf3eb93b05da716e16b87c30d7b5e08c22115330 (patch)
tree172f58d6f5c1cc756779e6e77d4f97fc25591e75 /numpy/core/numeric.py
parent1031df26af6d9b209458fb229a987247bf2d5497 (diff)
downloadnumpy-cf3eb93b05da716e16b87c30d7b5e08c22115330.tar.gz
Add errstate object to be created in new 'with' statement
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 66a6e3a04..8a5797e8b 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -16,7 +16,7 @@ __all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc',
'load', 'loads', 'isscalar', 'binary_repr', 'base_repr',
'ones', 'identity', 'allclose', 'compare_chararrays', 'putmask',
'seterr', 'geterr', 'setbufsize', 'getbufsize',
- 'seterrcall', 'geterrcall', 'flatnonzero',
+ 'seterrcall', 'geterrcall', 'errstate', 'flatnonzero',
'Inf', 'inf', 'infty', 'Infinity',
'nan', 'NaN', 'False_', 'True_', 'bitwise_not',
'CLIP', 'RAISE', 'WRAP', 'MAXDIMS', 'BUFSIZE', 'ALLOW_THREADS']
@@ -716,6 +716,14 @@ def geterrcall():
"""
return umath.geterrobj()[2]
+class errstate(object):
+ def __init__(self, **kwargs):
+ self.kwargs = kwargs
+ def __enter__(self):
+ self.oldstate = seterr(**self.kwargs)
+ def __exit__(self, *exc_info):
+ numpy.seterr(**self.oldstate)
+
def _setdef():
defval = [UFUNC_BUFSIZE_DEFAULT, ERR_DEFAULT, None]
umath.seterrobj(defval)