Skip to content

Commit ea71fed

Browse files
timtreisclaude
andcommitted
Fix datashader single-group bug, make tests 2-panel comparisons
Fix: the datashader shapes path skipped categorical aggregation when groups had exactly 1 entry (len(groups) > 1 was False), producing an empty plot. Remove the erroneous groups-length guard. Tests: all 4 groups-filtering PlotTester tests now show 2 panels side-by-side (left: default with na_color shown, right: na_color=None with filtered elements) for easy visual comparison. Baseline images removed — will be regenerated by CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 54d66aa commit ea71fed

7 files changed

+25
-5
lines changed

src/spatialdata_plot/pl/render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def _render_shapes(
416416

417417
aggregate_with_reduction = None
418418
continuous_nan_shapes = None
419-
if col_for_color is not None and (render_params.groups is None or len(render_params.groups) > 1):
419+
if col_for_color is not None:
420420
if color_by_categorical:
421421
# add a sentinel category so that shapes with NaN value are colored in the na_color
422422
transformed_element[col_for_color] = _inject_ds_nan_sentinel(transformed_element[col_for_color])
-37.4 KB
Binary file not shown.
Binary file not shown.
-23.2 KB
Binary file not shown.
Binary file not shown.

tests/pl/test_render_points.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,24 @@ def test_plot_can_annotate_points_with_nan_in_df_continuous_datashader(self, sda
579579
def test_plot_groups_na_color_none_filters_points(self, sdata_blobs: SpatialData):
580580
"""When groups is set and na_color=None, non-matching points are filtered out entirely."""
581581
sdata_blobs["blobs_points"]["cat_color"] = pd.Series(["a", "b", "c", "a"] * 50, dtype="category")
582-
sdata_blobs.pl.render_points("blobs_points", color="cat_color", groups=["a"], na_color=None, size=30).pl.show()
582+
_, axs = plt.subplots(nrows=1, ncols=2, layout="tight")
583+
sdata_blobs.pl.render_points("blobs_points", color="cat_color", groups=["a"], size=30).pl.show(
584+
ax=axs[0], title="default"
585+
)
586+
sdata_blobs.pl.render_points("blobs_points", color="cat_color", groups=["a"], na_color=None, size=30).pl.show(
587+
ax=axs[1], title="na_color=None"
588+
)
583589

584590
def test_plot_groups_na_color_none_filters_points_datashader(self, sdata_blobs: SpatialData):
585591
"""Groups filtering with na_color=None via datashader backend."""
586592
sdata_blobs["blobs_points"]["cat_color"] = pd.Series(["a", "b", "c", "a"] * 50, dtype="category")
593+
_, axs = plt.subplots(nrows=1, ncols=2, layout="tight")
594+
sdata_blobs.pl.render_points(
595+
"blobs_points", color="cat_color", groups=["a"], size=30, method="datashader"
596+
).pl.show(ax=axs[0], title="default")
587597
sdata_blobs.pl.render_points(
588598
"blobs_points", color="cat_color", groups=["a"], na_color=None, size=30, method="datashader"
589-
).pl.show()
599+
).pl.show(ax=axs[1], title="na_color=None")
590600

591601

592602
def test_groups_na_color_none_no_match_points(sdata_blobs: SpatialData):

tests/pl/test_render_shapes.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,14 +986,24 @@ def test_plot_can_annotate_shapes_with_nan_in_df_continuous_datashader(self, sda
986986
def test_plot_groups_na_color_none_filters_shapes(self, sdata_blobs: SpatialData):
987987
"""When groups is set and na_color=None, non-matching shapes are filtered out entirely."""
988988
sdata_blobs["blobs_polygons"]["cat_color"] = pd.Series(["a", "b", "a", "b", "a"], dtype="category")
989-
sdata_blobs.pl.render_shapes("blobs_polygons", color="cat_color", groups=["a"], na_color=None).pl.show()
989+
_, axs = plt.subplots(nrows=1, ncols=2, layout="tight")
990+
sdata_blobs.pl.render_shapes("blobs_polygons", color="cat_color", groups=["a"]).pl.show(
991+
ax=axs[0], title="default"
992+
)
993+
sdata_blobs.pl.render_shapes("blobs_polygons", color="cat_color", groups=["a"], na_color=None).pl.show(
994+
ax=axs[1], title="na_color=None"
995+
)
990996

991997
def test_plot_groups_na_color_none_filters_shapes_datashader(self, sdata_blobs: SpatialData):
992998
"""Groups filtering with na_color=None via datashader backend."""
993999
sdata_blobs["blobs_polygons"]["cat_color"] = pd.Series(["a", "b", "a", "b", "a"], dtype="category")
1000+
_, axs = plt.subplots(nrows=1, ncols=2, layout="tight")
1001+
sdata_blobs.pl.render_shapes("blobs_polygons", color="cat_color", groups=["a"], method="datashader").pl.show(
1002+
ax=axs[0], title="default"
1003+
)
9941004
sdata_blobs.pl.render_shapes(
9951005
"blobs_polygons", color="cat_color", groups=["a"], na_color=None, method="datashader"
996-
).pl.show()
1006+
).pl.show(ax=axs[1], title="na_color=None")
9971007

9981008

9991009
def test_groups_na_color_none_no_match_shapes(sdata_blobs: SpatialData):

0 commit comments

Comments
 (0)