Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read_zarr for consolidated metadata and use directly on zarr.Group #1057

Merged
merged 3 commits into from
Jul 14, 2023
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: 4 additions & 1 deletion anndata/_io/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def read_zarr(store: Union[str, Path, MutableMapping, zarr.Group]) -> AnnData:
if isinstance(store, Path):
store = str(store)

f = zarr.open(store, mode="r")
if isinstance(store, zarr.Group):
f = store
else:
f = zarr.open(store, mode="r")

# Read with handling for backwards compat
def callback(func, elem_name: str, elem, iospec):
Expand Down
21 changes: 21 additions & 0 deletions anndata/tests/test_io_elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,24 @@ def test_override_specification():
)
def _(store, key, adata):
pass


@pytest.mark.parametrize("consolidated", [True, False])
def test_read_zarr_from_group(tmp_path, consolidated):
# https://github.com/scverse/anndata/issues/1056
pth = tmp_path / "test.zarr"
adata = gen_adata((3, 2))

with zarr.open(pth, mode="w") as z:
write_elem(z, "table/table", adata)

if consolidated:
zarr.convenience.consolidate_metadata(z.store)

if consolidated:
read_func = zarr.open_consolidated
else:
read_func = zarr.open

with read_func(pth) as z:
assert_equal(ad.read_zarr(z["table/table"]), adata)
1 change: 1 addition & 0 deletions docs/release-notes/0.9.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

* Fix ufuncs of views like `adata.X[:10].cov(axis=0)` returning views {pr}`1043` {user}`flying-sheep`
* Fix instantiating AnnData where `.X` is a `DataFrame` with an integer valued index {pr}`1002` {user}`flying-sheep`
* Fix {func}`~anndata.read_zarr` when used on `zarr.Group` {pr}`1057` {user}`ivirshup`