Skip to content

Commit f5e962b

Browse files
timtreisclaude
andcommitted
Use proper DeprecationWarning for fig, add visual PlotTester tests
Switch fig deprecation from logger.warning() to warnings.warn(DeprecationWarning) matching the _deprecation_alias pattern used elsewhere. Add baseline-image tests for frameon=False on single-panel and multi-panel plots. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 31e6a76 commit f5e962b

4 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/spatialdata_plot/pl/basic.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import contextlib
44
import sys
5+
import warnings
56
from collections import OrderedDict
67
from collections.abc import Callable, Sequence
78
from copy import deepcopy
@@ -939,10 +940,12 @@ def show(
939940
)
940941

941942
if fig is not None and not isinstance(ax, Sequence):
942-
logger.warning(
943-
"The `fig` parameter is deprecated and will be removed in a future version. "
943+
warnings.warn(
944+
"`fig` is being deprecated as an argument to `PlotAccessor.show` in spatialdata-plot. "
944945
"To use a custom figure, create axes from it and pass them via `ax` instead: "
945-
"`ax = fig.add_subplot(111)`."
946+
"`ax = fig.add_subplot(111)`.",
947+
DeprecationWarning,
948+
stacklevel=2,
946949
)
947950

948951
sdata = self._copy()
23.2 KB
Loading
91.3 KB
Loading

tests/pl/test_show.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import warnings
12
from unittest.mock import patch
23

34
import matplotlib
45
import matplotlib.pyplot as plt
6+
import pytest
57
import scanpy as sc
68
from matplotlib.figure import Figure
79
from spatialdata import SpatialData
810

911
import spatialdata_plot # noqa: F401
10-
from spatialdata_plot._logging import logger, logger_no_warns, logger_warns
1112
from tests.conftest import DPI, PlotTester, PlotTesterMeta
1213

1314
sc.pl.set_rcParams_defaults()
@@ -27,6 +28,15 @@ class TestShow(PlotTester, metaclass=PlotTesterMeta):
2728
def test_plot_pad_extent_adds_padding(self, sdata_blobs: SpatialData):
2829
sdata_blobs.pl.render_images(element="blobs_image").pl.show(pad_extent=100)
2930

31+
def test_plot_frameon_false_single_panel(self, sdata_blobs: SpatialData):
32+
"""Visual test: frameon=False hides axes decorations on a single panel (regression for #204)."""
33+
sdata_blobs.pl.render_images(element="blobs_image").pl.show(frameon=False)
34+
35+
def test_plot_frameon_false_multi_panel(self, get_sdata_with_multiple_images):
36+
"""Visual test: frameon=False hides axes decorations on all panels (regression for #204)."""
37+
sdata = get_sdata_with_multiple_images("two")
38+
sdata.pl.render_images().pl.show(frameon=False)
39+
3040
def test_no_plt_show_when_ax_provided(self, sdata_blobs: SpatialData):
3141
"""plt.show() must not be called when the user supplies ax= (regression for #362)."""
3242
_, ax = plt.subplots()
@@ -62,26 +72,28 @@ def test_title_empty_string_suppresses_title(self, sdata_blobs: SpatialData):
6272
plt.close("all")
6373

6474

65-
def test_fig_parameter_emits_deprecation_warning(sdata_blobs: SpatialData, caplog):
66-
"""Passing fig= should emit a deprecation warning (regression for #204)."""
75+
def test_fig_parameter_emits_deprecation_warning(sdata_blobs: SpatialData):
76+
"""Passing fig= should emit a DeprecationWarning (regression for #204)."""
6777
fig = Figure()
68-
with logger_warns(caplog, logger, match="The `fig` parameter is deprecated"):
78+
with pytest.warns(DeprecationWarning, match="`fig` is being deprecated"):
6979
sdata_blobs.pl.render_images(element="blobs_image").pl.show(fig=fig, show=False)
7080
plt.close("all")
7181

7282

73-
def test_fig_parameter_default_no_warning(sdata_blobs: SpatialData, caplog):
83+
def test_fig_parameter_default_no_warning(sdata_blobs: SpatialData):
7484
"""Not passing fig= should not emit a deprecation warning."""
75-
with logger_no_warns(caplog, logger, match="The `fig` parameter is deprecated"):
85+
with warnings.catch_warnings():
86+
warnings.simplefilter("error", DeprecationWarning)
7687
sdata_blobs.pl.render_images(element="blobs_image").pl.show(show=False)
7788
plt.close("all")
7889

7990

80-
def test_fig_parameter_no_warning_with_ax_list(get_sdata_with_multiple_images, caplog):
91+
def test_fig_parameter_no_warning_with_ax_list(get_sdata_with_multiple_images):
8192
"""Passing fig= with a list of axes should not warn (fig is still required there)."""
8293
sdata = get_sdata_with_multiple_images("two")
8394
fig, axs = plt.subplots(1, 2)
84-
with logger_no_warns(caplog, logger, match="The `fig` parameter is deprecated"):
95+
with warnings.catch_warnings():
96+
warnings.simplefilter("error", DeprecationWarning)
8597
sdata.pl.render_images().pl.show(fig=fig, ax=list(axs), show=False)
8698
plt.close("all")
8799

0 commit comments

Comments
 (0)