How to suppress warnings?

import holoviews as hv
hv.extension('matplotlib')
hv.Curve([0, 1, 2]).opts(tools=['hover'])

yields

WARNING:param.main: Option 'tools' for Curve type not valid for selected backend ('matplotlib'). Option only applies to following backends: ['bokeh']

Is it possible to suppress these warnings?

This doesn’t seem to work:

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    hv.Curve([0, 1, 2]).opts(tools=['hover'])
import logging

logging.getLogger("param.main").setLevel(logging.CRITICAL)

hides it

Sure, you can hide those warnings using the logging module, but if what you are doing is switching between backends for the same code and you want certain options to go only to certain backends, I’d recommend not hiding the warnings, and instead explicitly declaring which backend the options should be used for:

import holoviews as hv
hv.extension('matplotlib')
hv.Curve([0, 1, 2]).opts(tools=['hover'], backend='bokeh')

This way you can provide options separately for each backend (in separate .opts() calls) and know that the option will be validated against the declared backend (only). That way you’ll detect if you’re using an unsupported option, and moreover you can select just the options you want for that backend, knowing that they won’t mistakenly be applied to another backend where they might be accepted but might not achieve what you want them to.

Thanks for the reply. However, even though I have that implemented, in my case, it still shows the warning thus I needed the logging. I suspect am using parallel processing to output several plots simultaneously so it’s bugging out.

If there’s a bug, please report it, but I’d guess that there’s just at least one place where you haven’t declared the backend for a bokeh-specific option.

2 Likes