render_labels raises IndexError when the table has rows for instances absent from the mask
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- numpy, pandas, python
- Domain
- data-visualization
Research direction
Run the provided Python reproduction, then inspect spatialdata_plot/pl/render.py around line 2409 and spatialdata_plot/pl/_color.py around line 791. Trace how the labels mask and ColorSpec vectors are filtered; done means render_labels(color=...) handles table rows absent from the labels without IndexError while retaining the existing behavior for matching rows.
Written by the indexing model from the issue text.
Description
A table may annotate instances that no longer exist in the labels element — e.g. objects lost when segmentation is regenerated, or a table read from an upstream pipeline. render_labels(color=...) then fails instead of treating them as missing.
import anndata as ad, numpy as np, pandas as pd, spatialdata as sd, spatialdata_plot # noqa
from spatialdata.models import Labels2DModel, TableModel
labels = np.zeros((16, 16), np.uint32)
labels[2:6, 2:6] = 1
labels[8:12, 8:12] = 2
obs = pd.DataFrame({"instance_id": [1, 2, 3], "region": pd.Categorical(["labels"] * 3)})
obs.index = obs.index.astype(str)
table = TableModel.parse(
ad.AnnData(np.zeros((3, 1), np.float32), obs=obs),
region="labels", region_key="region", instance_key="instance_id",
)
table.obs["value"] = [1.0, 2.0, 3.0]
sdata = sd.SpatialData(
labels={"labels": Labels2DModel.parse(labels, dims=("y", "x"))},
tables={"table": table},
)
sdata.pl.render_labels("labels", color="value", table_name="table").pl.show()
IndexError: boolean index did not match indexed array along axis 0;
size of axis is 2 but size of corresponding boolean axis is 3
The mask is computed from the instance ids present in the labels, but ColorSpec.source_vector/color_vector still have one entry per table row, so ColorSpec.filter indexes a length-2 array with a length-3 mask:
spatialdata_plot/pl/render.py:2409 → spatialdata_plot/pl/_color.py:791
Rendering without color works, as does dropping the unmatched rows from the table.
spatialdata 0.8.0, spatialdata-plot 0.4.2, Python 3.14.
- Dominant language
- Python
- Stars
- 86
- Forks
- 21
- Avg merge
- 14h 50m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from scverse/spatialdata-plot
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
scverse/spatialdata-plot#777 ·
-
`pl.show()` leading to `ValueError` due to mismatch between number of axes and number of panels Open
Difficulty 3/5 1-2 days Newbie friendliness 45/100
scverse/spatialdata-plot#749 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
scverse/spatialdata-plot#747 ·
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
scverse/spatialdata-plot#677 ·
-
enhancement priority: medium utils :wrench:
Difficulty 3/5 1-2 days Newbie friendliness 68/100
scverse/spatialdata-plot#632 ·
All issues in scverse/spatialdata-plot
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100