[SciPy-User] catching warnings without error/raise

josef.pktd@gmai... josef.pktd@gmai...
Thu Sep 22 11:16:45 CDT 2011


A python question, but hopefully someone can answer

I would like wrap functions that sometimes issue warnings, I want to
suppress the warning but I want to record whether a warning has been
issued, for later display.

python 2.6 has "with warnings.catch_warnings(record=True) as w:" that
seems to do what I want (from reading the description).

Is there a different way how to do this that also works for python 2.5

examples:

>>> from scipy import stats
>>> stats.kurtosistest(np.arange(5))
(-0.57245889052982701, 0.56701112882584059)
C:\Python26\lib\site-packages\scipy\stats\stats.py:1198: UserWarning:
kurtosistest only valid for n>=20 ... continuing anyway, n=5
  int(n))

>>> stats.ansari(np.arange(5), np.arange(5)**2)
(18.5, 0.12260027475751481)
C:\Python26\lib\site-packages\scipy\stats\morestats.py:731:
UserWarning: Ties preclude use of exact statistic.
  warnings.warn("Ties preclude use of exact statistic.")

Thanks,
Josef


More information about the SciPy-User mailing list