From 24e504452d532a539600500b39e16df8409b6e31 Mon Sep 17 00:00:00 2001 From: kinyatoride Date: Tue, 5 May 2026 21:38:49 -0600 Subject: [PATCH 1/2] Suppress sharing warnings when no sharing is possible --- ultraplot/axes/base.py | 30 ++++++++++---------- ultraplot/figure.py | 9 ++++++ ultraplot/tests/test_figure.py | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 14 deletions(-) diff --git a/ultraplot/axes/base.py b/ultraplot/axes/base.py index 416b33430..f72dea8a8 100644 --- a/ultraplot/axes/base.py +++ b/ultraplot/axes/base.py @@ -1347,22 +1347,24 @@ def shared(paxs): # External axes sharing, sometimes overrides panel axes sharing # Share x axes within compatible groups - axes_x = self._get_share_axes("x") - for group in self.figure._partition_share_axes(axes_x, "x"): - if not group: - continue - parent, *children = group - for child in children: - child._sharex_setup(parent) + if self.figure._sharex > 0: + axes_x = self._get_share_axes("x") + for group in self.figure._partition_share_axes(axes_x, "x"): + if not group: + continue + parent, *children = group + for child in children: + child._sharex_setup(parent) # Share y axes within compatible groups - axes_y = self._get_share_axes("y") - for group in self.figure._partition_share_axes(axes_y, "y"): - if not group: - continue - parent, *children = group - for child in children: - child._sharey_setup(parent) + if self.figure._sharey > 0: + axes_y = self._get_share_axes("y") + for group in self.figure._partition_share_axes(axes_y, "y"): + if not group: + continue + parent, *children = group + for child in children: + child._sharey_setup(parent) # Global sharing, use the reference subplot where compatible ref = self.figure._subplot_dict.get(self.figure._refnum, None) diff --git a/ultraplot/figure.py b/ultraplot/figure.py index 334c61a44..59646d1cd 100644 --- a/ultraplot/figure.py +++ b/ultraplot/figure.py @@ -1325,6 +1325,15 @@ def _share_ticklabels(self, *, axis: str) -> None: # Process each group independently for _, group_axes in groups.items(): + # Nothing to share if the group is too small or sharing is disabled — + # avoids unsupported-type warnings (e.g. PolarAxes) for those cases. + if len(group_axes) < 2: + continue + if all( + self._effective_share_level(axi, axis, sides) < 3 for axi in group_axes + ): + continue + # Build baseline from MAIN axes only (exclude panels) baseline, skip_group = self._compute_baseline_tick_state( group_axes, axis, label_keys diff --git a/ultraplot/tests/test_figure.py b/ultraplot/tests/test_figure.py index a78ac0402..6ae668c4f 100644 --- a/ultraplot/tests/test_figure.py +++ b/ultraplot/tests/test_figure.py @@ -354,6 +354,56 @@ def test_explicit_share_warns_for_mixed_cartesian_polar(): assert len(incompatible) == 1 +def test_share_zero_polar_emits_no_warnings(recwarn): + fig, axs = uplt.subplots(proj="polar", ncols=2, nrows=3, share=0) + fig.canvas.draw() + + ultra = [ + w + for w in recwarn + if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning) + ] + assert ultra == [], [str(w.message) for w in ultra] + + +def test_share_zero_mixed_cartesian_polar_emits_no_warnings(recwarn): + fig, axs = uplt.subplots(ncols=2, proj=("cart", "polar"), share=0) + fig.canvas.draw() + + ultra = [ + w + for w in recwarn + if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning) + ] + assert ultra == [], [str(w.message) for w in ultra] + + +def test_share_default_single_polar_emits_no_warnings(recwarn): + """A single polar axis has nothing to share — must not warn at default share.""" + fig, ax = uplt.subplots(proj="polar") + fig.canvas.draw() + + ultra = [ + w + for w in recwarn + if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning) + ] + assert ultra == [], [str(w.message) for w in ultra] + + +def test_share_default_single_polar_subplot_singular_emits_no_warnings(recwarn): + """``uplt.subplot(proj='polar')`` (singular) has nothing to share either.""" + fig, ax = uplt.subplot(proj="polar") + fig.canvas.draw() + + ultra = [ + w + for w in recwarn + if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning) + ] + assert ultra == [], [str(w.message) for w in ultra] + + def test_auto_share_local_yscale_change_splits_group(): fig, axs = uplt.subplots(ncols=2, share="auto") fig.canvas.draw() From 320b569735d9b323ac9dc1e2b52b5ea4e3c2089c Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 12 May 2026 14:21:16 +1000 Subject: [PATCH 2/2] Tighten the singleton-group guard in figure ticklabel sharing so we still reapply border masking for supported cartesian and geographic axes, while continuing to suppress no-op warnings for unsupported singleton groups like a lone polar subplot. This restores the guide-related geo ticklabel updates that the broader warning suppression accidentally skipped. --- ultraplot/figure.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ultraplot/figure.py b/ultraplot/figure.py index 59646d1cd..63538f12e 100644 --- a/ultraplot/figure.py +++ b/ultraplot/figure.py @@ -1325,9 +1325,19 @@ def _share_ticklabels(self, *, axis: str) -> None: # Process each group independently for _, group_axes in groups.items(): - # Nothing to share if the group is too small or sharing is disabled — - # avoids unsupported-type warnings (e.g. PolarAxes) for those cases. - if len(group_axes) < 2: + # Singleton groups can still need border masking reapplied for + # supported axes (e.g. GeoAxes split by guides), but unsupported + # singleton groups like a single PolarAxes should not warn. + main_axes = [ + axi for axi in group_axes if not getattr(axi, "_panel_side", None) + ] + supported_main_axes = any( + isinstance( + axi, (paxes.CartesianAxes, paxes._CartopyAxes, paxes._BasemapAxes) + ) + for axi in main_axes + ) + if len(group_axes) < 2 and not supported_main_axes: continue if all( self._effective_share_level(axi, axis, sides) < 3 for axi in group_axes