scverse / scverse/spatialdata-plot

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

Offen Anfängerfreundlich
#775 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
86
Forks
21
Ø Merge
14 Std. 50 Min.
Gemergte PRs (30 T.)
3

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führen Sie die bereitgestellte Python-Reproduktion aus und untersuchen Sie anschließend spatialdata_plot/pl/render.py ungefähr bei Zeile 2409 sowie spatialdata_plot/pl/_color.py ungefähr bei Zeile 791. Verfolgen Sie, wie die labels-Maske und die ColorSpec-Vektoren gefiltert werden. Erledigt ist die Aufgabe, wenn render_labels(color=...) Tabellenzeilen, die in den labels fehlen, ohne IndexError verarbeitet und dabei das bestehende Verhalten für übereinstimmende Zeilen beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
numpy, pandas, python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Aktiv
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
84/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.