I'm struggling to understand how to use the message argument in
The command
I don't understand why the message filter doesn't work. What should I put to filter that specific warning?
Note: I am not explicitly using that
warnings.filterwarnings
. I am specifically trying to silent a deprecation warning from matplotlib
. Here is what I have:import warnings from matplotlib import pyplot fig, ax = pyplot.subplots(1, 1)The following command gives a warning:
t = ax.is_first_col()
Error:<stdin>:1: MatplotlibDeprecationWarning:
The is_first_col function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use ax.get_subplotspec().is_first_col() instead.
I have been trying to filter by type (DeprecationWarning), or module (matplotlib, matplotlib/..*, matplotlib*) which didn't work# make sure all the warnings show at every instance: warnings.filterwarnings('always') warnings.filterwarnings('ignore', category=DeprecationWarning) t = ax.is_first_col()
Error:<stdin>:1: MatplotlibDeprecationWarning:
The is_first_col function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use ax.get_subplotspec().is_first_col() instead.
warnings.filterwarnings('ignore', module='matplotlib') t = ax.is_first_col()
Error:<stdin>:1: MatplotlibDeprecationWarning:
The is_first_col function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use ax.get_subplotspec().is_first_col() instead.
warnings.filterwarnings('ignore', module='matplotlib*') t = ax.is_first_col()
Error:<stdin>:1: MatplotlibDeprecationWarning:
The is_first_col function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use ax.get_subplotspec().is_first_col() instead.
warnings.filterwarnings('ignore', module='matplotlib/..*') t = ax.is_first_col()
Error:<stdin>:1: MatplotlibDeprecationWarning:
The is_first_col function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use ax.get_subplotspec().is_first_col() instead.
Then I have been trying to filter the messages:warnings.filterwarnings('ignore', message='.*MatplotlibDeprecationWarning.*') t = ax.is_first_col()
Error:<stdin>:1: MatplotlibDeprecationWarning:
The is_first_col function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use ax.get_subplotspec().is_first_col() instead.
warnings.filterwarnings('always') warnings.filterwarnings('ignore', message='.*MatplotlibDeprecationWarning.*') warnings.warn('some text MatplotlibDeprecationWarning some other text\n another line')The latter command doesn't result in any warning at all, so the message is indeed filtered according to the regexp, but not the one from
matplotlib
. The command
warnings.filterwarnings('filter')
works but it filters everything which is not desirable.I don't understand why the message filter doesn't work. What should I put to filter that specific warning?
Note: I am not explicitly using that
is_first_col
function, this comes from another module that I am using.