[Numpy-discussion] Warnings as exceptions?

Timothy Hochberg tim.hochberg@ieee....
Tue Nov 13 10:23:39 CST 2007


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20071113/845c749a/attachment-0001.html 


More information about the Numpy-discussion mailing list