Skip to content

Commit 73ea1d2

Browse files
committed
fixup
1 parent b94bff2 commit 73ea1d2

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

src/zarr/_info.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def human_readable_size(size: int) -> str:
5757

5858
def byte_info(size: int) -> str:
5959
if size < 2**10:
60-
return size
60+
return str(size)
6161
else:
6262
return f"{size} ({human_readable_size(size)})"
6363

@@ -67,8 +67,8 @@ class ArrayInfo:
6767
type: Literal["Array"] = "Array"
6868
zarr_format: Literal[2, 3]
6969
data_type: str
70-
shape: tuple[int,]
71-
chunk_shape: tuple[int,]
70+
shape: tuple[int, ...]
71+
chunk_shape: tuple[int, ...] | None = None
7272
order: Literal["C", "F"]
7373
read_only: bool
7474
store_type: str
@@ -91,6 +91,9 @@ def __repr__(self) -> str:
9191
Store type : {store_type}""")
9292

9393
kwargs = dataclasses.asdict(self)
94+
if self.chunk_shape is None:
95+
# for non-regular chunk grids
96+
kwargs["chunk_shape"] = "<variable>"
9497
if self.compressor is not None:
9598
template += "\nCompressor : {compressor}"
9699

src/zarr/core/array.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,27 +1148,39 @@ def __repr__(self) -> str:
11481148

11491149
@property
11501150
def info(self) -> ArrayInfo:
1151-
kwargs = {}
1151+
return self._info()
1152+
1153+
async def info_complete(self) -> ArrayInfo:
1154+
# do the I/O to get the extra
1155+
extra: dict[str, int] = {}
1156+
return self._info(extra=extra)
1157+
1158+
def _info(self, extra: dict[str, int] | None = None) -> ArrayInfo:
1159+
kwargs: dict[str, Any] = {}
11521160
if self.metadata.zarr_format == 2:
1153-
kwargs["compressor"] = self.metadata.compressor
1154-
kwargs["filters"] = self.metadata.filters
1161+
assert isinstance(self.metadata, ArrayV2Metadata)
1162+
if self.metadata.compressor is not None:
1163+
kwargs["compressor"] = str(self.metadata.compressor)
1164+
if self.metadata.filters is not None:
1165+
kwargs["filters"] = str(self.metadata.filters)
1166+
kwargs["data_type"] = str(self.metadata.dtype)
1167+
kwargs["chunks"] = self.metadata.chunks
11551168
else:
1156-
kwargs["codecs"] = self.metadata.codecs
1169+
kwargs["codecs"] = str(self.metadata.codecs)
1170+
kwargs["data_type"] = str(self.metadata.data_type)
1171+
# just regular?
1172+
if isinstance(self.metadata.chunk_grid, RegularChunkGrid):
1173+
kwargs["chunks"] = self.metadata.chunk_grid.chunk_shape
11571174

11581175
return ArrayInfo(
11591176
zarr_format=self.metadata.zarr_format,
1160-
data_type=self.metadata.data_type,
11611177
shape=self.shape,
1162-
chunk_shape=self.metadata.chunk_grid.chunk_shape,
11631178
order=self.order,
11641179
read_only=self.store_path.store.mode.readonly,
11651180
store_type=type(self.store_path.store).__name__,
1166-
**kwargs
1181+
**kwargs,
11671182
)
11681183

1169-
async def info_full(self) -> None:
1170-
return ArrayInfo()
1171-
11721184

11731185
@dataclass(frozen=True)
11741186
class Array:
@@ -2844,7 +2856,7 @@ def info(self) -> ArrayInfo:
28442856
return self._async_array.info
28452857

28462858
def info_complete(self) -> ArrayInfo:
2847-
return sync(self._async_array.info_complete)
2859+
return sync(self._async_array.info_complete())
28482860

28492861

28502862
def nchunks_initialized(

src/zarr/core/group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ def _info(
825825
read_only=self.store_path.store.mode.readonly,
826826
store_type=type(self.store_path.store).__name__,
827827
zarr_format=self.metadata.zarr_format,
828-
**kwargs,
828+
# maybe do a typeddict
829+
**kwargs, # type: ignore[arg-type]
829830
)
830831

831832
@property

tests/v3/test_info.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import textwrap
2-
from typing import Literal
32

43
import pytest
54

6-
from zarr.core.common import ZarrFormat
75
from zarr._info import ArrayInfo, GroupInfo
8-
6+
from zarr.core.common import ZarrFormat
97

108
ZARR_FORMATS = [2, 3]
119

@@ -48,7 +46,7 @@ def test_group_info_complete(zarr_format: ZarrFormat) -> None:
4846

4947

5048
@pytest.mark.parametrize("zarr_format", ZARR_FORMATS)
51-
def test_array_info(zarr_format: ZarrFormat):
49+
def test_array_info(zarr_format: ZarrFormat) -> None:
5250
info = ArrayInfo(
5351
zarr_format=zarr_format,
5452
data_type="int32",
@@ -73,10 +71,10 @@ def test_array_info(zarr_format: ZarrFormat):
7371

7472

7573
@pytest.mark.parametrize("zarr_format", ZARR_FORMATS)
76-
@pytest.mark.parametrize("bytes_things", [(1_000_000, "976.6K", 500_000, "5", "2.0", 5)])
74+
@pytest.mark.parametrize("bytes_things", [(1_000_000, "976.6K", 500_000, "500000", "2.0", 5)])
7775
def test_array_info_complete(
7876
zarr_format: ZarrFormat, bytes_things: tuple[int, str, int, str, str, int]
79-
):
77+
) -> None:
8078
(
8179
count_bytes,
8280
count_bytes_formatted,
@@ -109,7 +107,7 @@ def test_array_info_complete(
109107
Read-only : True
110108
Store type : MemoryStore
111109
Codecs : ["BytesCodec(endian=<Endian.little: 'little'>"]
112-
No. bytes : 1000000 (976.6K)
113-
No. bytes stored : 500000
114-
Storage ratio : 2.0
110+
No. bytes : {count_bytes} ({count_bytes_formatted})
111+
No. bytes stored : {count_bytes_stored_formatted}
112+
Storage ratio : {storage_ratio_formatted}
115113
Chunks Initialized : 5""")

0 commit comments

Comments
 (0)