diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5fa18..ed80915 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Changelog -## Version 0.0.10 +## Version 0.0.11 +- BUGFIX: `to_anndata()` only populates `obsm` with spatial coordinates if the original `SpatialExperiment` has spatial coordinates (PR #53) + +## Version 0.0.10 - Add an affine function that computes a `rasterio.Affine` object given a `scale_factor`. This assumes a simple scaling where the origin is (0,0) in the spatial coordinate system corresponding to the top-left pixel (0,0). More complex alignments would require explicit affine transforms. - Ensure img_raster() consistently returns a PIL.Image.Image. - Add to_numpy() method. @@ -11,9 +14,11 @@ ## Version 0.0.9 - Added `to_anndata()` in main `SpatialExperiment` class (PR #50) + ## Version 0.0.8 - Set the expected column names for image data slot (PR #46) + ## Version 0.0.7 - Added `img_source` function in main SpatialExperiment class and child classes of VirtualSpatialExperiment (PR #36) - Added `remove_img` function (PR #34) @@ -21,20 +26,21 @@ - Disambiguated `get_img_data` between `_imgutils.py` and `SpatialExperiment.py` - Moved `SpatialFeatureExperiment` into its own package + ## Version 0.0.6 - Added `read_tenx_visium()` function to load 10x Visium data as SpatialExperiment - Added `combine_columns` function - Implemented `__eq__` override for `SpatialImage` subclasses -## Version 0.0.5 +## Version 0.0.5 - Implementing a placeholder `SpatialFeatureExperiment` class. This version only implements the data structure to hold various geometries but none of the methods except for slicing. -## Version 0.0.3 - 0.0.4 +## Version 0.0.3 - 0.0.4 - Streamlining the `SpatialImage` class implementations. -## Version 0.0.1 - 0.0.2 +## Version 0.0.1 - 0.0.2 - Initial version of the SpatialExperiment class with the additional slots. - Allow spatial coordinates to be a numpy array diff --git a/src/spatialexperiment/spatialexperiment.py b/src/spatialexperiment/spatialexperiment.py index b94b942..bdf69e6 100644 --- a/src/spatialexperiment/spatialexperiment.py +++ b/src/spatialexperiment/spatialexperiment.py @@ -1051,7 +1051,9 @@ def to_anndata(self, include_alternative_experiments: bool = False) -> "anndata. "tissue_hires_scalef": row["scale_factor"] } # default to `tissue_hires_scalef` for now - obj.obsm["spatial"] = np.column_stack([self.spatial_coordinates[axis] for axis in self.spatial_coords_names]) + if len(self.spatial_coordinates) > 0: + coords_by_axis = [self.spatial_coordinates[axis] for axis in self.spatial_coords_names] + obj.obsm["spatial"] = np.column_stack(coords_by_axis) return obj, alt_exps diff --git a/tests/test_to_anndata.py b/tests/test_to_anndata.py index 258f6a5..b12b6c6 100644 --- a/tests/test_to_anndata.py +++ b/tests/test_to_anndata.py @@ -1,6 +1,9 @@ +import pytest from copy import deepcopy from pathlib import Path -import pytest +import anndata as ad + +from spatialexperiment import SpatialExperiment __author__ = "keviny2" __copyright__ = "keviny2" @@ -28,6 +31,14 @@ def test_to_anndata(spe): assert obj.obsm['spatial'].shape == (500, 2) +def test_to_anndata_empty(): + tspe = SpatialExperiment() + + obj, alt_exps = tspe.to_anndata() + + assert isinstance(obj, ad.AnnData) + + def test_to_anndata_spatial_key_exists(spe): tspe = deepcopy(spe)