diff --git a/CHANGELOG.md b/CHANGELOG.md index 688407f464..c878960eee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [6.1.1] - 2025-05-20 + +### Fixed +- Prevent swallowing of `ValueError` when creating a figure with subplots [[#3888](https://github.com/plotly/plotly.py/pull/3888)] +- Fix issue causing `fig.write_image()` to not generate an image [[#5193](https://github.com/plotly/plotly.py/pull/5193)] + ## [6.1.0] - 2025-05-15 ### Updated diff --git a/plotly/basedatatypes.py b/plotly/basedatatypes.py index 12b14c1ca8..443c34e826 100644 --- a/plotly/basedatatypes.py +++ b/plotly/basedatatypes.py @@ -3908,7 +3908,7 @@ def write_image(self, *args, **kwargs): warnings.warn( ENGINE_PARAM_DEPRECATION_MSG, DeprecationWarning, stacklevel=2 ) - return pio.write_image(self, *args, **kwargs) + return pio.write_image(self, *args, **kwargs) # Static helpers # -------------- diff --git a/plotly/express/_core.py b/plotly/express/_core.py index 3e0675dcbb..efee6985e3 100644 --- a/plotly/express/_core.py +++ b/plotly/express/_core.py @@ -2890,6 +2890,7 @@ def _spacing_error_translator(e, direction, facet_arg): except ValueError as e: _spacing_error_translator(e, "Horizontal", "facet_col_spacing") _spacing_error_translator(e, "Vertical", "facet_row_spacing") + raise # Remove explicit font size of row/col titles so template can take over for annot in fig.layout.annotations: diff --git a/pyproject.toml b/pyproject.toml index 6ffbbbee86..8d8e813caa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,7 @@ classifiers = [ ] requires-python = ">=3.8" license = {file="LICENSE.txt"} -version = "6.1.0" +version = "6.1.1" dependencies = [ "narwhals>=1.15.1", "packaging" diff --git a/tests/test_optional/test_kaleido/test_kaleido.py b/tests/test_optional/test_kaleido/test_kaleido.py index 9a9d414dc9..84b0777230 100644 --- a/tests/test_optional/test_kaleido/test_kaleido.py +++ b/tests/test_optional/test_kaleido/test_kaleido.py @@ -1,15 +1,18 @@ +import base64 +from contextlib import redirect_stdout from io import BytesIO, StringIO from pathlib import Path import tempfile -from contextlib import redirect_stdout -import base64 +from unittest.mock import patch from pdfrw import PdfReader from PIL import Image +import plotly.graph_objects as go import plotly.io as pio from plotly.io.kaleido import kaleido_available, kaleido_major import pytest + fig = {"data": [], "layout": {"title": {"text": "figure title"}}} @@ -160,3 +163,43 @@ def test_defaults(): finally: pio.defaults.default_format = "png" assert pio.defaults.default_format == "png" + + +def test_fig_write_image(): + """Test that fig.write_image() calls the correct underlying Kaleido function.""" + + test_fig = go.Figure(fig) + test_image_bytes = b"mock image data" + + if kaleido_major() > 0: + patch_funcname = "plotly.io._kaleido.kaleido.calc_fig_sync" + else: + patch_funcname = "plotly.io._kaleido.scope.transform" + + with patch(patch_funcname, return_value=test_image_bytes) as mock_calc_fig: + test_fig.write_image("test_path.png") + + # Verify patched function was called once with fig dict as first argument + mock_calc_fig.assert_called_once() + args, _ = mock_calc_fig.call_args + assert args[0] == test_fig.to_dict() + + +def test_fig_to_image(): + """Test that fig.to_image() calls the correct underlying Kaleido function.""" + + test_fig = go.Figure(fig) + test_image_bytes = b"mock image data" + + if kaleido_major() > 0: + patch_funcname = "plotly.io._kaleido.kaleido.calc_fig_sync" + else: + patch_funcname = "plotly.io._kaleido.scope.transform" + + with patch(patch_funcname, return_value=test_image_bytes) as mock_calc_fig: + test_fig.to_image() + + # Verify patched function was called once with fig dict as first argument + mock_calc_fig.assert_called_once() + args, _ = mock_calc_fig.call_args + assert args[0] == test_fig.to_dict()