Skip to content

Commit

Permalink
Merge pull request #283 from melonora/transform_copy
Browse files Browse the repository at this point in the history
Tranformation copy
  • Loading branch information
LucaMarconato authored Jun 3, 2023
2 parents 2e55e83 + 6e8a4f5 commit e33db15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/spatialdata/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def parse(
:class:`spatial_image.SpatialImage` or
:class:`multiscale_spatial_image.MultiscaleSpatialImage`.
"""
if transformations:
transformations = transformations.copy()
if "name" in kwargs:
raise ValueError("The `name` argument is not (yet) supported for raster data.")
# if dims is specified inside the data, get the value of dims from the data
Expand Down
18 changes: 17 additions & 1 deletion tests/core/operations/test_spatialdata_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
from spatial_image import SpatialImage
from spatialdata import SpatialData
from spatialdata._core.concatenate import _concatenate_tables, concatenate
from spatialdata.datasets import blobs
from spatialdata.models import (
Image2DModel,
Labels2DModel,
PointsModel,
ShapesModel,
TableModel,
)
from spatialdata.transformations.operations import set_transformation
from spatialdata.transformations.operations import get_transformation, set_transformation
from spatialdata.transformations.transformations import Identity, Scale

from tests.conftest import _get_table
Expand Down Expand Up @@ -239,3 +240,18 @@ def test_set_item(full_sdata):
# trying to overwrite the file used for backing (only for images, labels and points)
with pytest.raises(ValueError):
full_sdata[name] = full_sdata[name]


def test_no_shared_transformations():
"""Test transformation dictionary copy for transformations not to be shared."""
sdata = blobs()
element_name = "blobs_image"
test_space = "test"
set_transformation(sdata.images[element_name], Identity(), to_coordinate_system=test_space)

gen = sdata._gen_elements()
for _, name, obj in gen:
if name != element_name:
assert test_space not in get_transformation(obj, get_all=True)
else:
assert test_space in get_transformation(obj, get_all=True)

0 comments on commit e33db15

Please sign in to comment.