render_labels raises IndexError when the table has rows for instances absent from the mask
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 84/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- numpy, pandas, python
研究方向
執行提供的 Python 重現程式,然後檢查 spatialdata_plot/pl/render.py 約第 2409 行以及 spatialdata_plot/pl/_color.py 約第 791 行。追蹤 labels 遮罩和 ColorSpec 向量如何被篩選;當 render_labels(color=...) 能在不產生 IndexError 的情況下處理表格中不存在於 labels 的列,同時保留相符列的既有行為時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Python
- 星號
- 86
- 分支
- 21
- 平均合併
- 14 小時 50 分鐘
- 30 天內合併 PR
- 3
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
scverse/spatialdata-plot 的其他 Issue
-
bug
難度 3/5 1-2 天 新手友好度 68/100
scverse/spatialdata-plot#777 ·
-
難度 3/5 1-2 天 新手友好度 45/100
scverse/spatialdata-plot#749 · 1 則留言 ·
-
難度 4/5 3-5 天 新手友好度 48/100
scverse/spatialdata-plot#747 ·
-
難度 5/5 一週以上 新手友好度 45/100
scverse/spatialdata-plot#677 ·
-
enhancement priority: medium utils :wrench:
難度 3/5 1-2 天 新手友好度 68/100
scverse/spatialdata-plot#632 ·
查看 scverse/spatialdata-plot 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 82/100
-
難度 2/5 1-3 小時 新手友好度 78/100
-
enhancement
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 74/100