diff --git a/tests/_images/Shapes_can_plot_queried_with_annotation_despite_random_shuffling.png b/tests/_images/Shapes_can_plot_queried_with_annotation_despite_random_shuffling.png index 77d1ac75..ff728798 100644 Binary files a/tests/_images/Shapes_can_plot_queried_with_annotation_despite_random_shuffling.png and b/tests/_images/Shapes_can_plot_queried_with_annotation_despite_random_shuffling.png differ diff --git a/tests/pl/test_render_labels.py b/tests/pl/test_render_labels.py index 3e8160dc..d85cbe46 100644 --- a/tests/pl/test_render_labels.py +++ b/tests/pl/test_render_labels.py @@ -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) diff --git a/tests/pl/test_render_shapes.py b/tests/pl/test_render_shapes.py index ef67ec43..fcb1cde5 100644 --- a/tests/pl/test_render_shapes.py +++ b/tests/pl/test_render_shapes.py @@ -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): diff --git a/tests/pl/test_utils.py b/tests/pl/test_utils.py index edc4a2b9..21e9b823 100644 --- a/tests/pl/test_utils.py +++ b/tests/pl/test_utils.py @@ -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()