diff options
author | Pauli Virtanen <pav@iki.fi> | 2009-12-10 19:12:41 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2009-12-10 19:12:41 +0000 |
commit | 794a6c4511ced84c74bc8f2dd8cd8f277925a6ac (patch) | |
tree | 406d57b79c829f4ec2f3f7dfc5d28c5b7fa6daca /numpy/core/numeric.py | |
parent | 8d24b14a7eed3fba60bab462e873214cc9fa2a1f (diff) | |
download | numpy-794a6c4511ced84c74bc8f2dd8cd8f277925a6ac.tar.gz |
ENH: emit ComplexWarning when casting complex to real (addresses #1319)
Casting complex numbers to real discards the imaginary part, which may
be unexpected. For safety, emit a warning when this occurs.
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index e35fca07b..8c4fa2980 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -19,7 +19,8 @@ __all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc', 'seterrcall', 'geterrcall', 'errstate', 'flatnonzero', 'Inf', 'inf', 'infty', 'Infinity', 'nan', 'NaN', 'False_', 'True_', 'bitwise_not', - 'CLIP', 'RAISE', 'WRAP', 'MAXDIMS', 'BUFSIZE', 'ALLOW_THREADS'] + 'CLIP', 'RAISE', 'WRAP', 'MAXDIMS', 'BUFSIZE', 'ALLOW_THREADS', + 'ComplexWarning'] import sys import warnings @@ -32,6 +33,16 @@ from numerictypes import * if sys.version_info[0] < 3: __all__.extend(['getbuffer', 'newbuffer']) +class ComplexWarning(RuntimeWarning): + """ + Warning that is raised when casting complex numbers to real. + + Casting a complex number to real discards its imaginary part, and + this behavior may not be what is intended in all cases. + + """ + pass + bitwise_not = invert CLIP = multiarray.CLIP |