diff --git a/CHANGELOG.md b/CHANGELOG.md index 6521a5dc..82bbd8e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,12 @@ Release notes for `v0.7.1` and earlier are available on the [Releases][] page. documentation builds, `mypy` type checking of `src` and `tests`, `biome`/`pyproject-fmt`/`zizmor` pre-commit hooks, and Dependabot updates. +### Fixed + +- `visium()`: the circles are built again from the spot coordinates instead of from the raw `tissue_positions` table, + which made the reader raise `TypeError: ShapesModel.parse() does not support the type + `. + ### Removed - Support for Python 3.11. diff --git a/src/spatialdata_io/readers/visium.py b/src/spatialdata_io/readers/visium.py index 5d9fad58..9d784121 100644 --- a/src/spatialdata_io/readers/visium.py +++ b/src/spatialdata_io/readers/visium.py @@ -174,7 +174,10 @@ def visium( assert isinstance(adata.obs, pd.DataFrame) adata.obs = pd.merge(adata.obs, coords, how="left", left_index=True, right_index=True) - adata.obsm["spatial"] = adata.obs[[VisiumKeys.SPOTS_X, VisiumKeys.SPOTS_Y]].values + # `coords` above is the raw `tissue_positions` table; the circles are built from the + # spot coordinates in the order of `adata`, so keep them in a separate variable + spot_coords = adata.obs[[VisiumKeys.SPOTS_X, VisiumKeys.SPOTS_Y]].to_numpy() + adata.obsm["spatial"] = spot_coords adata.obs = pd.DataFrame(adata.obs) adata.obs.drop(columns=[VisiumKeys.SPOTS_X, VisiumKeys.SPOTS_Y], inplace=True) adata.obs["spot_id"] = np.arange(len(adata)) @@ -204,7 +207,7 @@ def visium( ) shapes = {} circles = ShapesModel.parse( - coords, + spot_coords, geometry=0, radius=scalefactors["spot_diameter_fullres"] / 2.0, index=adata.obs["spot_id"].copy(),