Skip to content

Commit

Permalink
fix str column showing object dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
melonora committed Mar 15, 2024
1 parent c2e4ef9 commit 4101557
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/spatialdata/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,10 @@ def _validate_table_annotation_metadata(self, data: AnnData) -> None:
raise ValueError(f"`{attr[self.REGION_KEY_KEY]}` not found in `adata.obs`.")
if attr[self.INSTANCE_KEY] not in data.obs:
raise ValueError(f"`{attr[self.INSTANCE_KEY]}` not found in `adata.obs`.")
if (dtype := data.obs[attr[self.INSTANCE_KEY]].dtype) not in [np.int16, np.int32, np.int64, str]:
if (dtype := data.obs[attr[self.INSTANCE_KEY]].dtype) not in [np.int16, np.int32, np.int64, "O"] or (
dtype == "O" and (val_dtype := type(data.obs[attr[self.INSTANCE_KEY]][0])) != str
):
dtype = dtype if dtype != "O" else val_dtype
raise TypeError(
f"Only np.int16, np.int32, np.int64 or string allowed as dtype for "
f"instance_key column in obs. Dtype found to be {dtype}"
Expand Down

0 comments on commit 4101557

Please sign in to comment.