Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Multi-column `groupby` crashes on non-string observations in dotplot/matrixplot/heatmap

Aperta Adatta ai principianti
#4,384 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@barlowa124 ci sta già lavorando.

Dal 28/9/2026.

  • #4385 di @barlowa124 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
numpy, pandas, python

Direzione di ricerca

Inizia in plotting/legacy/_anndata.py, in _prepare_dataframe, quindi segui il modo in cui BasePlot.init lo invoca. Riproduci l’esempio minimo di dotplot e controlla i corrispondenti percorsi di matrixplot, stacked_violin, tracksplot e heatmap; il lavoro è completato quando multi-column groupby accetta osservazioni numeriche e categoriali senza gli errori segnalati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Please make sure these conditions are met
  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.
What happened?

Passing a list of groupby keys fails with TypeError when any key is a non-string observation, whether an integer categorical or a plain numeric column. A single-key groupby handles the same column fine (is_numeric_dtype → pd.cut, or astype("category")), so this only affects the multi-key path.

Reproduces in sc.pl.dotplot, sc.pl.matrixplot, sc.pl.stacked_violin, sc.pl.tracksplot, and sc.pl.heatmap: all go through _prepare_dataframe in plotting/legacy/_anndata.py (BasePlot subclasses call it from BasePlot.__init__).

Two problems in the multi-key branch:

  1. obs_tidy[groupby].apply("_".join, axis=1) requires every joined value to be str. Integer categories or numeric columns raise TypeError: sequence item 1: expected str instance, int found.
  2. obs_tidy[g].cat.categories assumes each groupby column is categorical. A plain numeric column would raise AttributeError at this line if it got past the join.
Minimal code sample
import numpy as np
import pandas as pd
import scanpy as sc

adata = sc.datasets.pbmc68k_reduced()
adata.obs["num_grp"] = pd.Categorical(np.repeat([1, 2], adata.n_obs // 2))

# single key works
sc.pl.dotplot(adata, var_names=adata.var_names[:4], groupby="num_grp", show=False)

# multi key raises TypeError
sc.pl.dotplot(adata, var_names=adata.var_names[:4], groupby=["bulk_labels", "num_grp"], show=False)
Error output
TypeError: sequence item 1: expected str instance, int found

I have a fix ready: convert joined values with astype(str), take levels from .cat.categories only for categorical columns (np.unique otherwise), and fall back to end-ordering for joined labels missing from the order map (NaN-containing combinations). Happy to open a PR.

Lingua principale
Python
Stelle
2.6k
Fork
801
Merge medio
1g 3h
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scverse/scanpy

Tutte le issue di scverse/scanpy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.