nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: altair-viz/altair
Pull request #3376 (2024-03-22 11:40:53)

fix: Don't error when embed_options are None
Fix for https://github.com/vega/vl-convert/issues/159


Patch:
diff --git a/altair/utils/mimebundle.py b/altair/utils/mimebundle.py
index a06f1f19..49a1f555 100644
--- a/altair/utils/mimebundle.py
+++ b/altair/utils/mimebundle.py
@@ -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)
diff --git a/doc/releases/changes.rst b/doc/releases/changes.rst
index be354bb3..81690155 100644
--- a/doc/releases/changes.rst
+++ b/doc/releases/changes.rst
@@ -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)
 


Test patch:
diff --git a/tests/vegalite/v5/test_renderers.py b/tests/vegalite/v5/test_renderers.py
index 998a958c..7201c41d 100644
--- a/tests/vegalite/v5/test_renderers.py
+++ b/tests/vegalite/v5/test_renderers.py
@@ -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):