concatenate(): orphan tables crash the dict form; a generator input gives a misleading error
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 394
- Forks
- 95
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 7
Description
[!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 thespatialdatacode base. It has not been verified or triaged by a human yet; theneeds: triagelabel 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
- A table without
spatialdata_attrs(orphan table, supported elsewhere viainclude_orphan_tables) makesconcatenate({...})raiseValueError: No spatialdata_attrs key found in table.uns. 2. The signature acceptsIterable[SpatialData]but a generator is exhausted after the first pass, so the length check fails withKeyError: '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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/spatialdata/_core/concatenate.py, focusing on concatenate and _fix_ensure_unique_element_names. Run the supplied repro.py with uv run to confirm both failures. Done means dict-form concatenation carries orphan tables with the suffix and generator input completes without the misleading uniqueness error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design, data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100