Skip to content

Commit

Permalink
Merge pull request scverse#133 from melonora/main
Browse files Browse the repository at this point in the history
make obs names unique
  • Loading branch information
melonora authored Apr 24, 2024
2 parents 3ca6f8b + 2888976 commit 85a58b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning][].

- (Xenium) support reading multi-polygon selection files from the Xenium Explorer

### Fixed

- (Visium) Fixed issue with joining a SpatialElement with a table due to index values not being unique.
obs_names_make_unique is now called internally to enforce unique index values allowing for join operations.

## [0.1.2] - 2024-03-30

### Added
Expand Down
6 changes: 6 additions & 0 deletions src/spatialdata_io/readers/visium.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ def visium(
adata.obs.drop(columns=[VisiumKeys.SPOTS_X, VisiumKeys.SPOTS_Y], inplace=True)
adata.obs["spot_id"] = np.arange(len(adata))
adata.var_names_make_unique()

if not adata.obs_names.is_unique:
logger.info("Non-unique obs names detected, calling `obs_names_make_unique`.")
# This is required for napari-spatialdata because of the join operation that would otherwise fail
adata.obs_names_make_unique()

if (path / "spatial" / VisiumKeys.SCALEFACTORS_FILE).exists() or (
scalefactors_file is not None and (path / scalefactors_file).exists()
):
Expand Down
1 change: 1 addition & 0 deletions src/spatialdata_io/readers/visium_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def load_image(path: Path, suffix: str, scale_factors: list[int] | None = None)
# parse table
adata.obs[VisiumHDKeys.REGION_KEY] = shapes_name
adata.obs[VisiumHDKeys.REGION_KEY] = adata.obs[VisiumHDKeys.REGION_KEY].astype("category")

tables[bin_size_str] = TableModel.parse(
adata,
region=shapes_name,
Expand Down

0 comments on commit 85a58b6

Please sign in to comment.