Skip to content

Commit 91346dc

Browse files
committed
test(as_points): matched matplotlib/datashader visual pairs
Restructure the as_points visual tests into matplotlib+datashader pairs that render identical params (shared helper) for shapes (no color), labels (instance_id), and labels (categorical). Drop the old inconsistent/stale baselines; all 6 will be regenerated from CI so the two backends are directly comparable and look maximally similar.
1 parent 920b9ca commit 91346dc

7 files changed

Lines changed: 32 additions & 26 deletions
-31.9 KB
Binary file not shown.
-41.2 KB
Binary file not shown.
-34.7 KB
Binary file not shown.
-45.2 KB
Binary file not shown.
-16.2 KB
Binary file not shown.

tests/pl/test_render_labels.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -435,29 +435,34 @@ def test_plot_can_color_labels_by_gene_symbols(self, sdata_blobs: SpatialData):
435435
"blobs_labels", color="GeneA", table_name="table", gene_symbols="gene_symbol"
436436
).pl.show()
437437

438-
def test_plot_can_render_labels_as_points(self, sdata_blobs: SpatialData):
439-
"""as_points draws one colored dot per label at its centroid instead of the mask."""
440-
sdata_blobs.pl.render_labels("blobs_labels", color="instance_id", as_points=True, size=100).pl.show()
438+
@staticmethod
439+
def _as_points(sdata_blobs: SpatialData, method: str, color: str = "instance_id"):
440+
# identical params for both backends, so the matplotlib and datashader baselines are comparable
441+
return sdata_blobs.pl.render_labels("blobs_labels", color=color, as_points=True, method=method, size=600)
441442

442-
def test_plot_labels_as_points_respects_size(self, sdata_blobs: SpatialData):
443-
"""size sets the scatter marker area; larger size -> larger dots."""
444-
sdata_blobs.pl.render_labels("blobs_labels", color="instance_id", as_points=True, size=600).pl.show()
445-
446-
def test_plot_labels_as_points_datashader(self, sdata_blobs: SpatialData):
447-
"""as_points with method='datashader' rasterizes the colored centroids instead of drawing markers."""
448-
sdata_blobs.pl.render_labels(
449-
"blobs_labels", color="instance_id", as_points=True, method="datashader", size=600
450-
).pl.show()
451-
452-
def test_plot_labels_as_points_datashader_categorical(self, sdata_blobs: SpatialData):
453-
"""Categorical-coloured as_points centroids datashade with a legend (color_source_vector path)."""
443+
@staticmethod
444+
def _add_categorical_color(sdata_blobs: SpatialData) -> str:
454445
max_col = sdata_blobs["table"].to_df().idxmax(axis=1)
455446
sdata_blobs["table"].obs["which_max"] = pd.Categorical(
456447
max_col, categories=sdata_blobs["table"].to_df().columns, ordered=True
457448
)
458-
sdata_blobs.pl.render_labels(
459-
"blobs_labels", color="which_max", as_points=True, method="datashader", size=600
460-
).pl.show()
449+
return "which_max"
450+
451+
def test_plot_labels_as_points_matplotlib(self, sdata_blobs: SpatialData):
452+
"""as_points draws one colored dot per label at its centroid (matplotlib backend)."""
453+
self._as_points(sdata_blobs, "matplotlib").pl.show()
454+
455+
def test_plot_labels_as_points_datashader(self, sdata_blobs: SpatialData):
456+
"""Same render via datashader; should look maximally similar to the matplotlib baseline."""
457+
self._as_points(sdata_blobs, "datashader").pl.show()
458+
459+
def test_plot_labels_as_points_categorical_matplotlib(self, sdata_blobs: SpatialData):
460+
"""Categorical-coloured as_points with a legend (matplotlib backend)."""
461+
self._as_points(sdata_blobs, "matplotlib", color=self._add_categorical_color(sdata_blobs)).pl.show()
462+
463+
def test_plot_labels_as_points_categorical_datashader(self, sdata_blobs: SpatialData):
464+
"""Same categorical render via datashader (color_source_vector + legend path)."""
465+
self._as_points(sdata_blobs, "datashader", color=self._add_categorical_color(sdata_blobs)).pl.show()
461466

462467

463468
def test_raises_when_table_does_not_annotate_element(sdata_blobs: SpatialData):

tests/pl/test_render_shapes.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,17 +1108,18 @@ def test_plot_can_color_shapes_by_gene_symbols(self, sdata_blobs: SpatialData):
11081108
"blobs_circles", color="GeneA", table_name="table", gene_symbols="gene_symbol"
11091109
).pl.show()
11101110

1111-
def test_plot_can_render_circles_as_points(self, sdata_blobs: SpatialData):
1112-
"""as_points draws one dot per shape at its centroid instead of the geometry."""
1113-
sdata_blobs.pl.render_shapes("blobs_circles", as_points=True, size=100).pl.show()
1111+
@staticmethod
1112+
def _as_points(sdata_blobs: SpatialData, method: str):
1113+
# identical params for both backends, so the matplotlib and datashader baselines are comparable
1114+
return sdata_blobs.pl.render_shapes("blobs_circles", as_points=True, method=method, size=600)
11141115

1115-
def test_plot_shapes_as_points_respects_size(self, sdata_blobs: SpatialData):
1116-
"""size sets the scatter marker area; larger size -> larger dots."""
1117-
sdata_blobs.pl.render_shapes("blobs_circles", as_points=True, size=600).pl.show()
1116+
def test_plot_shapes_as_points_matplotlib(self, sdata_blobs: SpatialData):
1117+
"""as_points draws one dot per shape at its centroid (matplotlib backend)."""
1118+
self._as_points(sdata_blobs, "matplotlib").pl.show()
11181119

11191120
def test_plot_shapes_as_points_datashader(self, sdata_blobs: SpatialData):
1120-
"""as_points with method='datashader' rasterizes the centroids instead of drawing markers."""
1121-
sdata_blobs.pl.render_shapes("blobs_circles", as_points=True, method="datashader", size=600).pl.show()
1121+
"""Same render via datashader; should look maximally similar to the matplotlib baseline."""
1122+
self._as_points(sdata_blobs, "datashader").pl.show()
11221123

11231124

11241125
def test_gene_symbols_auto_detect_table(sdata_blobs: SpatialData):

0 commit comments

Comments
 (0)