Skip to content

Commit

Permalink
Suppress bokeh warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 15, 2019
1 parent 88c4af9 commit a891a0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions holoviews/plotting/bokeh/renderer.py
Expand Up @@ -12,6 +12,7 @@
from param.parameterized import bothmethod
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.core.validation.warnings import EMPTY_LAYOUT, MISSING_RENDERERS
from bokeh.document import Document
from bokeh.embed.notebook import encode_utf8, notebook_content
from bokeh.io import curdoc, show as bkshow
Expand All @@ -26,7 +27,7 @@
from ..plot import Plot, GenericElementPlot
from ..renderer import Renderer, MIME_TYPES, HTML_TAGS
from .widgets import BokehScrubberWidget, BokehSelectionWidget, BokehServerWidgets
from .util import attach_periodic, compute_plot_size, bokeh_version
from .util import attach_periodic, compute_plot_size, bokeh_version, silence_warnings

NOTEBOOK_DIV = """
{plot_div}
Expand Down Expand Up @@ -286,7 +287,8 @@ def _figure_data(self, plot, fmt='html', doc=None, as_script=False, **kwargs):
js = ''
else:
try:
js, div, _ = notebook_content(model)
with silence_warnings(EMPTY_LAYOUT, MISSING_RENDERERS):
js, div, _ = notebook_content(model)
html = NOTEBOOK_DIV.format(plot_script=js, plot_div=div)
data = encode_utf8(html)
doc.hold()
Expand Down
15 changes: 15 additions & 0 deletions holoviews/plotting/bokeh/util.py
Expand Up @@ -15,6 +15,7 @@

from bokeh.core.json_encoder import serialize_json # noqa (API import)
from bokeh.core.properties import value
from bokeh.core.validation import silence
from bokeh.layouts import WidgetBox, Row, Column
from bokeh.models import tools
from bokeh.models import Model, ToolbarBox, FactorRange, Range1d, Plot, Spacer, CustomJS, GridBox
Expand Down Expand Up @@ -333,6 +334,20 @@ def compute_layout_properties(
'plot_width' : width})


@contextmanager
def silence_warnings(*warnings):
"""
Context manager for silencing bokeh validation warnings.
"""
for warning in warnings:
silence(warning)
try:
yield
finally:
for warning in warnings:
silence(warning, False)


def empty_plot(width, height):
"""
Creates an empty and invisible plot of the specified size.
Expand Down

0 comments on commit a891a0f

Please sign in to comment.