Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.5.3]

### Fix
- Fix bug in AnnData backend where "raw" entry with encoding-type "null" is written by default in newer anndata versions, which causes compatibility issues with older anndata versions. Now the "raw" entry is removed after writing if it has encoding-type "null".

## [0.5.2]

### Fix
Expand Down
12 changes: 12 additions & 0 deletions src/ngio/tables/backends/_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def _write_to_memory_store(
suppress_warnings=True,
)

def _cleanup_after_write(self) -> None:
"""Clean up any temporary data after writing."""
group = self._group_handler._group
try:
raw_group = group["raw"]
except KeyError:
return
# Remove "raw" entry (encoding-type "null") that anndata <0.11 can't read
if dict(raw_group.attrs).get("encoding-type") == "null":
del group["raw"]

def write_from_anndata(self, table: AnnData) -> None:
"""Serialize the table from an AnnData object."""
# Make sure to use the correct zarr format
Expand Down Expand Up @@ -112,6 +123,7 @@ def write_from_anndata(self, table: AnnData) -> None:
"Please make sure to use a compatible "
"store like a LocalStore, or FsspecStore."
)
self._cleanup_after_write()

def write_from_pandas(self, table: DataFrame) -> None:
"""Serialize the table from a pandas DataFrame."""
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/tables/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ def test_anndata_backend(tmp_path: Path):
lf_data = backend.load_as_polars_lf()
backend.write(lf_data, metadata={"test": "test"})

# Test that the "raw" entry with encoding-type "null" is
# removed after writing for compatibility with older anndata versions
with pytest.raises(KeyError):
backend._group_handler._group["raw"]


@pytest.mark.parametrize(
"index_label, index_type",
Expand Down