napari-spatialdata
napari-spatialdata copied to clipboard
NaN values colored if non-NaN values are only one
~When the table misses some instances or contains NaN values, colors are not mapped. Specifically if:~
- ~The table contains less
instancesthan the segmentation image inlabels~ - ~Or an observation column or X column contains NaN (because missing values have been filled up).~
Actual behavior:
If an obs/X column contains NaN and the non-NaN values are all the same, all labels are visualized with color, as if it ignores the fact that some are NaN.
Expected behavior:
It does not color values that are NaN.
Sorry, the initial observation actually is working correctly.
Except in one edge case:
- If a column's non-NaN values have a single value (all same or NaN), all labels receive the same color (yellow) although the NaN labels should be transparent.
This is specifically the case when n_obs == 2 (so rather a rare case, not a critical issue):
import anndata as ad
import numpy as np
import pandas as pd
import spatialdata as sd
from napari_spatialdata import Interactive
labels = sd.models.Labels2DModel.parse(np.array([[0, 1], [2, 0]]), dims=("y", "x"))
adata = ad.AnnData(obs=pd.DataFrame({"col1": [0.5, np.nan], "region": "region1", "instance_id": [1, 2]}))
table = sd.models.TableModel.parse(adata, region=["region1"], region_key="region", instance_key="instance_id")
sdata = sd.SpatialData(labels={"region1": labels}, table=table)
Interactive(sdata=sdata)
# Expected: obs "col1" is yellow for label 1 (top right) and transparent for label 2 (bottom left)
# Actual: label 1 and label 2 are yellow
Thanks for reporting! Will look into it