Repository: scverse/spatialdata

Issue:
Potential api change transform_element_to_coordinate_system
For the method `SpatialData.transform_element_to_coordinate_system(element, target_coordinate_system, maintain_positioning)`, element here is expected to be the element and not the element name. Not certain whether there are any objections to allow for the element name to be passed as an argument.

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/scverse/spatialdata/pull/611?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scverse) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 91.93%. Comparing base [(`03cde00`)](https://app.codecov.io/gh/scverse/spatialdata/commit/03cde0030e27acd0f65fe0e9c035507b54cb1ec9?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scverse) to head [(`4b1da0b`)](https://app.codecov.io/gh/scverse/spatialdata/commit/4b1da0bc748551a0bbc644632ca91ad4ced11368?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scverse).

> :exclamation: **Current head 4b1da0b differs from pull request most recent head 1af9df2**
> 
> Please [upload](https://docs.codecov.com/docs/codecov-uploader) reports for the commit 1af9df2 to get more accurate results.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #611   +/-   ##
=======================================
  Coverage   91.92%   91.93%           
=======================================
  Files          44       44           
  Lines        6654     6659    +5     
=======================================
+ Hits         6117     6122    +5     
  Misses        537      537           
```

| [Files](https://app.codecov.io/gh/scverse/spatialdata/pull/611?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scverse) | Coverage Δ | |
|---|---|---|
| [src/spatialdata/\_core/spatialdata.py](https://app.codecov.io/gh/scverse/spatialdata/pull/611?src=pr&el=tree&filepath=src%2Fspatialdata%2F_core%2Fspatialdata.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scverse#diff-c3JjL3NwYXRpYWxkYXRhL19jb3JlL3NwYXRpYWxkYXRhLnB5) | `90.96% <100.00%> (+0.05%)` | :arrow_up: |

</details>

Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index bf159bb..9dd31a5 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -17,17 +17,17 @@ repos:
       hooks:
           - id: prettier
     - repo: https://github.com/asottile/blacken-docs
-      rev: 1.16.0
+      rev: 1.18.0
       hooks:
           - id: blacken-docs
     - repo: https://github.com/pre-commit/mirrors-mypy
-      rev: v1.10.0
+      rev: v1.10.1
       hooks:
           - id: mypy
             additional_dependencies: [numpy, types-requests]
             exclude: tests/|docs/
     - repo: https://github.com/astral-sh/ruff-pre-commit
-      rev: v0.4.10
+      rev: v0.5.0
       hooks:
           - id: ruff
             args: [--fix, --exit-non-zero-on-fix]
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d1c1e7..362f33c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,12 +8,15 @@ and this project adheres to [Semantic Versioning][].
 [keep a changelog]: https://keepachangelog.com/en/1.0.0/
 [semantic versioning]: https://semver.org/spec/v2.0.0.html
 
-## [0.1.3] - 2024-xx-xx
+## [0.2.1] - 2024-xx-xx
+
+## [0.2.0] - 2024-07-03
 
 ### Changed
 
 -   Using `DataArray` directly instead of the subclass `SpatialImage` (removed install constraint for the `spatial_image` package) #587
 -   Using `DataTree` directly instead of the subclass `MultiscaleSpatialImage` (removed install constraint for the `multiscale_spatial_image` package) #587
+-   Changed `element`parameter (deprecation in v0.3.0) of `transform_element_to_coordinate_system` to a string `element_name` #611
 
 ### Major
 
diff --git a/pyproject.toml b/pyproject.toml
index 998cebb..354cce5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -12,7 +12,7 @@ authors = [
 maintainers = [
     {name = "scverse", email = "giov.pll@gmail.com"},
 ]
-urls.Documentation = "spatialdata.scverse.org/en/latest"
+urls.Documentation = "https://spatialdata.scverse.org/en/latest"
 urls.Source = "https://github.com/scverse/spatialdata.git"
 urls.Home-page = "https://github.com/scverse/spatialdata.git"
 requires-python = ">=3.9"
diff --git a/src/spatialdata/_core/spatialdata.py b/src/spatialdata/_core/spatialdata.py
index 456bcba..8bd7422 100644
--- a/src/spatialdata/_core/spatialdata.py
+++ b/src/spatialdata/_core/spatialdata.py
@@ -199,7 +199,7 @@ class SpatialData:
                     else:
                         dtype = element.index.dtype
                     if dtype != table.obs[instance_key].dtype and (
-                        dtype == str or table.obs[instance_key].dtype == str
+                        dtype is str or table.obs[instance_key].dtype is str
                     ):
                         raise TypeError(
                             f"Table instance_key column ({instance_key}) has a dtype "
@@ -801,16 +801,17 @@ class SpatialData:
             # set the new transformations
             set_transformation(element=element, transformation=new_transformations, set_all=True)
 
+    @_deprecation_alias(element="element_name", version="0.3.0")
     def transform_element_to_coordinate_system(
-        self, element: SpatialElement, target_coordinate_system: str, maintain_positioning: bool = False
+        self, element_name: str, target_coordinate_system: str, maintain_positioning: bool = False
     ) -> SpatialElement:
         """
         Transform an element to a given coordinate system.
 
         Parameters
         ----------
-        element
-            The element to transform.
+        element_name:
+            The name of the element to transform.
         target_coordinate_system
             The target coordinate system.
         maintain_positioning
@@ -831,6 +832,18 @@ class SpatialData:
             set_transformation,
         )
 
+        # TODO remove after deprecation
+        if not isinstance(element_name, str):
+            warnings.warn(
+                "Passing a SpatialElement is as element will be deprecated in SpatialData v0.3.0. Pass"
+                "element_name as string to silence this warning.",
+                DeprecationWarning,
+                stacklevel=2,
+            )
+            element = element_name
+        else:
+            element = self.get(element_name)
+
         t = get_transformation_between_coordinate_systems(self, element, target_coordinate_system)
         if maintain_positioning:
             transformed = transform(element, transformation=t, maintain_positioning=maintain_positioning)
diff --git a/src/spatialdata/datasets.py b/src/spatialdata/datasets.py
index eb3e4c0..11c2c79 100644
--- a/src/spatialdata/datasets.py
+++ b/src/spatialdata/datasets.py
@@ -184,7 +184,7 @@ class BlobsDataset:
         masks = []
         for i in range(n_channels):
             mask = self._generate_blobs(length=length, seed=i)
-            mask = (mask - mask.min()) / mask.ptp()
+            mask = (mask - mask.min()) / mask.ptp()  # type: ignore[attr-defined]
             masks.append(mask)
 
         x = np.stack(masks, axis=0)
diff --git a/src/spatialdata/models/models.py b/src/spatialdata/models/models.py
index bdf1c9e..4b07760 100644
--- a/src/spatialdata/models/models.py
+++ b/src/spatialdata/models/models.py
@@ -854,7 +854,7 @@ class TableModel:
         if attr[self.INSTANCE_KEY] not in data.obs:
             raise ValueError(f"`{attr[self.INSTANCE_KEY]}` not found in `adata.obs`. Please create the column.")
         if (dtype := data.obs[attr[self.INSTANCE_KEY]].dtype) not in [int, np.int16, np.int32, np.int64, "O"] or (
-            dtype == "O" and (val_dtype := type(data.obs[attr[self.INSTANCE_KEY]].iloc[0])) != str
+            dtype == "O" and (val_dtype := type(data.obs[attr[self.INSTANCE_KEY]].iloc[0])) is not str
         ):
             dtype = dtype if dtype != "O" else val_dtype
             raise TypeError(
diff --git a/src/spatialdata/transformations/ngff/ngff_transformations.py b/src/spatialdata/transformations/ngff/ngff_transformations.py
index d95f887..32266f7 100644
--- a/src/spatialdata/transformations/ngff/ngff_transformations.py
+++ b/src/spatialdata/transformations/ngff/ngff_transformations.py
@@ -916,7 +916,7 @@ class NgffSequence(NgffBaseTransformation):
         # complexity in these NgffSequence class will be rewarded in the long term.
         input_axes, output_axes = self._get_and_validate_axes()
         self._validate_transform_points_shapes(len(input_axes), points.shape)
-        assert type(self.input_coordinate_system) == NgffCoordinateSystem
+        assert type(self.input_coordinate_system) is NgffCoordinateSystem
         latest_output_cs: NgffCoordinateSystem = self.input_coordinate_system
         for t in self.transformations:
             latest_output_cs, input_cs, output_cs = NgffSequence._inferring_cs_pre_action(t, latest_output_cs)
@@ -934,7 +934,7 @@ class NgffSequence(NgffBaseTransformation):
         # method, applies also here
         input_axes, output_axes = self._get_and_validate_axes()
         composed = np.eye(len(input_axes) + 1)
-        assert type(self.input_coordinate_system) == NgffCoordinateSystem
+        assert type(self.input_coordinate_system) is NgffCoordinateSystem
         latest_output_cs: NgffCoordinateSystem = self.input_coordinate_system
         for t in self.transformations:
             latest_output_cs, input_cs, output_cs = NgffSequence._inferring_cs_pre_action(t, latest_output_cs)


Test patch:
diff --git a/tests/core/operations/test_transform.py b/tests/core/operations/test_transform.py
index 9b57933..fc5d33f 100644
--- a/tests/core/operations/test_transform.py
+++ b/tests/core/operations/test_transform.py
@@ -489,10 +489,11 @@ def test_transform_elements_and_entire_spatial_data_object(full_sdata: SpatialDa
     scale = Scale([k], axes=("x",))
     translation = Translation([k], axes=("x",))
     sequence = Sequence([scale, translation])
-    for element in full_sdata._gen_spatial_element_values():
+    for _, element_name, _ in full_sdata.gen_spatial_elements():
+        element = full_sdata[element_name]
         set_transformation(element, sequence, "my_space")
         transformed_element = full_sdata.transform_element_to_coordinate_system(
-            element, "my_space", maintain_positioning=maintain_positioning
+            element_name, "my_space", maintain_positioning=maintain_positioning
         )
         t = get_transformation(transformed_element, to_coordinate_system="my_space")
         a = t.to_affine_matrix(input_axes=("x",), output_axes=("x",))