Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions tests/pl/test_render_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,16 +712,17 @@ def test_render_labels_lognorm_with_zeros_does_not_crash(sdata_blobs: SpatialDat

@pytest.mark.parametrize("dtype", [np.float16, np.float32, np.float64])
def test_render_labels_rejects_float_dtype(dtype):
# Regression test for #606: float-dtype labels must raise a clear
# ValueError naming the element and dtype, not a cryptic skimage TypeError.
# Regression test for #606: float-dtype labels must raise a clear "integer dtype" ValueError,
# not a cryptic skimage TypeError. spatialdata>=0.8 enforces this at model validation
# (parse/construction); on older spatialdata our render-time guard is the safety net. The
# supported stack must reject them at one of those layers either way.
arr = np.zeros((20, 20), dtype=dtype)
arr[3:8, 3:8] = 1
arr[12:17, 12:17] = 2
sdata = SpatialData(labels={"lbl": Labels2DModel.parse(arr, dims=["y", "x"])})

fig, ax = plt.subplots()
try:
with pytest.raises(ValueError, match=r"Label element 'lbl'.*integer dtype"):
with pytest.raises(ValueError, match="integer dtype"):
sdata = SpatialData(labels={"lbl": Labels2DModel.parse(arr, dims=["y", "x"])})
sdata.pl.render_labels("lbl").pl.show(ax=ax)
finally:
plt.close(fig)
Expand Down
6 changes: 6 additions & 0 deletions tests/pl/test_render_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,12 @@ def test_plot_can_plot_queried_with_annotation_despite_random_shuffling(self, sd
filter_table=True,
)

# spatialdata's query returns the cropped geometries in a version-dependent order (0.8's
# relational-query refactor reorders them), which flips the draw/z-order of the overlapping
# circles and so the rendered image. Sort by index for a deterministic draw order, so the
# baseline matches across the supported spatialdata range.
sdata_cropped["blobs_circles"] = sdata_cropped["blobs_circles"].sort_index()

sdata_cropped.pl.render_shapes("blobs_circles", color="annotation").pl.show()

def test_plot_can_color_two_shapes_elements_by_annotation(self, sdata_blobs: SpatialData):
Expand Down
9 changes: 7 additions & 2 deletions tests/pl/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,14 @@ def test_unmatched_instance_ids_warn_and_write_nan(self, sdata_blobs: SpatialDat
assert np.isnan(table.obsm["spatial"]).all()

def test_float_dtype_labels_supported(self, sdata_blobs: SpatialData) -> None:
# #3: a float-typed (but integer-valued) labels raster must not crash np.bincount.
# #3: on spatialdata<0.8 (which accepts float-dtype labels), a float-typed but
# integer-valued labels raster must not crash np.bincount. spatialdata>=0.8 rejects
# float labels at construction, so the scenario is unreachable and the test skips there.
arr = np.asarray(sdata_blobs["blobs_labels"].data).astype(np.float32)
sd = _labels_sdata(arr)
try:
sd = _labels_sdata(arr)
except ValueError:
pytest.skip("spatialdata>=0.8 rejects float-dtype labels at construction")
measure_obs(sd, "lab", table_name="t")
assert np.isfinite(sd["t"].obsm["spatial"]).all()

Expand Down
Loading