Suppressing warning from obspy.signal

If I import any module in obspy.signal, I get a numpy warning about oldnumeric:

/Users/mhearne/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/oldnumeric/__init__.py:11:
ModuleDeprecationWarning: The oldnumeric module will be dropped in
Numpy 1.9
  warnings.warn(_msg, ModuleDeprecationWarning)

I looked around for tips on how to suppress warnings, but none of the
suggestions I found seem to work. At the end of the email is what I
thought would work.

I have two questions:
1) What is causing this warning?
2) How can I suppress this warning?

My system information:
OS: Mac 10.7.5
Python version: 2.7.6 (from Enthought)
Numpy version: 1.8.1
Obspy version: 0.9.0

#!/usr/bin/env python

import warnings
warnings.filterwarnings("ignore")
import obspy.signal

if __name__ == '__main__':
    pass

You can just ignore this warning (unless you explicitely use the oldnumeric, obviously).

Simplest is to open the numpy file as indicated (/Users/mhearne/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/oldnumeric/__init__.py) and delete line 11 which raises the warning.

best,
Tobias

Tobias - Thank you for your response. However, I am writing this code
for others to use, and it is disconcerting for non-Python developers
to see warnings pop up, and then annoying when they feel compelled to
report it back to me.

For this same reason, it is impractical to delete the offending line
in the oldnumeric init script, as I cannot expect my users to do that,
nor am I able to do it for all of them.

I am confused about what is making this warning pop up, because I
could find no explicit calls to oldnumeric in the obspy code, although
I did find imports of modules that *do* make explicit calls to
oldnumeric (fft, linear_algebra, etc.)

Also, if I import obspy.signal.filter, I get the error, but if I
import all of the packages that filter imports, I do NOT get the
warning. Also, if I import numpy.oldnumeric directly, I do not get
the warning.

I'll post my question on the numpy mailing list and see if anyone
there has any tips.

Thanks,

Mike

Hey Mike,

I’ve also wondered about that behaviour but warnings are a little bit tricky due to a per-module warnings registry so each warnings is only printed once. To see it each time it is triggered, do the following:

import warnings
warnings.simplefilter(“always”)

If you want to distribute production code the best option is to simply disable deprecation warnings so your users are not bothered.

import warnings
warnings.simplefilter(“ignore”, DeprecationWarning)

Please let us know if you find the actual cause but my bet is that some module imports a module that imports oldnumeric so there is nothing we can really do.

All the best,

Lion

This should take care of your problem

Hi Mike,

Have you tried the captureWarnings function of the logging module?

https://docs.python.org/2/library/logging.html#integration-with-the-warnings-module

That’s what I would do, I don’t like ignoring warnings, but looks like this one is harmless if you’re not using oldnumeric. This way you could just discard the ‘py.warnings’ log by default by ignoring it, or adding a NullHandler, which would also give users (and yourself) the option of initializing the logger and sending it somewhere for debugging in their own scripts. It’s the “recommended” way to log APIs for end users.

https://docs.python.org/2/howto/logging.html#library-config

Mark Williams
Nevada Seismological Laboratory
Nevada Seismic Network
University of Nevada, Reno
tel: (775)-784-4317

Lion - Actually, doing

import warnings
warnings.simplefilter("ignore", DeprecationWarning)

does NOT work, and I would love to know why. What DOES work is adding
the filterwarnings in the modules in obspy.signal that import the
numpy.fft module. I forked the releases branch of obspy in an effort
to fix that, but I can't get the tests to run because of this error:

ImportError: No module named future.builtins

There is however a module called "future_builtins" - is this a typo in
one of the tests?

--Mike

Hi!

[...] numpy.fft module. I forked the releases branch of obspy in an effort
to fix that, but I can't get the tests to run because of this error:

ImportError: No module named future.builtins

There is however a module called "future_builtins" - is this a typo in
one of the tests?

You are probably missing the future package, which contains future.builtins. To install it using pip:

$ pip install future

Are you sure you are working in the releases branch though? I think the future module only became an ObsPy dependency in the master, especially as I couldn't find any import of future.builtins in the releases branch.

Best,
Bernhard

Hi Mike,

oh I see. Sorry I did not pay enough attention earlier. That is indeed strange.

A trick that works on my system:
import warnings
warnings.simplefilter("ignore", DeprecationWarning)
import numpy.oldnumeric
import obspy.signal
This is of course not a proper solution so I opened a ticket to track the issue here:
https://github.com/obspy/obspy/issues/776

Lets move the discussion to the issue tracker.

Cheers!

Lion