scverse / scverse/spatialdata-plot

render_labels raises IndexError when the table has rows for instances absent from the mask

オープン 初心者向け
#775 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
86
フォーク
21
平均マージ
14時間 50分
マージ済み PR(30日)
3

説明

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:2409spatialdata_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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された Python の再現コードを実行し、その後 spatialdata_plot/pl/render.py の 2409 行付近と spatialdata_plot/pl/_color.py の 791 行付近を調べてください。labels マスクと ColorSpec ベクトルがどのようにフィルタリングされるかを追跡します。render_labels(color=...) が labels に存在しないテーブル行を IndexError なしで処理し、一致する行については既存の動作を維持できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
numpy, pandas, python
領域
data-visualization
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
84/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。