Skip to content

Commit e33db15

Browse files
Merge pull request #283 from melonora/transform_copy
Tranformation copy
2 parents 2e55e83 + 6e8a4f5 commit e33db15

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/spatialdata/models/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def parse(
124124
:class:`spatial_image.SpatialImage` or
125125
:class:`multiscale_spatial_image.MultiscaleSpatialImage`.
126126
"""
127+
if transformations:
128+
transformations = transformations.copy()
127129
if "name" in kwargs:
128130
raise ValueError("The `name` argument is not (yet) supported for raster data.")
129131
# if dims is specified inside the data, get the value of dims from the data

tests/core/operations/test_spatialdata_operations.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
from spatial_image import SpatialImage
1212
from spatialdata import SpatialData
1313
from spatialdata._core.concatenate import _concatenate_tables, concatenate
14+
from spatialdata.datasets import blobs
1415
from spatialdata.models import (
1516
Image2DModel,
1617
Labels2DModel,
1718
PointsModel,
1819
ShapesModel,
1920
TableModel,
2021
)
21-
from spatialdata.transformations.operations import set_transformation
22+
from spatialdata.transformations.operations import get_transformation, set_transformation
2223
from spatialdata.transformations.transformations import Identity, Scale
2324

2425
from tests.conftest import _get_table
@@ -239,3 +240,18 @@ def test_set_item(full_sdata):
239240
# trying to overwrite the file used for backing (only for images, labels and points)
240241
with pytest.raises(ValueError):
241242
full_sdata[name] = full_sdata[name]
243+
244+
245+
def test_no_shared_transformations():
246+
"""Test transformation dictionary copy for transformations not to be shared."""
247+
sdata = blobs()
248+
element_name = "blobs_image"
249+
test_space = "test"
250+
set_transformation(sdata.images[element_name], Identity(), to_coordinate_system=test_space)
251+
252+
gen = sdata._gen_elements()
253+
for _, name, obj in gen:
254+
if name != element_name:
255+
assert test_space not in get_transformation(obj, get_all=True)
256+
else:
257+
assert test_space in get_transformation(obj, get_all=True)

0 commit comments

Comments
 (0)