Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added tests/_images/Labels_label_categorical_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 26 additions & 1 deletion tests/pl/test_render_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import pandas as pd
import pytest
import scanpy as sc
from anndata import AnnData
from spatial_image import to_spatial_image
from spatialdata import SpatialData, deepcopy
from spatialdata import SpatialData, deepcopy, get_element_instances
from spatialdata.models import TableModel

import spatialdata_plot # noqa: F401
Expand Down Expand Up @@ -208,3 +209,27 @@ def test_plot_subset_categorical_label_maintains_order_when_palette_overwrite(se
sdata_blobs.pl.render_labels(
"blobs_labels", color="which_max", groups=["channel_0_sum"], palette="red"
).pl.show(ax=axs[1])

def test_plot_label_categorical_color(self, sdata_blobs: SpatialData):
self._make_tablemodel_with_categorical_labels(sdata_blobs, labels_name="blobs_labels")
sdata_blobs.pl.render_labels("blobs_labels", color="category").pl.show()

def _make_tablemodel_with_categorical_labels(self, sdata_blobs, labels_name: str):
instances = get_element_instances(sdata_blobs[labels_name])
n_obs = len(instances)
adata = AnnData(
RNG.normal(size=(n_obs, 10)),
obs=pd.DataFrame(RNG.normal(size=(n_obs, 3)), columns=["a", "b", "c"]),
)
adata.obs["instance_id"] = instances.values
adata.obs["category"] = RNG.choice(["a", "b", "c"], size=adata.n_obs)
adata.obs["category"][:3] = ["a", "b", "c"]
adata.obs["region"] = labels_name
table = TableModel.parse(
adata=adata,
region_key="region",
instance_key="instance_id",
region=labels_name,
)
sdata_blobs["other_table"] = table
sdata_blobs["other_table"].obs["category"] = sdata_blobs["other_table"].obs["category"].astype("category")
Loading