Skip to content

Commit

Permalink
fix: Don't error when embed_options are None (#3376)
Browse files Browse the repository at this point in the history
* Fix error when embed_options are None

* Add changelog entry
  • Loading branch information
jonmmease committed Mar 22, 2024
1 parent 71eea06 commit b1b9dba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion altair/utils/mimebundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def preprocess_embed_options(embed_options: dict) -> dict:
embed_opts : dict
The preprocessed embed options dictionary.
"""
embed_options = embed_options.copy()
embed_options = (embed_options or {}).copy()

# Convert locale strings to objects compatible with Vega Embed using vl-convert
format_locale = embed_options.get("formatLocale", None)
Expand Down
1 change: 1 addition & 0 deletions doc/releases/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Enhancements

Bug Fixes
~~~~~~~~~
- Fix error when embed_options are None (#3376)
- Fix type hints for libraries such as Polars where Altair uses the dataframe interchange protocol (#3297)
- Fix anywidget deprecation warning (#3364)

Expand Down
15 changes: 15 additions & 0 deletions tests/vegalite/v5/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ def test_json_renderer_embed_options(chart, renderer="json"):
assert metadata == {mimetype: {"option": "foo"}}


def test_renderer_with_none_embed_options(chart, renderer="mimetype"):
# Check that setting embed_options to None doesn't crash
from altair.utils.mimebundle import spec_to_mimebundle

spec = chart.to_dict()
with alt.renderers.enable(renderer, embed_options=None):
bundle = spec_to_mimebundle(
spec=spec,
mode="vega-lite",
format="svg",
embed_options=None,
)
assert bundle["image/svg+xml"].startswith("<svg")


def test_jupyter_renderer_mimetype(chart, renderer="jupyter"):
"""Test that we get the expected widget mimetype when the jupyter renderer is enabled"""
with alt.renderers.enable(renderer):
Expand Down

0 comments on commit b1b9dba

Please sign in to comment.