Trying to turn warning to errors
![](https://secure.gravatar.com/avatar/468dc4066b83362fbb6584115f3112b3.jpg?s=120&d=mm&r=g)
Dear all, I am trying to turn Python warnings to errors, but it does not work as expected with numpy. The following two piece of code work: $ python -W error -c 'import warnings; import numpy; warnings.warn("test", numpy.core.numeric.ComplexWarning)' Traceback (most recent call last): File "<string>", line 1, in <module> numpy.core.numeric.ComplexWarning: test $ python -W error -c 'import warnings; import numpy; raise numpy.core.numeric.ComplexWarning' Traceback (most recent call last): File "<string>", line 1, in <module> numpy.core.numeric.ComplexWarning while this does not (i.e. still produces just a warning): $ python -W error -c 'import numpy; x=numpy.ones(2); x+=1j' numpy.core.numeric.ComplexWarning: Casting complex values to real discards the imaginary part This is with Python 2.6.6 and numpy 1.5.1, but also confirmed with Python 2.7. Thanks for any suggested solutions, Ondrej Marsalek
![](https://secure.gravatar.com/avatar/da3a0a1942fbdc5ee9a9b8115ac5dae7.jpg?s=120&d=mm&r=g)
Fri, 13 May 2011 17:39:26 +0200, Ondrej Marsalek wrote: [clip]
while this does not (i.e. still produces just a warning):
$ python -W error -c 'import numpy; x=numpy.ones(2); x+=1j' numpy.core.numeric.ComplexWarning: Casting complex values to real discards the imaginary part
This is with Python 2.6.6 and numpy 1.5.1, but also confirmed with Python 2.7.
Hmm, I suspect that there is some code in the type casting path that swallows exceptions... Seems to also occur on 1.6.0rc3 Can you file a bug ticket on this on the Numpy Trac, so it won't get lost?
![](https://secure.gravatar.com/avatar/468dc4066b83362fbb6584115f3112b3.jpg?s=120&d=mm&r=g)
On Fri, May 13, 2011 at 18:54, Pauli Virtanen <pav@iki.fi> wrote:
Fri, 13 May 2011 17:39:26 +0200, Ondrej Marsalek wrote: [clip]
while this does not (i.e. still produces just a warning):
$ python -W error -c 'import numpy; x=numpy.ones(2); x+=1j' numpy.core.numeric.ComplexWarning: Casting complex values to real discards the imaginary part
This is with Python 2.6.6 and numpy 1.5.1, but also confirmed with Python 2.7.
Hmm, I suspect that there is some code in the type casting path that swallows exceptions... Seems to also occur on 1.6.0rc3
Can you file a bug ticket on this on the Numpy Trac, so it won't get lost?
If someone with an account could do this, that would be great. Thanks, Ondrej
![](https://secure.gravatar.com/avatar/468dc4066b83362fbb6584115f3112b3.jpg?s=120&d=mm&r=g)
On Fri, May 13, 2011 at 21:15, Ondrej Marsalek <ondrej.marsalek@gmail.com> wrote:
On Fri, May 13, 2011 at 18:54, Pauli Virtanen <pav@iki.fi> wrote:
Fri, 13 May 2011 17:39:26 +0200, Ondrej Marsalek wrote: [clip]
while this does not (i.e. still produces just a warning):
$ python -W error -c 'import numpy; x=numpy.ones(2); x+=1j' numpy.core.numeric.ComplexWarning: Casting complex values to real discards the imaginary part
This is with Python 2.6.6 and numpy 1.5.1, but also confirmed with Python 2.7.
Hmm, I suspect that there is some code in the type casting path that swallows exceptions... Seems to also occur on 1.6.0rc3
Can you file a bug ticket on this on the Numpy Trac, so it won't get lost?
If someone with an account could do this, that would be great.
OK, I made an account and created the ticket. Ondrej
participants (2)
-
Ondrej Marsalek
-
Pauli Virtanen