[SciPy-user] "catching warnings"

A. M. Archibald peridot.faceted at gmail.com
Wed Sep 20 23:10:12 CDT 2006


On 19/09/06, Robert Kern <robert.kern at gmail.com> wrote:
> A. M. Archibald wrote:
> > It would be nice if scipy provided some consistent way to signal
> > non-errors to the surrounding program. Would it work for all modules
> > to use warnings?
>
> Yes. Patches are welcome.

Here's a simple initial patch, fixing only scipy.interpolate.fitpack,
just to see what people think of this approach.

On a first pass through the code, I'm just changing print str to
warn(ScipyWarning(str)); by default, this just prints a warning on
stderr, including line number information. Users can, using the
package "warnings", control what is done with them - treat them as
exceptions, add them to a big list, feed them to a logfile, put them
in a text box...

The reason for using the class ScipyWarning is so that users can trap
specifically Scipy warnings. There is also a subclass, LossOfAccuracy,
not currently used (and it should be named LossOfPrecision, I now
realize), intended to indicate when a warning is signaling numerical
difficulties. I decided against a scipy-specific wrapper function for
warn() because I want to encourage people to pick the correct subclass
of ScipyWarning (although perhaps defaulting to ScipyWarning instead
of UserWarning might be a good idea).

I have also included Robert Kern's Redirector; it is not used yet but
(if he gives permission) I thought of including it for use in testing
and for collecting output from talkative FORTRAN and C.

A. M. Archibald
-------------- next part --------------
A non-text attachment was scrubbed...
Name: initial-warningization
Type: application/octet-stream
Size: 5751 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/scipy-user/attachments/20060921/f9ec79b4/attachment.obj 


More information about the SciPy-user mailing list