Skip to content

Commit ef5f520

Browse files
committed
fix deprecation warnings
1 parent b3e8d36 commit ef5f520

File tree

3 files changed

+186
-94
lines changed

3 files changed

+186
-94
lines changed

Diff for: plotly/basedatatypes.py

+78-20
Original file line numberDiff line numberDiff line change
@@ -3718,48 +3718,77 @@ def to_image(self, *args, **kwargs):
37183718
- 'webp'
37193719
- 'svg'
37203720
- 'pdf'
3721-
- 'eps' (Requires the poppler library to be installed)
3721+
- 'eps' (deprecated) (Requires the poppler library to be installed)
37223722
3723-
If not specified, will default to `plotly.io.config.default_format`
3723+
If not specified, will default to:
3724+
- `plotly.io.defaults.default_format` if engine is "kaleido"
3725+
- `plotly.io.orca.config.default_format` if engine is "orca" (deprecated)
37243726
37253727
width: int or None
37263728
The width of the exported image in layout pixels. If the `scale`
37273729
property is 1.0, this will also be the width of the exported image
37283730
in physical pixels.
37293731
3730-
If not specified, will default to `plotly.io.config.default_width`
3732+
If not specified, will default to:
3733+
- `plotly.io.defaults.default_width` if engine is "kaleido"
3734+
- `plotly.io.orca.config.default_width` if engine is "orca" (deprecated)
37313735
37323736
height: int or None
37333737
The height of the exported image in layout pixels. If the `scale`
37343738
property is 1.0, this will also be the height of the exported image
37353739
in physical pixels.
37363740
3737-
If not specified, will default to `plotly.io.config.default_height`
3741+
If not specified, will default to:
3742+
- `plotly.io.defaults.default_height` if engine is "kaleido"
3743+
- `plotly.io.orca.config.default_height` if engine is "orca" (deprecated)
37383744
37393745
scale: int or float or None
37403746
The scale factor to use when exporting the figure. A scale factor
37413747
larger than 1.0 will increase the image resolution with respect
37423748
to the figure's layout pixel dimensions. Whereas as scale factor of
37433749
less than 1.0 will decrease the image resolution.
37443750
3745-
If not specified, will default to `plotly.io.config.default_scale`
3751+
If not specified, will default to:
3752+
- `plotly.io.defaults.default_scale` if engine is "kaliedo"
3753+
- `plotly.io.orca.config.default_scale` if engine is "orca" (deprecated)
37463754
37473755
validate: bool
37483756
True if the figure should be validated before being converted to
37493757
an image, False otherwise.
37503758
3751-
engine: str
3752-
Image export engine to use:
3753-
- "kaleido": Use Kaleido for image export
3754-
- "orca": Use Orca for image export
3755-
- "auto" (default): Use Kaleido if installed, otherwise use orca
3759+
engine (deprecated): str
3760+
Image export engine to use. This parameter is deprecated and Orca engine support will be
3761+
dropped in the next major Plotly version. Until then, the following values are supported:
3762+
- "kaleido": Use Kaleido for image export
3763+
- "orca": Use Orca for image export
3764+
- "auto" (default): Use Kaleido if installed, otherwise use Orca
37563765
37573766
Returns
37583767
-------
37593768
bytes
37603769
The image data
37613770
"""
37623771
import plotly.io as pio
3772+
from plotly.io.kaleido import (
3773+
kaleido_available,
3774+
kaleido_major,
3775+
KALEIDO_DEPRECATION_MSG,
3776+
ORCA_DEPRECATION_MSG,
3777+
ENGINE_PARAM_DEPRECATION_MSG,
3778+
)
3779+
3780+
if (
3781+
kwargs.get("engine", None) in {None, "auto", "kaleido"}
3782+
and kaleido_available()
3783+
and kaleido_major() < 1
3784+
):
3785+
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3786+
if kwargs.get("engine", None) == "orca":
3787+
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3788+
if kwargs.get("engine", None):
3789+
warnings.warn(
3790+
ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2
3791+
)
37633792

37643793
return pio.to_image(self, *args, **kwargs)
37653794

@@ -3781,49 +3810,78 @@ def write_image(self, *args, **kwargs):
37813810
- 'webp'
37823811
- 'svg'
37833812
- 'pdf'
3784-
- 'eps' (Requires the poppler library to be installed)
3813+
- 'eps' (deprecated) (Requires the poppler library to be installed)
37853814
37863815
If not specified and `file` is a string then this will default to the
37873816
file extension. If not specified and `file` is not a string then this
3788-
will default to `plotly.io.config.default_format`
3817+
will default to:
3818+
- `plotly.io.defaults.default_format` if engine is "kaleido"
3819+
- `plotly.io.orca.config.default_format` if engine is "orca" (deprecated)
37893820
37903821
width: int or None
37913822
The width of the exported image in layout pixels. If the `scale`
37923823
property is 1.0, this will also be the width of the exported image
37933824
in physical pixels.
37943825
3795-
If not specified, will default to `plotly.io.config.default_width`
3826+
If not specified, will default to:
3827+
- `plotly.io.defaults.default_width` if engine is "kaleido"
3828+
- `plotly.io.orca.config.default_width` if engine is "orca" (deprecated)
37963829
37973830
height: int or None
37983831
The height of the exported image in layout pixels. If the `scale`
37993832
property is 1.0, this will also be the height of the exported image
38003833
in physical pixels.
38013834
3802-
If not specified, will default to `plotly.io.config.default_height`
3835+
If not specified, will default to:
3836+
- `plotly.io.defaults.default_height` if engine is "kaleido"
3837+
- `plotly.io.orca.config.default_height` if engine is "orca" (deprecated)
38033838
38043839
scale: int or float or None
38053840
The scale factor to use when exporting the figure. A scale factor
38063841
larger than 1.0 will increase the image resolution with respect
38073842
to the figure's layout pixel dimensions. Whereas as scale factor of
38083843
less than 1.0 will decrease the image resolution.
38093844
3810-
If not specified, will default to `plotly.io.config.default_scale`
3845+
If not specified, will default to:
3846+
- `plotly.io.defaults.default_scale` if engine is "kaleido"
3847+
- `plotly.io.orca.config.default_scale` if engine is "orca" (deprecated)
38113848
38123849
validate: bool
38133850
True if the figure should be validated before being converted to
38143851
an image, False otherwise.
38153852
3816-
engine: str
3817-
Image export engine to use:
3818-
- "kaleido": Use Kaleido for image export
3819-
- "orca": Use Orca for image export
3820-
- "auto" (default): Use Kaleido if installed, otherwise use orca
3853+
engine (deprecated): str
3854+
Image export engine to use. This parameter is deprecated and Orca engine support will be
3855+
dropped in the next major Plotly version. Until then, the following values are supported:
3856+
- "kaleido": Use Kaleido for image export
3857+
- "orca": Use Orca for image export
3858+
- "auto" (default): Use Kaleido if installed, otherwise use Orca
3859+
38213860
Returns
38223861
-------
38233862
None
38243863
"""
38253864
import plotly.io as pio
3865+
from plotly.io.kaleido import (
3866+
kaleido_available,
3867+
kaleido_major,
3868+
KALEIDO_DEPRECATION_MSG,
3869+
ORCA_DEPRECATION_MSG,
3870+
ENGINE_PARAM_DEPRECATION_MSG,
3871+
)
38263872

3873+
if (
3874+
kwargs.get("engine", None) in {None, "auto", "kaleido"}
3875+
and kaleido_available()
3876+
and kaleido_major() < 1
3877+
):
3878+
warnings.warn(KALEIDO_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3879+
if kwargs.get("engine", None) == "orca":
3880+
warnings.warn(ORCA_DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
3881+
if kwargs.get("engine", None):
3882+
warnings.warn(
3883+
ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2
3884+
)
38273885
return pio.write_image(self, *args, **kwargs)
38283886

38293887
# Static helpers

0 commit comments

Comments
 (0)