concatenate({'a': sdata1, 'b': sdata2}) renames the coordinate systems of the input objects in place
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 pure combine operation has a hidden side effect on its inputs: subsequent queries/plots on sdata1 with target_coordinate_system="global" fail or silently return nothing.
Severity (agent's assessment): medium/high — after the call sdata1 maps to global-a instead of global; if backed, write_transformations() persists the renamed systems
Where: src/spatialdata/_core/concatenate.py::_fix_ensure_unique_element_names (remove_transformation(el, remove_all=True) / set_transformation(el, t, new_cs) on the original element objects; only tables are optionally copied via modify_tables_inplace)
Expected behaviour
Inputs unchanged (or the in-place behaviour documented and opt-in, as for tables).
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({'a': sdata1, 'b': sdata2}) renames the coordinate systems of the INPUT objects in place."""
import warnings
import numpy as np
from spatialdata import SpatialData, concatenate
from spatialdata.models import Image2DModel
from spatialdata.transformations import get_transformation
warnings.simplefilter("ignore")
s1 = SpatialData(images={"img": Image2DModel.parse(np.zeros((1, 4, 4), dtype=np.uint8))})
s2 = SpatialData(images={"img": Image2DModel.parse(np.zeros((1, 4, 4), dtype=np.uint8))})
print("before: s1 coordinate systems:", s1.coordinate_systems)
merged = concatenate({"a": s1, "b": s2})
print("after : s1 coordinate systems:", s1.coordinate_systems, "| s1['img'] transformations:", list(get_transformation(s1["img"], get_all=True)))
print("merged coordinate systems:", sorted(merged.coordinate_systems))
bug = s1.coordinate_systems != ["global"]
print("VERDICT:", "BUG REPRODUCED (input mutated)" if bug else "NOT REPRODUCED")
Observed output
before: s1 coordinate systems: ['global']
after : s1 coordinate systems: ['global-a'] | s1['img'] transformations: ['global-a']
merged coordinate systems: ['global-a', 'global-b']
VERDICT: BUG REPRODUCED (input mutated)
Possible fix direction (unverified)
Shallow-copy each element before rewriting its transformations (xarray/geopandas .copy(); dask frame .copy() plus a copy of the transform dict; for DataTree copy the tree and per-scale attrs), mirroring modify_tables_inplace=False.
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.
Possibly related issues
#998
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 with repro.py and src/spatialdata/_core/concatenate.py::_fix_ensure_unique_element_names, then trace how transformations are removed and assigned to input elements. Reproduce the mutation with uv run repro.py and ensure concatenate leaves sdata1 and sdata2 unchanged while the merged object still has unique coordinate systems.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100