Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ivirshup committed Jul 14, 2023
1 parent 18d0ee3 commit 0036a30
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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(read_elem(z["table/table"]), adata)

0 comments on commit 0036a30

Please sign in to comment.