Skip to content

Commit 6dad2dc

Browse files
Suppress sharing warnings when no sharing is possible (#715)
* Suppress sharing warnings when no sharing is possible * 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. --------- Co-authored-by: cvanelteren <caspervanelteren@gmail.com>
1 parent 71e7607 commit 6dad2dc

3 files changed

Lines changed: 85 additions & 14 deletions

File tree

ultraplot/axes/base.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,22 +1347,24 @@ def shared(paxs):
13471347

13481348
# External axes sharing, sometimes overrides panel axes sharing
13491349
# Share x axes within compatible groups
1350-
axes_x = self._get_share_axes("x")
1351-
for group in self.figure._partition_share_axes(axes_x, "x"):
1352-
if not group:
1353-
continue
1354-
parent, *children = group
1355-
for child in children:
1356-
child._sharex_setup(parent)
1350+
if self.figure._sharex > 0:
1351+
axes_x = self._get_share_axes("x")
1352+
for group in self.figure._partition_share_axes(axes_x, "x"):
1353+
if not group:
1354+
continue
1355+
parent, *children = group
1356+
for child in children:
1357+
child._sharex_setup(parent)
13571358

13581359
# Share y axes within compatible groups
1359-
axes_y = self._get_share_axes("y")
1360-
for group in self.figure._partition_share_axes(axes_y, "y"):
1361-
if not group:
1362-
continue
1363-
parent, *children = group
1364-
for child in children:
1365-
child._sharey_setup(parent)
1360+
if self.figure._sharey > 0:
1361+
axes_y = self._get_share_axes("y")
1362+
for group in self.figure._partition_share_axes(axes_y, "y"):
1363+
if not group:
1364+
continue
1365+
parent, *children = group
1366+
for child in children:
1367+
child._sharey_setup(parent)
13661368

13671369
# Global sharing, use the reference subplot where compatible
13681370
ref = self.figure._subplot_dict.get(self.figure._refnum, None)

ultraplot/figure.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,25 @@ def _share_ticklabels(self, *, axis: str) -> None:
13251325

13261326
# Process each group independently
13271327
for _, group_axes in groups.items():
1328+
# Singleton groups can still need border masking reapplied for
1329+
# supported axes (e.g. GeoAxes split by guides), but unsupported
1330+
# singleton groups like a single PolarAxes should not warn.
1331+
main_axes = [
1332+
axi for axi in group_axes if not getattr(axi, "_panel_side", None)
1333+
]
1334+
supported_main_axes = any(
1335+
isinstance(
1336+
axi, (paxes.CartesianAxes, paxes._CartopyAxes, paxes._BasemapAxes)
1337+
)
1338+
for axi in main_axes
1339+
)
1340+
if len(group_axes) < 2 and not supported_main_axes:
1341+
continue
1342+
if all(
1343+
self._effective_share_level(axi, axis, sides) < 3 for axi in group_axes
1344+
):
1345+
continue
1346+
13281347
# Build baseline from MAIN axes only (exclude panels)
13291348
baseline, skip_group = self._compute_baseline_tick_state(
13301349
group_axes, axis, label_keys

ultraplot/tests/test_figure.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,56 @@ def test_explicit_share_warns_for_mixed_cartesian_polar():
354354
assert len(incompatible) == 1
355355

356356

357+
def test_share_zero_polar_emits_no_warnings(recwarn):
358+
fig, axs = uplt.subplots(proj="polar", ncols=2, nrows=3, share=0)
359+
fig.canvas.draw()
360+
361+
ultra = [
362+
w
363+
for w in recwarn
364+
if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning)
365+
]
366+
assert ultra == [], [str(w.message) for w in ultra]
367+
368+
369+
def test_share_zero_mixed_cartesian_polar_emits_no_warnings(recwarn):
370+
fig, axs = uplt.subplots(ncols=2, proj=("cart", "polar"), share=0)
371+
fig.canvas.draw()
372+
373+
ultra = [
374+
w
375+
for w in recwarn
376+
if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning)
377+
]
378+
assert ultra == [], [str(w.message) for w in ultra]
379+
380+
381+
def test_share_default_single_polar_emits_no_warnings(recwarn):
382+
"""A single polar axis has nothing to share — must not warn at default share."""
383+
fig, ax = uplt.subplots(proj="polar")
384+
fig.canvas.draw()
385+
386+
ultra = [
387+
w
388+
for w in recwarn
389+
if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning)
390+
]
391+
assert ultra == [], [str(w.message) for w in ultra]
392+
393+
394+
def test_share_default_single_polar_subplot_singular_emits_no_warnings(recwarn):
395+
"""``uplt.subplot(proj='polar')`` (singular) has nothing to share either."""
396+
fig, ax = uplt.subplot(proj="polar")
397+
fig.canvas.draw()
398+
399+
ultra = [
400+
w
401+
for w in recwarn
402+
if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning)
403+
]
404+
assert ultra == [], [str(w.message) for w in ultra]
405+
406+
357407
def test_auto_share_local_yscale_change_splits_group():
358408
fig, axs = uplt.subplots(ncols=2, share="auto")
359409
fig.canvas.draw()

0 commit comments

Comments
 (0)