Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Oct 18, 2024
1 parent a3b797d commit 30c4e6a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/zarr/_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ArrayInfo:
store_type: str
compressor: str | None = None
filters: list[str] | None = None
codecs: list[str] | None = None
codecs: str | None = None
count_bytes: int | None = None
count_bytes_stored: int | None = None
count_chunks_initialized: int | None = None
Expand Down
9 changes: 4 additions & 5 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,9 +1151,8 @@ def info(self) -> ArrayInfo:
return self._info()

async def info_complete(self) -> ArrayInfo:
# do the I/O to get the extra
extra: dict[str, int] = {}
return self._info(extra=extra)
# TODO: get the size of the object from the store.
raise NotImplementedError

def _info(self, extra: dict[str, int] | None = None) -> ArrayInfo:
kwargs: dict[str, Any] = {}
Expand All @@ -1164,13 +1163,13 @@ def _info(self, extra: dict[str, int] | None = None) -> ArrayInfo:
if self.metadata.filters is not None:
kwargs["filters"] = str(self.metadata.filters)
kwargs["data_type"] = str(self.metadata.dtype)
kwargs["chunks"] = self.metadata.chunks
kwargs["chunk_shape"] = self.metadata.chunks
else:
kwargs["codecs"] = str(self.metadata.codecs)
kwargs["data_type"] = str(self.metadata.data_type)
# just regular?
if isinstance(self.metadata.chunk_grid, RegularChunkGrid):
kwargs["chunks"] = self.metadata.chunk_grid.chunk_shape
kwargs["chunk_shape"] = self.metadata.chunk_grid.chunk_shape

return ArrayInfo(
zarr_format=self.metadata.zarr_format,
Expand Down
55 changes: 55 additions & 0 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,13 +794,41 @@ def attrs(self) -> dict[str, Any]:

@property
def info(self) -> GroupInfo:
"""
Return the statically known information for a group.
Returns
-------
GroupInfo
See Also
--------
AsyncGroup.info_complete
All information about a group, including dynamic information
like the children members.
"""

if self.metadata.consolidated_metadata:
members = list(self.metadata.consolidated_metadata.flattened_metadata.values())
else:
members = None
return self._info(members=members)

async def info_complete(self) -> GroupInfo:
"""
Return information for a group.
If this group doesn't contain consolidated metadata then
this will need to read from the backing Store.
Returns
-------
GroupInfo
See Also
--------
AsyncGroup.info
"""
members = [x[1].metadata async for x in self.members(max_depth=None)]
return self._info(members=members)

Expand Down Expand Up @@ -1473,9 +1501,36 @@ def attrs(self) -> Attributes:

@property
def info(self) -> GroupInfo:
"""
Return the statically known information for a group.
Returns
-------
GroupInfo
See Also
--------
Group.info_complete
All information about a group, including dynamic information
like the children members.
"""
return self._async_group.info

def info_complete(self) -> GroupInfo:
"""
Return information for a group.
If this group doesn't contain consolidated metadata then
this will need to read from the backing Store.
Returns
-------
GroupInfo
See Also
--------
Group.info
"""
return self._sync(self._async_group.info_complete())

@property
Expand Down
32 changes: 32 additions & 0 deletions tests/v3/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import zarr.api.asynchronous
from zarr import Array, AsyncArray, Group
from zarr._info import ArrayInfo
from zarr.codecs import BytesCodec, VLenBytesCodec
from zarr.core.array import chunks_initialized
from zarr.core.buffer.cpu import NDBuffer
Expand Down Expand Up @@ -417,3 +418,34 @@ def test_update_attrs(zarr_format: int) -> None:

arr2 = zarr.open_array(store=store, zarr_format=zarr_format)
assert arr2.attrs["foo"] == "bar"


class TestInfo:
def test_info_v2(self) -> None:
arr = zarr.create(shape=(4, 4), chunks=(2, 2), zarr_format=2)
result = arr.info
expected = ArrayInfo(
zarr_format=2,
data_type="float64",
shape=(4, 4),
chunk_shape=(2, 2),
order="C",
read_only=False,
store_type="MemoryStore",
)
assert result == expected

def test_info_v3(self) -> None:
arr = zarr.create(shape=(4, 4), chunks=(2, 2), zarr_format=3)
result = arr.info
expected = ArrayInfo(
zarr_format=3,
data_type="DataType.float64",
shape=(4, 4),
chunk_shape=(2, 2),
order="C",
read_only=False,
store_type="MemoryStore",
codecs="[BytesCodec(endian=<Endian.little: 'little'>)]",
)
assert result == expected

0 comments on commit 30c4e6a

Please sign in to comment.