From 67151573408fdeb61f09626f2873c3210a54b28b Mon Sep 17 00:00:00 2001 From: anon Date: Wed, 20 May 2026 16:26:55 +0200 Subject: [PATCH] Raise clear error for all-empty shapes (#629) Previously `render_shapes(...).show()` crashed with a bare upstream `AssertionError("Cannot compute extent of an empty collection of geometries.")` when every geometry in a shape element was empty. Detect this up front before calling `get_extent` and raise a `ValueError` naming the element(s) and coordinate system instead. --- src/spatialdata_plot/pl/basic.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/spatialdata_plot/pl/basic.py b/src/spatialdata_plot/pl/basic.py index e1d28d3b..8b3ce310 100644 --- a/src/spatialdata_plot/pl/basic.py +++ b/src/spatialdata_plot/pl/basic.py @@ -1513,6 +1513,18 @@ def _draw_colorbar( if fig_params.frameon is False: ax.axis("off") + if has_shapes and wants_shapes: + empty_shape_elements = [ + name + for name in wanted_elements + if name in sdata.shapes and not sdata.shapes[name]["geometry"].apply(lambda g: not g.is_empty).any() + ] + if empty_shape_elements: + raise ValueError( + f"Cannot render shape element(s) {empty_shape_elements} in coordinate system {cs!r}: " + "all geometries are empty. Drop the element or restore at least one non-empty geometry." + ) + extent = get_extent( sdata, coordinate_system=cs,