@@ -628,12 +628,20 @@ def test_unmatched_instance_ids_warn_and_write_nan(self, sdata_blobs: SpatialDat
628628 measure_obs (sdata_blobs , "blobs_labels" )
629629 assert np .isnan (table .obsm ["spatial" ]).all ()
630630
631- def test_float_dtype_labels_supported (self , sdata_blobs : SpatialData ) -> None :
632- # #3: a float-typed (but integer-valued) labels raster must not crash np.bincount.
633- arr = np .asarray (sdata_blobs ["blobs_labels" ].data ).astype (np .float32 )
634- sd = _labels_sdata (arr )
635- measure_obs (sd , "lab" , table_name = "t" )
636- assert np .isfinite (sd ["t" ].obsm ["spatial" ]).all ()
631+ def test_float_dtype_labels_handled_by_centroid_stats (self , sdata_blobs : SpatialData ) -> None :
632+ # #3: an integer-valued but float-typed raster must be cast to int, not crash np.bincount.
633+ # spatialdata now rejects float labels at the model boundary, so this can no longer reach
634+ # `measure_obs` through a SpatialData; the cast lives in `_stream_label_centroid_stats`, so
635+ # exercise it there: a float raster must yield exactly what its integer counterpart yields.
636+ from spatialdata_plot .pl .utils import _stream_label_centroid_stats
637+
638+ arr_int = np .asarray (sdata_blobs ["blobs_labels" ].data ).astype (np .int64 )
639+ lbl_i , x_i , y_i , area_i = _stream_label_centroid_stats (arr_int )
640+ lbl_f , x_f , y_f , area_f = _stream_label_centroid_stats (arr_int .astype (np .float32 ))
641+ np .testing .assert_array_equal (lbl_f , lbl_i )
642+ np .testing .assert_allclose (x_f , x_i )
643+ np .testing .assert_allclose (y_f , y_i )
644+ np .testing .assert_array_equal (area_f , area_i )
637645
638646 def test_existing_nonnumeric_column_raises_before_any_write (self , sdata_blobs : SpatialData ) -> None :
639647 # #4: a non-numeric collision raises BEFORE obsm is mutated (no half-written table).
0 commit comments