Skip to content

Commit 860cc4e

Browse files
timtreisclaude
andcommitted
Fix empty-result crash when no elements match groups with na_color=None
When all elements are filtered out by groups filtering, downstream code crashes: get_extent returns NaN/Inf for points, and GeoDataFrame operations fail on empty geometry for shapes. Add early returns to handle this edge case. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6a34619 commit 860cc4e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/spatialdata_plot/pl/render.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ def _render_shapes(
245245
)
246246
shapes = shapes[keep].reset_index(drop=True)
247247
sdata_filt[element] = shapes
248+
if len(shapes) == 0:
249+
return
248250

249251
# color_source_vector is None when the values aren't categorical
250252
if values_are_categorical and render_params.transfunc is not None:
@@ -871,6 +873,9 @@ def _render_points(
871873
keep, color_source_vector, color_vector = _filter_groups_transparent_na(
872874
groups, color_source_vector, color_vector
873875
)
876+
n_points = int(keep.sum())
877+
if n_points == 0:
878+
return
874879
# filter the materialized points, adata, and re-register in sdata_filt
875880
points = points[keep].reset_index(drop=True)
876881
adata = adata[keep].copy()
@@ -881,7 +886,6 @@ def _render_points(
881886
transformation=transformation_in_cs,
882887
to_coordinate_system=coordinate_system,
883888
)
884-
n_points = int(keep.sum())
885889

886890
# color_source_vector is None when the values aren't categorical
887891
if color_source_vector is None and render_params.transfunc is not None:

0 commit comments

Comments
 (0)