-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Support Kaleido v1 in Plotly.py #5062
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments and a question, happy to read through again as soon as you want.
- 'webp' | ||
- 'svg' | ||
- 'pdf' | ||
- 'eps' (Requires the poppler library to be installed and on the PATH) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still handle EPS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gvwilson Following up on this — Kaleido v1 does not support EPS yet. So either we drop support for EPS entirely, or document that EPS is only available with Kaleido v0 and add an informative error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do the latter - thanks
- "kaleido": Use Kaleido for image export | ||
- "orca": Use Orca for image export | ||
- "auto" (default): Use Kaleido if installed, otherwise use orca | ||
engine (deprecated): str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we print a deprecation warning if this argument is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, assuming we are in agreement about removing this argument, I'll add one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in agreement that we should remove this argument
def check_image(path_or_buffer, size=(700, 500), format="PNG"): | ||
if format == "PDF": | ||
img = PdfReader(path_or_buffer) | ||
# TODO: There is a conversion factor needed here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of the TODO is for me to educate myself on how Plotly currently determines PDF size when writing to PDF. :)
But the size
argument is measured in pixels (at least for raster file types) and PDFs have no concept of pixels so I wouldn't expect the PDF to report the same "size" as passed in the argument necessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will also take a looksy on that issue, lets say for this and the above tomorrow. I am flying today.
cc @ayjayt |
Do we need to maintain backwards compatibility with older Kaleido versions here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there percy tests that use kaleido to make sure that the actual images generated are correct?
If not specified, will default to: | ||
- `plotly.io.kaleido.scope.default_format` if engine is "kaleido" | ||
- `plotly.io.orca.config.default_format` if engine is "orca" | ||
If not specified, will default to `plotly.io.kaleido.scope.default_format` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these references to plotly.io.kaleido.scope..
need to be something else if that's no longer imported here
https://github.com/plotly/plotly.py/pull/5062/files#diff-40813ac13aafeaa7135da57a86bec52cae638135b0acf9324677c9c4eee2ba2bR1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, those docstrings should be changed -- I need to research where those defaults are defined in Kaleido v1. (@ayjayt do you know off the top of your head?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order is png default overridden by user-specified output path w/ extension overriden by user-specified format in opts
uv pip install -r ./test_requirements/requirements_optional.txt | ||
# Install Kaleido v1 instead of the default version | ||
uv pip uninstall -y kaleido | ||
uv pip install 'git+https://github.com/plotly/[email protected]#subdirectory=src/py' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uv pip install kaleido>=1.0.0 || uv pip install 'git+https://github.com/plotly/Kaleido.git@latest-tag#subdirectory=src/py'
is my recommendation
This initial draft is an attempt at supporting both the Kaleido v0 and v1 APIs in Plotly.py.
The changes so far are contained to
plotly/io/_kaleido.py
,plotly/io/kaleido.py
, andtests/test_optional/test_kaleido/test_kaleido.py
.fig.write_image()
,fig.to_image()
,pio.write_image()
, andpio.to_image()
are basically working with both Kaleido versions as far as I can tell (with the exception of writing EPS files, which is not yet supported by Kaleido v1).These changes also remove support for orca.
There are some remaining test failures to investigate.
TODO
engine
argument towrite_image
/to_image