From 2402c3b4913bde4a27b4808071e2cf4e1c9138ed Mon Sep 17 00:00:00 2001 From: lorenzo Date: Mon, 9 Feb 2026 18:54:07 +0100 Subject: [PATCH 1/3] remove empty raw group when empty --- src/ngio/tables/backends/_anndata.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ngio/tables/backends/_anndata.py b/src/ngio/tables/backends/_anndata.py index 40a092f1..4d1d4a64 100644 --- a/src/ngio/tables/backends/_anndata.py +++ b/src/ngio/tables/backends/_anndata.py @@ -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 @@ -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.""" From 820fda835b9f4f20b1cf1becb73a618fcf5cfeea Mon Sep 17 00:00:00 2001 From: lorenzo Date: Mon, 9 Feb 2026 19:09:37 +0100 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 116a9e18..893a163c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 9f0ab192cf18f8c27141e642da35da795d0d0ffb Mon Sep 17 00:00:00 2001 From: lorenzo Date: Mon, 9 Feb 2026 19:12:51 +0100 Subject: [PATCH 3/3] add raw check in testing --- tests/unit/tables/test_backends.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit/tables/test_backends.py b/tests/unit/tables/test_backends.py index ff54c8f7..9e7e29a2 100644 --- a/tests/unit/tables/test_backends.py +++ b/tests/unit/tables/test_backends.py @@ -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",