concatenate(): orphan tables crash the dict form; a generator input gives a misleading error

Aperta
#1,241 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Inizia da src/spatialdata/_core/concatenate.py, concentrandoti su concatenate e _fix_ensure_unique_element_names. Esegui il repro.py fornito con uv run per confermare entrambi i fallimenti. Il lavoro è completato quando la concatenazione in forma di dict conserva le tabelle orfane con il suffisso e l’input del generatore viene completato senza l’errore fuorviante di unicità.

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

Descrizione

bug 🚨 method: concatenate needs: triage

[!NOTE]
This whole message is AI-generated. The issue was automatically discovered and reported by an AI agent (Claude) during an autonomous bug hunt on the spatialdata code base. It has not been verified or triaged by a human yet; the needs: triage label is set so that a maintainer can confirm it. The reproduction script below was executed by the agent in an isolated environment (see Environment) and its output is pasted verbatim.

Summary

  1. A table without spatialdata_attrs (orphan table, supported elsewhere via include_orphan_tables) makes concatenate({...}) raise ValueError: No spatialdata_attrs key found in table.uns. 2. The signature accepts Iterable[SpatialData] but a generator is exhausted after the first pass, so the length check fails with KeyError: 'Images must have unique names across the SpatialData objects to concatenate...'.

Severity (agent's assessment): low

Where: src/spatialdata/_core/concatenate.py (_fix_ensure_unique_element_names calls get_table_keys(table) unconditionally; concatenate iterates sdatas several times)

Expected behaviour

Orphan tables are carried over (renamed with the suffix); generators are materialised with list(sdatas) or the type hint is Sequence.

Reproduction

Save as repro.py and run uv run repro.py (the PEP 723 header pins spatialdata to the commit the bug was found on; replace the URL fragment with @main to test the current main branch).

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "spatialdata @ git+https://github.com/scverse/spatialdata.git@ccf1ea048d054b6624214bf618008a9f9ae223e0",
# ]
# ///
"""concatenate(): orphan tables crash the dict form; a generator input gives a misleading error."""
import warnings
import numpy as np
from anndata import AnnData
from spatialdata import SpatialData, concatenate
from spatialdata.models import Image2DModel

warnings.simplefilter("ignore")


def mk():
    return SpatialData(images={"img": Image2DModel.parse(np.zeros((1, 4, 4), dtype=np.uint8))})


bug = False
s1, s2 = mk(), mk()
s1.tables["orphan"] = AnnData(X=np.zeros((2, 1)))  # table without spatialdata_attrs (allowed elsewhere)
try:
    m = concatenate({"a": s1, "b": s2})
    print("dict form with an orphan table: OK ->", list(m.tables))
except Exception as e:  # noqa: BLE001
    print("dict form with an orphan table:", type(e).__name__, str(e)[:100])
    bug = True
try:
    concatenate(s for s in [mk(), mk()])
    print("generator input: OK")
except Exception as e:  # noqa: BLE001
    print("generator input:", type(e).__name__, str(e)[:100])
    bug = True
print("VERDICT:", "BUG REPRODUCED" if bug else "NOT REPRODUCED")
Observed output
dict form with an orphan table: ValueError No spatialdata_attrs key found in table.uns, therefore, no table keys found. Please parse the table.
generator input: KeyError 'Images must have unique names across the SpatialData objects to concatenate. Please pass a `dict[st
VERDICT: BUG REPRODUCED

Possible fix direction (unverified)

See above.

Environment

uv run repro.py with the PEP 723 metadata in the script (fresh, isolated environment; spatialdata built from main @ ccf1ea0 (2026-08-28); Python 3.13, latest releases of the dependencies at run time: pandas 3.0, anndata 0.13, zarr 3.3, dask 2026.8, numpy 2.5, geopandas 1.1, shapely 2.1). macOS (arm64). Also reproduced in a second environment with pandas 2.3.3 / anndata 0.12.11 / numpy 2.4.4 / zarr 3.2.1.


Automatically generated; discovered by an AI agent (Claude) and not yet reviewed by a human.

Lingua principale
Python
Stelle
394
Fork
95
Merge medio
3g 9h
PR unite (30g)
5

Guida per i contributori

Apri la guida per i contributori

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/spatialdata

Tutte le issue di scverse/spatialdata

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.