summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Kern <robert.kern@gmail.com>2011-03-30 17:48:43 -0500
committerCharles Harris <charlesr.harris@gmail.com>2011-04-01 19:49:46 -0600
commitdc22394efedc3dafff45dd857b96398f2f56f625 (patch)
tree2187689c63ab725a5be8aa2214aa2f62ea212185
parentef46a0910a9233b485a3b1313d2eedc217d3981b (diff)
downloadnumpy-dc22394efedc3dafff45dd857b96398f2f56f625.tar.gz
ENH: Change the default error handling to warn instead of print, except for underflow, which remains ignored.
-rw-r--r--numpy/core/include/numpy/ufuncobject.h6
-rw-r--r--numpy/core/numeric.py6
-rw-r--r--numpy/doc/misc.py40
3 files changed, 28 insertions, 24 deletions
diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h
index b6f534425..34cd72707 100644
--- a/numpy/core/include/numpy/ufuncobject.h
+++ b/numpy/core/include/numpy/ufuncobject.h
@@ -110,9 +110,9 @@ typedef struct {
/* Default user error mode */
#define UFUNC_ERR_DEFAULT2 \
- (UFUNC_ERR_PRINT << UFUNC_SHIFT_DIVIDEBYZERO) + \
- (UFUNC_ERR_PRINT << UFUNC_SHIFT_OVERFLOW) + \
- (UFUNC_ERR_PRINT << UFUNC_SHIFT_INVALID)
+ (UFUNC_ERR_WARN << UFUNC_SHIFT_DIVIDEBYZERO) + \
+ (UFUNC_ERR_WARN << UFUNC_SHIFT_OVERFLOW) + \
+ (UFUNC_ERR_WARN << UFUNC_SHIFT_INVALID)
#if NPY_ALLOW_THREADS
#define NPY_LOOP_BEGIN_THREADS do {if (!(loop->obj & UFUNC_OBJ_NEEDS_API)) _save = PyEval_SaveThread();} while (0)
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 74b8ba8a4..e36f196c1 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -2141,8 +2141,8 @@ def geterr():
Examples
--------
- >>> np.geterr() # default is all set to 'ignore'
- {'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore',
+ >>> np.geterr()
+ {'over': 'warn', 'divide': 'warn', 'invalid': 'warn',
'under': 'ignore'}
>>> np.arange(3.) / np.arange(3.)
array([ NaN, 1., 1.])
@@ -2390,7 +2390,7 @@ class errstate(object):
Outside the context the error handling behavior has not changed:
>>> np.geterr()
- {'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore',
+ {'over': 'warn', 'divide': 'warn', 'invalid': 'warn',
'under': 'ignore'}
"""
diff --git a/numpy/doc/misc.py b/numpy/doc/misc.py
index 81d7a54af..8fa3f8a31 100644
--- a/numpy/doc/misc.py
+++ b/numpy/doc/misc.py
@@ -46,24 +46,28 @@ from the results: ::
>>> np.nansum(x)
42.0
-How numpy handles numerical exceptions
-
-Default is to "warn"
-But this can be changed, and it can be set individually for different kinds
-of exceptions. The different behaviors are: ::
-
- 'ignore' : ignore completely
- 'warn' : print a warning (once only)
- 'raise' : raise an exception
- 'call' : call a user-supplied function (set using seterrcall())
-
-These behaviors can be set for all kinds of errors or specific ones: ::
-
- all: apply to all numeric exceptions
- invalid: when NaNs are generated
- divide: divide by zero (for integers as well!)
- overflow: floating point overflows
- underflow: floating point underflows
+How numpy handles numerical exceptions:
+------------------------------------------
+
+The default is to ``'warn'`` for ``invalid``, ``divide``, and ``overflow``
+and ``'ignore'`` for ``underflow``. But this can be changed, and it can be
+set individually for different kinds of exceptions. The different behaviors
+are:
+
+ - 'ignore' : Take no action when the exception occurs.
+ - 'warn' : Print a `RuntimeWarning` (via the Python `warnings` module).
+ - 'raise' : Raise a `FloatingPointError`.
+ - 'call' : Call a function specified using the `seterrcall` function.
+ - 'print' : Print a warning directly to ``stdout``.
+ - 'log' : Record error in a Log object specified by `seterrcall`.
+
+These behaviors can be set for all kinds of errors or specific ones:
+
+ - all : apply to all numeric exceptions
+ - invalid : when NaNs are generated
+ - divide : divide by zero (for integers as well!)
+ - overflow : floating point overflows
+ - underflow : floating point underflows
Note that integer divide-by-zero is handled by the same machinery.
These behaviors are set on a per-thread basis.