@@ -1076,9 +1076,7 @@ def test_gene_symbols_missing_column_raises_auto_detect(sdata_blobs: SpatialData
10761076 sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_circles"
10771077 sdata_blobs ["table" ].var ["gene_symbol" ] = ["GeneA" , "GeneB" , "GeneC" ]
10781078 with pytest .raises (KeyError , match = "`gene_symbols=`" ):
1079- sdata_blobs .pl .render_shapes (
1080- "blobs_circles" , color = "GeneA" , gene_symbols = "WRONGCOL"
1081- ).pl .show ()
1079+ sdata_blobs .pl .render_shapes ("blobs_circles" , color = "GeneA" , gene_symbols = "WRONGCOL" ).pl .show ()
10821080
10831081
10841082def test_groups_na_color_none_no_match_shapes (sdata_blobs : SpatialData ):
@@ -1351,6 +1349,35 @@ def test_render_shapes_color_with_conflicting_index_name():
13511349 sdata .pl .render_shapes ("shapes" , color = "cell_type" , table_name = "table" ).pl .show ()
13521350
13531351
1352+ def test_render_shapes_disjoint_instance_ids_clear_error ():
1353+ # regression test for #603: disjoint instance_id values must raise a clear ValueError
1354+ shapes = ShapesModel .parse (
1355+ gpd .GeoDataFrame ({"geometry" : [Point (5 , 5 ), Point (15 , 5 ), Point (25 , 5 )], "radius" : [2.0 ] * 3 })
1356+ )
1357+ obs = pd .DataFrame (
1358+ {
1359+ "instance_id" : [99 , 100 , 101 ], # element has IDs 0, 1, 2 (no overlap)
1360+ "region" : pd .Categorical (["s" ] * 3 ),
1361+ "cat" : pd .Categorical (["A" , "B" , "C" ]),
1362+ }
1363+ )
1364+ obs .index = obs .index .astype (str )
1365+ table = TableModel .parse (
1366+ AnnData (X = np .zeros ((3 , 1 )), obs = obs ),
1367+ region = ["s" ],
1368+ region_key = "region" ,
1369+ instance_key = "instance_id" ,
1370+ )
1371+ sdata = SpatialData (shapes = {"s" : shapes }, tables = {"t" : table })
1372+
1373+ fig , ax = plt .subplots ()
1374+ try :
1375+ with pytest .raises (ValueError , match = r"No instance IDs overlap.*table 't'.*element 's'" ):
1376+ sdata .pl .render_shapes ("s" , color = "cat" , table_name = "t" ).pl .show (ax = ax )
1377+ finally :
1378+ plt .close (fig )
1379+
1380+
13541381def test_datashader_colorbar_range_matches_data (sdata_blobs : SpatialData ):
13551382 """Datashader colorbar range must not exceed the actual data range for shapes.
13561383
0 commit comments