Skip to content

Commit d52fbf2

Browse files
committed
fixed tests
1 parent 3e793f7 commit d52fbf2

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

src/spatialdata_plot/pl/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,10 @@ def _as_rgba_array(x: Any) -> np.ndarray:
425425
fill_c[is_num] = cmap(used_norm(num[is_num]))
426426

427427
# non-numeric entries as explicit colors
428-
if (~is_num).any():
429-
fill_c[~is_num] = ColorConverter().to_rgba_array(c_series[~is_num].tolist())
428+
# treat missing values as na_color, and only convert valid color-like entries
429+
non_numeric_mask = (~is_num) & c_series.notna()
430+
if non_numeric_mask.any():
431+
fill_c[non_numeric_mask] = ColorConverter().to_rgba_array(c_series[non_numeric_mask].tolist())
430432

431433
# Case C: single color or list of color-like specs (strings or tuples)
432434
else:
0 Bytes
Loading
20.5 KB
Loading

tests/pl/test_render_shapes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ def test_plot_can_annotate_shapes_with_table_layer(self, sdata_blobs: SpatialDat
619619

620620
def test_plot_respects_custom_colors_from_uns(self, sdata_blobs: SpatialData):
621621
shapes_name = "blobs_polygons"
622+
# Ensure that the table annotations point to the shapes element
623+
sdata_blobs["table"].obs["region"] = pd.Categorical([shapes_name] * sdata_blobs["table"].n_obs)
622624
sdata_blobs.set_table_annotates_spatialelement("table", region=shapes_name)
623625

624626
categories = get_standard_RNG().choice(["a", "b", "c"], size=sdata_blobs["table"].n_obs)
@@ -631,6 +633,8 @@ def test_plot_respects_custom_colors_from_uns(self, sdata_blobs: SpatialData):
631633

632634
def test_plot_respects_custom_colors_from_uns_dict(self, sdata_blobs: SpatialData):
633635
shapes_name = "blobs_polygons"
636+
# Ensure that the table annotations point to the shapes element
637+
sdata_blobs["table"].obs["region"] = pd.Categorical([shapes_name] * sdata_blobs["table"].n_obs)
634638
sdata_blobs.set_table_annotates_spatialelement("table", region=shapes_name)
635639

636640
categories = get_standard_RNG().choice(["a", "b", "c"], size=sdata_blobs["table"].n_obs)

0 commit comments

Comments
 (0)