Skip to content

Commit 9eb8203

Browse files
authored
fix: Silence Bokeh FIXED_SIZING_MODE warning on hv.save (#6674)
1 parent 2dfe271 commit 9eb8203

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

holoviews/plotting/bokeh/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from bokeh.core.json_encoder import serialize_json # noqa (API import)
1212
from bokeh.core.property.datetime import Datetime
1313
from bokeh.core.validation import silence
14+
from bokeh.core.validation.check import is_silenced
1415
from bokeh.layouts import Column, Row, group_tools
1516
from bokeh.models import (
1617
CategoricalAxis,
@@ -546,12 +547,15 @@ def silence_warnings(*warnings):
546547
"""Context manager for silencing bokeh validation warnings.
547548
548549
"""
550+
silenced = set()
549551
for warning in warnings:
550-
silence(warning)
552+
if not is_silenced(warning):
553+
silenced.add(warning)
554+
silence(warning)
551555
try:
552556
yield
553557
finally:
554-
for warning in warnings:
558+
for warning in silenced:
555559
silence(warning, False)
556560

557561

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import logging
2+
3+
import pytest
4+
5+
import holoviews as hv
6+
7+
8+
@pytest.mark.usefixtures("bokeh_backend")
9+
@pytest.mark.parametrize(
10+
"opts",
11+
[
12+
{"frame_width": 200},
13+
{"frame_height": 200},
14+
{"frame_height": 200, "frame_width": 200},
15+
{},
16+
],
17+
)
18+
def test_save_suppresses_bokeh_fixed_sizing_mode(tmp_path, caplog, opts):
19+
curve = hv.Curve([1, 2, 3]).opts(**opts, backend="bokeh")
20+
21+
out = tmp_path / "curve.html"
22+
logging.getLogger("bokeh").propagate = True
23+
with caplog.at_level(logging.WARNING):
24+
hv.save(curve, out)
25+
26+
assert out.exists()
27+
assert all(["FIXED_SIZING_MODE" not in e.msg for e in caplog.records])

holoviews/util/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,16 @@ def save(obj, filename, fmt='auto', backend=None, resources='cdn', toolbar=None,
841841
fmt = formats[-1]
842842
if formats[-1] in supported:
843843
filename = '.'.join(formats[:-1])
844-
return renderer_obj.save(obj, filename, fmt=fmt, resources=resources,
845-
title=title)
844+
if backend == "bokeh":
845+
# Suppress only the specific validator that warns when `sizing_mode='fixed'`
846+
# but width/height are not both set on a Bokeh Plot, this happens in HoloViews
847+
# when `.opts(fixed_{width,height}=...)` are set, which sets width/height to `None`.
848+
from bokeh.core.validation.warnings import FIXED_SIZING_MODE
849+
850+
from ..plotting.bokeh.util import silence_warnings
851+
with silence_warnings(FIXED_SIZING_MODE):
852+
return renderer_obj.save(obj, filename, fmt=fmt, resources=resources, title=title)
853+
return renderer_obj.save(obj, filename, fmt=fmt, resources=resources, title=title)
846854

847855

848856
def render(obj, backend=None, **kwargs):

0 commit comments

Comments
 (0)