@@ -100,7 +100,7 @@ def _make_multi():
100100
101101 def test_plot_can_color_from_geodataframe (self , sdata_blobs : SpatialData ):
102102 blob = deepcopy (sdata_blobs )
103- blob ["table" ].obs ["region" ] = "blobs_polygons"
103+ blob ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_polygons" ] * blob [ "table" ]. n_obs )
104104 blob ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_polygons"
105105 blob .shapes ["blobs_polygons" ]["value" ] = [1 , 10 , 1 , 20 , 1 ]
106106 blob .pl .render_shapes (
@@ -114,7 +114,7 @@ def test_plot_can_scale_shapes(self, sdata_blobs: SpatialData):
114114 def test_plot_can_filter_with_groups (self , sdata_blobs : SpatialData ):
115115 _ , axs = plt .subplots (nrows = 1 , ncols = 2 , layout = "tight" )
116116
117- sdata_blobs ["table" ].obs ["region" ] = "blobs_polygons"
117+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_polygons" ] * sdata_blobs [ "table" ]. n_obs )
118118 sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_polygons"
119119 sdata_blobs .shapes ["blobs_polygons" ]["cluster" ] = "c1"
120120 sdata_blobs .shapes ["blobs_polygons" ].iloc [3 :5 , 1 ] = "c2"
@@ -128,7 +128,7 @@ def test_plot_can_filter_with_groups(self, sdata_blobs: SpatialData):
128128 )
129129
130130 def test_plot_coloring_with_palette (self , sdata_blobs : SpatialData ):
131- sdata_blobs ["table" ].obs ["region" ] = "blobs_polygons"
131+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_polygons" ] * sdata_blobs [ "table" ]. n_obs )
132132 sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_polygons"
133133 sdata_blobs .shapes ["blobs_polygons" ]["cluster" ] = "c1"
134134 sdata_blobs .shapes ["blobs_polygons" ].iloc [3 :5 , 1 ] = "c2"
@@ -141,21 +141,21 @@ def test_plot_coloring_with_palette(self, sdata_blobs: SpatialData):
141141 ).pl .show ()
142142
143143 def test_plot_colorbar_respects_input_limits (self , sdata_blobs : SpatialData ):
144- sdata_blobs ["table" ].obs ["region" ] = "blobs_polygons"
144+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_polygons" ] * sdata_blobs [ "table" ]. n_obs )
145145 sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_polygons"
146146 sdata_blobs .shapes ["blobs_polygons" ]["cluster" ] = [1 , 2 , 3 , 5 , 20 ]
147147 sdata_blobs .pl .render_shapes ("blobs_polygons" , color = "cluster" ).pl .show ()
148148
149149 def test_plot_colorbar_can_be_normalised (self , sdata_blobs : SpatialData ):
150- sdata_blobs ["table" ].obs ["region" ] = "blobs_polygons"
150+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_polygons" ] * sdata_blobs [ "table" ]. n_obs )
151151 sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_polygons"
152152 sdata_blobs .shapes ["blobs_polygons" ]["cluster" ] = [1 , 2 , 3 , 5 , 20 ]
153153 norm = Normalize (vmin = 0 , vmax = 5 , clip = True )
154154 sdata_blobs .pl .render_shapes ("blobs_polygons" , color = "cluster" , groups = ["c1" ], norm = norm ).pl .show ()
155155
156156 def test_plot_can_plot_shapes_after_spatial_query (self , sdata_blobs : SpatialData ):
157157 # subset to only shapes, should be unnecessary after rasterizeation of multiscale images is included
158- blob = SpatialData .from_elements_dict (
158+ blob = SpatialData .init_from_elements (
159159 {
160160 "blobs_circles" : sdata_blobs .shapes ["blobs_circles" ],
161161 "blobs_multipolygons" : sdata_blobs .shapes ["blobs_multipolygons" ],
@@ -168,7 +168,7 @@ def test_plot_can_plot_shapes_after_spatial_query(self, sdata_blobs: SpatialData
168168 cropped_blob .pl .render_shapes ().pl .show ()
169169
170170 def test_plot_can_plot_with_annotation_despite_random_shuffling (self , sdata_blobs : SpatialData ):
171- sdata_blobs ["table" ].obs ["region" ] = "blobs_circles"
171+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_circles" ] * sdata_blobs [ "table" ]. n_obs )
172172 new_table = sdata_blobs ["table" ][:5 ]
173173 new_table .uns ["spatialdata_attrs" ]["region" ] = "blobs_circles"
174174 new_table .obs ["instance_id" ] = np .array (range (5 ))
@@ -187,7 +187,7 @@ def test_plot_can_plot_with_annotation_despite_random_shuffling(self, sdata_blob
187187 sdata_blobs .pl .render_shapes ("blobs_circles" , color = "annotation" ).pl .show ()
188188
189189 def test_plot_can_plot_queried_with_annotation_despite_random_shuffling (self , sdata_blobs : SpatialData ):
190- sdata_blobs ["table" ].obs ["region" ] = "blobs_circles"
190+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_circles" ] * sdata_blobs [ "table" ]. n_obs )
191191 new_table = sdata_blobs ["table" ][:5 ].copy ()
192192 new_table .uns ["spatialdata_attrs" ]["region" ] = "blobs_circles"
193193 new_table .obs ["instance_id" ] = np .array (range (5 ))
@@ -215,11 +215,12 @@ def test_plot_can_plot_queried_with_annotation_despite_random_shuffling(self, sd
215215 sdata_cropped .pl .render_shapes ("blobs_circles" , color = "annotation" ).pl .show ()
216216
217217 def test_plot_can_color_two_shapes_elements_by_annotation (self , sdata_blobs : SpatialData ):
218- sdata_blobs ["table" ].obs ["region" ] = "blobs_circles"
218+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_circles" ] * sdata_blobs [ "table" ]. n_obs )
219219 new_table = sdata_blobs ["table" ][:10 ].copy ()
220220 new_table .uns ["spatialdata_attrs" ]["region" ] = ["blobs_circles" , "blobs_polygons" ]
221221 new_table .obs ["instance_id" ] = np .concatenate ((np .array (range (5 )), np .array (range (5 ))))
222222
223+ new_table .obs ["region" ] = new_table .obs ["region" ].cat .add_categories (["blobs_polygons" ])
223224 new_table .obs .loc [5 * [False ] + 5 * [True ], "region" ] = "blobs_polygons"
224225 new_table .obs ["annotation" ] = ["a" , "b" , "c" , "d" , "e" , "v" , "w" , "x" , "y" , "z" ]
225226 new_table .obs ["annotation" ] = new_table .obs ["annotation" ].astype ("category" )
@@ -231,11 +232,12 @@ def test_plot_can_color_two_shapes_elements_by_annotation(self, sdata_blobs: Spa
231232 ).pl .show ()
232233
233234 def test_plot_can_color_two_queried_shapes_elements_by_annotation (self , sdata_blobs : SpatialData ):
234- sdata_blobs ["table" ].obs ["region" ] = "blobs_circles"
235+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_circles" ] * sdata_blobs [ "table" ]. n_obs )
235236 new_table = sdata_blobs ["table" ][:10 ].copy ()
236237 new_table .uns ["spatialdata_attrs" ]["region" ] = ["blobs_circles" , "blobs_polygons" ]
237238 new_table .obs ["instance_id" ] = np .concatenate ((np .array (range (5 )), np .array (range (5 ))))
238239
240+ new_table .obs ["region" ] = new_table .obs ["region" ].cat .add_categories (["blobs_polygons" ])
239241 new_table .obs .loc [5 * [False ] + 5 * [True ], "region" ] = "blobs_polygons"
240242 new_table .obs ["annotation" ] = ["a" , "b" , "c" , "d" , "e" , "v" , "w" , "x" , "y" , "z" ]
241243 new_table .obs ["annotation" ] = new_table .obs ["annotation" ].astype ("category" )
@@ -360,7 +362,7 @@ def test_plot_can_color_by_category_with_cmap(self, sdata_blobs: SpatialData):
360362 sdata_blobs .pl .render_shapes (element = "blobs_polygons" , color = "category" , cmap = "cool" ).pl .show ()
361363
362364 def test_plot_datashader_can_color_by_value (self , sdata_blobs : SpatialData ):
363- sdata_blobs ["table" ].obs ["region" ] = "blobs_polygons"
365+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ([ "blobs_polygons" ] * sdata_blobs [ "table" ]. n_obs )
364366 sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_polygons"
365367 sdata_blobs .shapes ["blobs_polygons" ]["value" ] = [1 , 10 , 1 , 20 , 1 ]
366368 sdata_blobs .pl .render_shapes (element = "blobs_polygons" , color = "value" , method = "datashader" ).pl .show ()
@@ -370,13 +372,13 @@ def test_plot_datashader_can_color_by_identical_value(self, sdata_blobs: Spatial
370372 We test this, because datashader internally scales the values, so when all shapes have the same value,
371373 the scaling would lead to all of them being assigned an alpha of 0, so we wouldn't see anything
372374 """
373- sdata_blobs ["table" ].obs ["region" ] = ["blobs_polygons" ] * sdata_blobs ["table" ].n_obs
375+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ( ["blobs_polygons" ] * sdata_blobs ["table" ].n_obs )
374376 sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_polygons"
375377 sdata_blobs .shapes ["blobs_polygons" ]["value" ] = [1 , 1 , 1 , 1 , 1 ]
376378 sdata_blobs .pl .render_shapes (element = "blobs_polygons" , color = "value" , method = "datashader" ).pl .show ()
377379
378380 def test_plot_datashader_shades_with_linear_cmap (self , sdata_blobs : SpatialData ):
379- sdata_blobs ["table" ].obs ["region" ] = ["blobs_polygons" ] * sdata_blobs ["table" ].n_obs
381+ sdata_blobs ["table" ].obs ["region" ] = pd . Categorical ( ["blobs_polygons" ] * sdata_blobs ["table" ].n_obs )
380382 sdata_blobs ["table" ].uns ["spatialdata_attrs" ]["region" ] = "blobs_polygons"
381383 sdata_blobs .shapes ["blobs_polygons" ]["value" ] = [1 , 2 , 1 , 20 , 1 ]
382384 sdata_blobs .pl .render_shapes (element = "blobs_polygons" , color = "value" , method = "datashader" ).pl .show ()
@@ -410,7 +412,7 @@ def test_plot_datashader_can_render_with_rgba_colored_outline(self, sdata_blobs:
410412 def test_plot_can_set_clims_clip (self , sdata_blobs : SpatialData ):
411413 table_shapes = sdata_blobs ["table" ][:5 ].copy ()
412414 table_shapes .obs .instance_id = list (range (5 ))
413- table_shapes .obs ["region" ] = "blobs_circles"
415+ table_shapes .obs ["region" ] = pd . Categorical ([ "blobs_circles" ] * table_shapes . n_obs )
414416 table_shapes .obs ["dummy_gene_expression" ] = [i * 10 for i in range (5 )]
415417 table_shapes .uns ["spatialdata_attrs" ]["region" ] = "blobs_circles"
416418 sdata_blobs ["new_table" ] = table_shapes
@@ -489,7 +491,7 @@ def test_plot_datashader_can_transform_circles(self, sdata_blobs: SpatialData):
489491 def test_plot_can_do_non_matching_table (self , sdata_blobs : SpatialData ):
490492 table_shapes = sdata_blobs ["table" ][:3 ].copy ()
491493 table_shapes .obs .instance_id = list (range (3 ))
492- table_shapes .obs ["region" ] = "blobs_circles"
494+ table_shapes .obs ["region" ] = pd . Categorical ([ "blobs_circles" ] * table_shapes . n_obs )
493495 table_shapes .uns ["spatialdata_attrs" ]["region" ] = "blobs_circles"
494496 sdata_blobs ["new_table" ] = table_shapes
495497
0 commit comments