
Why are numpy warnings printed rather than issued using the standard warnings library? I know that the behaviour can be controlled by seterr(), but it seem rather unpythonic not to use the warnings library. Is there an explicit reason for this choice? (It seems like a pretty trivial modification of util.py will catch most of the cases.) If performance is an issue, one could add a 'print' mode which behaves as the current 'warn'. Michael. (P.S. I am sure this has been discussed somewhere before, but I can't seem to find a reference.)

On Nov 10, 2007 3:33 PM, Michael McNeil Forbes <mforbes@physics.ubc.ca> wrote:
Why are numpy warnings printed rather than issued using the standard warnings library? I know that the behaviour can be controlled by seterr(), but it seem rather unpythonic not to use the warnings library.
Is there an explicit reason for this choice? (It seems like a pretty trivial modification of util.py will catch most of the cases.) If performance is an issue, one could add a 'print' mode which behaves as the current 'warn'.
I believe that performance is at least part of the reason. I suspect that routing things through the Python warnings module is somewhat expensive and there are some things that one usually want to ignore (underflow for example). It's not the cases where warnings are printed that are a performance issue; it's the cases where something dodgy happens but you are intentionally ignoring it that could cause performance issues. In principle, I think that you could get away with just using seterr to turn warnings on and off and use the warnings framework to do everything else. However, the warnings framework has always been harder for me to work with than seterr, so I'm not keen on that myself. What might well make sense is to route things through the warnings module only when seterr is set to "warn" for that error type. -- . __ . |-\ . . tim.hochberg@ieee.org

Michael McNeil Forbes wrote:
Why are numpy warnings printed rather than issued using the standard warnings library? I know that the behaviour can be controlled by seterr(), but it seem rather unpythonic not to use the warnings library.
The "warn" option explicitly allows you to use the warnings library. There is already the "print" mode which is in fact the default. It is trivial to change your default to "warn" if you prefer. The standard default is "print" because it is less intrusive and does not require users to setup the warnings module which is not always done by many users. -Travis O.

Michael McNeil Forbes wrote:
Why are numpy warnings printed rather than issued using the standard warnings library? ... in util.py ... The "warn" option explicitly allows you to use the warnings library. There is already the "print" mode which is in fact the default. I see now that it works exactly like I expected. I got confused by
On 13 Nov 2007, at 8:46 AM, Travis E. Oliphant wrote: the default and then looked in util.py in the old *numarray* code by mistake... Thanks. Michael.

On Nov 13, 2007 11:48 AM, Michael McNeil Forbes <mforbes@physics.ubc.ca> wrote:
On 13 Nov 2007, at 8:46 AM, Travis E. Oliphant wrote:
Why are numpy warnings printed rather than issued using the standard warnings library? ... in util.py ... The "warn" option explicitly allows you to use the warnings library. There is already the "print" mode which is in fact the default. I see now that it works exactly like I expected. I got confused by
Michael McNeil Forbes wrote: the default and then looked in util.py in the old *numarray* code by mistake...
Ooops. I should have known that. The docstring for seterr should be adjusted since it does not list "print" as an option. I'll try to do it if no one gets to it first.
Thanks. Michael.
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
-- . __ . |-\ . . tim.hochberg@ieee.org
participants (3)
-
Michael McNeil Forbes
-
Timothy Hochberg
-
Travis E. Oliphant