Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embed_options in mimebundle is NoneType (error when calling chart.save in Altair to a PDF) #159

Closed
jowens opened this issue Mar 21, 2024 · 5 comments

Comments

@jowens
Copy link

jowens commented Mar 21, 2024

Having trouble interpreting the error message when calling chart.save to a PDF.

    chart.save(os.path.join(outputdir, title + ".pdf"), engine="vl-convert")
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/altair/vegalite/v5/api.py", line 1214, in save
    save(**kwds)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/altair/utils/save.py", line 200, in save
    perform_save()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/altair/utils/save.py", line 162, in perform_save
    mimebundle = spec_to_mimebundle(
                 ^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/altair/utils/mimebundle.py", line 77, in spec_to_mimebundle
    embed_options = preprocess_embed_options(embed_options)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/altair/utils/mimebundle.py", line 321, in preprocess_embed_options
    embed_options = embed_options.copy()
                    ^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'copy'

I have import vl_convert as vlc (although no other references to vlc in my code) and I've done pip install vl-convert-python but there's nothing in that trace that indicates it's dropped out of Altair into vl_convert. The Altair instructions are dead simple (https://altair-viz.github.io/user_guide/saving_charts.html) so I've clearly missed something.

Keeping you busy today!

@jonmmease
Copy link
Collaborator

Hey @jowens, you don't have to import vl_convert for this to work. This error is in Altair before it gets to invoking vl-convert. Can you open an issue in the altair repo (https://github.com/altair-viz/altair) with a repro and the exact version of altair you're using?

I can't reproduce this with a simple test, and looking at the code in https://github.com/altair-viz/altair/blob/v5.2.0/altair/utils/mimebundle.py, it doesn't look like embed_options should ever be None when passed into preprocess_embed_options.

One quick thing to look at is, what's the result of?

import altair as alt
alt.renderers.options.get("embed_options", {})

Could you include this result in the Altair issue?

@jowens
Copy link
Author

jowens commented Mar 22, 2024

Hate to make your life harder, really I do.

print(alt.renderers.options.get("embed_options", {}))
vf.enable()
print(alt.renderers.options.get("embed_options", {}))

prints

{}
None

@jowens
Copy link
Author

jowens commented Mar 22, 2024

Oh wait that's vegafusion. That's not you.

@jowens
Copy link
Author

jowens commented Mar 22, 2024

I've disabled vf and everything works as expected.

@jonmmease
Copy link
Collaborator

jonmmease commented Mar 22, 2024

Oh, that's really helpful! I'll open a VegaFusion issue to avoid setting this to None.

See vega/vegafusion#474

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants