You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
Thank you sooooooo much for your work on, well, everything. Here, in particular on altair ❤️
I was thrilled to discover altair_saver, as I just happened to need a way of saving plots to HTML with the javascript dependencies inline: altair_saver.save(chart, "boom.html", inline=True)!
The encoding happens in a module named "cp1252.py", which seems to indicate the Windows 1252 encoding
How my machine ends up thinking 1252 is the way to go is beyond me: I checked sys.getdefaultencoding() and got utf-8.
Context
altair 4.0.1
altair_saver 0.1.0
vega_datasets 0.8.0
conda-installed python 3.7.6
Windows 10
Monkeypatching solution
I found that I could "solve" the problem (i.e., successfully save a usable html) by monkeypatching altair_saver.savers._saver.maybe_open to explicitly use utf-8, like so:
importcontextlibfromtypingimportUnion, Iterator, IO@contextlib.contextmanagerdefmaybe_open(fp: Union[IO, str], mode: str="w") ->Iterator[IO]:
"""Write to string or file-like object"""ifisinstance(fp, str):
withopen(fp, mode, encoding="UTF-8") asf: # --------- I added the encoding kwargyieldfelifisinstance(fp, io.TextIOBase) and"b"inmode:
raiseValueError("File expected to be opened in binary mode.")
elifisinstance(fp, io.BufferedIOBase) and"b"notinmode:
raiseValueError("File expected to be opened in text mode")
else:
yieldfpfromaltair_saver.saversimport_saver_saver.maybe_open=maybe_open
I know far too little about HTML encodings to tell if this is a generally good idea, so... draw your own conclusions 😉
The text was updated successfully, but these errors were encountered:
We are going to archive this repo, so I'm closing all the open issues and PRs before doing so. Try out the new options for saving charts mentioned above and if you run into issues, please open an issue directly in the altair or vl-convert repo.
Hi Jake!
Thank you sooooooo much for your work on, well, everything. Here, in particular on altair ❤️
I was thrilled to discover
altair_saver
, as I just happened to need a way of saving plots to HTML with the javascript dependencies inline:altair_saver.save(chart, "boom.html", inline=True)
!Problem
At first try, it fails on my machine:
sys.getdefaultencoding()
and got utf-8.Context
conda-installed python 3.7.6
Windows 10
Monkeypatching solution
I found that I could "solve" the problem (i.e., successfully save a usable html) by monkeypatching
altair_saver.savers._saver.maybe_open
to explicitly use utf-8, like so:I know far too little about HTML encodings to tell if this is a generally good idea, so... draw your own conclusions 😉
The text was updated successfully, but these errors were encountered: