Skip to content

Commit cdb1672

Browse files
committed
fixup
1 parent 73c304a commit cdb1672

File tree

6 files changed

+147
-137
lines changed

6 files changed

+147
-137
lines changed

src/zarr/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
zeros,
2727
zeros_like,
2828
)
29-
from zarr.core._info import GroupInfo
3029
from zarr.core.array import Array, AsyncArray
3130
from zarr.core.config import config
3231
from zarr.core.group import AsyncGroup, Group
@@ -39,7 +38,6 @@
3938
"AsyncArray",
4039
"AsyncGroup",
4140
"Group",
42-
"GroupInfo",
4341
"__version__",
4442
"array",
4543
"config",

src/zarr/core/_info.py

Lines changed: 69 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,29 @@ class GroupInfo:
3333
or when using :class:`Group.info_complete`.
3434
"""
3535

36-
name: str
37-
type: Literal["Group"] = "Group"
38-
zarr_format: Literal[2, 3]
39-
read_only: bool
40-
store_type: str
41-
count_members: int | None = None
42-
count_arrays: int | None = None
43-
count_groups: int | None = None
36+
_name: str
37+
_type: Literal["Group"] = "Group"
38+
_zarr_format: Literal[2, 3]
39+
_read_only: bool
40+
_store_type: str
41+
_count_members: int | None = None
42+
_count_arrays: int | None = None
43+
_count_groups: int | None = None
4444

4545
def __repr__(self) -> str:
4646
template = textwrap.dedent("""\
47-
Name : {name}
48-
Type : {type}
49-
Zarr format : {zarr_format}
50-
Read-only : {read_only}
51-
Store type : {store_type}""")
52-
53-
if self.count_members is not None:
54-
template += "\nNo. members : {count_members}"
55-
if self.count_arrays is not None:
56-
template += "\nNo. arrays : {count_arrays}"
57-
if self.count_groups is not None:
58-
template += "\nNo. groups : {count_groups}"
47+
Name : {_name}
48+
Type : {_type}
49+
Zarr format : {_zarr_format}
50+
Read-only : {_read_only}
51+
Store type : {_store_type}""")
52+
53+
if self._count_members is not None:
54+
template += "\nNo. members : {_count_members}"
55+
if self._count_arrays is not None:
56+
template += "\nNo. arrays : {_count_arrays}"
57+
if self._count_groups is not None:
58+
template += "\nNo. groups : {_count_groups}"
5959
return template.format(**dataclasses.asdict(self))
6060

6161

@@ -83,61 +83,68 @@ def byte_info(size: int) -> str:
8383

8484
@dataclasses.dataclass(kw_only=True)
8585
class ArrayInfo:
86-
type: Literal["Array"] = "Array"
87-
zarr_format: Literal[2, 3]
88-
data_type: str
89-
shape: tuple[int, ...]
90-
chunk_shape: tuple[int, ...] | None = None
91-
order: Literal["C", "F"]
92-
read_only: bool
93-
store_type: str
94-
compressor: str | None = None
95-
filters: list[str] | None = None
96-
codecs: str | None = None
97-
count_bytes: int | None = None
98-
count_bytes_stored: int | None = None
99-
count_chunks_initialized: int | None = None
86+
"""
87+
Render the information for an array.
88+
89+
Note that this method and its properties is not part of
90+
Zarr's public API.
91+
"""
92+
93+
_type: Literal["Array"] = "Array"
94+
_zarr_format: Literal[2, 3]
95+
_data_type: str
96+
_shape: tuple[int, ...]
97+
_chunk_shape: tuple[int, ...] | None = None
98+
_order: Literal["C", "F"]
99+
_read_only: bool
100+
_store_type: str
101+
_compressor: str | None = None
102+
_filters: list[str] | None = None
103+
_codecs: str | None = None
104+
_count_bytes: int | None = None
105+
_count_bytes_stored: int | None = None
106+
_count_chunks_initialized: int | None = None
100107

101108
def __repr__(self) -> str:
102109
template = textwrap.dedent("""\
103-
Type : {type}
104-
Zarr format : {zarr_format}
105-
Data type : {data_type}
106-
Shape : {shape}
107-
Chunk shape : {chunk_shape}
108-
Order : {order}
109-
Read-only : {read_only}
110-
Store type : {store_type}""")
110+
Type : {_type}
111+
Zarr format : {_zarr_format}
112+
Data type : {_data_type}
113+
Shape : {_shape}
114+
Chunk shape : {_chunk_shape}
115+
Order : {_order}
116+
Read-only : {_read_only}
117+
Store type : {_store_type}""")
111118

112119
kwargs = dataclasses.asdict(self)
113-
if self.chunk_shape is None:
120+
if self._chunk_shape is None:
114121
# for non-regular chunk grids
115122
kwargs["chunk_shape"] = "<variable>"
116-
if self.compressor is not None:
117-
template += "\nCompressor : {compressor}"
123+
if self._compressor is not None:
124+
template += "\nCompressor : {_compressor}"
118125

119-
if self.filters is not None:
120-
template += "\nFilters : {filters}"
126+
if self._filters is not None:
127+
template += "\nFilters : {_filters}"
121128

122-
if self.codecs is not None:
123-
template += "\nCodecs : {codecs}"
129+
if self._codecs is not None:
130+
template += "\nCodecs : {_codecs}"
124131

125-
if self.count_bytes is not None:
126-
template += "\nNo. bytes : {count_bytes}"
127-
kwargs["count_bytes"] = byte_info(self.count_bytes)
132+
if self._count_bytes is not None:
133+
template += "\nNo. bytes : {_count_bytes}"
134+
kwargs["_count_bytes"] = byte_info(self._count_bytes)
128135

129-
if self.count_bytes_stored is not None:
130-
template += "\nNo. bytes stored : {count_bytes_stored}"
131-
kwargs["count_stored"] = byte_info(self.count_bytes_stored)
136+
if self._count_bytes_stored is not None:
137+
template += "\nNo. bytes stored : {_count_bytes_stored}"
138+
kwargs["_count_stored"] = byte_info(self._count_bytes_stored)
132139

133140
if (
134-
self.count_bytes is not None
135-
and self.count_bytes_stored is not None
136-
and self.count_bytes_stored > 0
141+
self._count_bytes is not None
142+
and self._count_bytes_stored is not None
143+
and self._count_bytes_stored > 0
137144
):
138-
template += "\nStorage ratio : {storage_ratio}"
139-
kwargs["storage_ratio"] = f"{self.count_bytes / self.count_bytes_stored:.1f}"
145+
template += "\nStorage ratio : {_storage_ratio}"
146+
kwargs["_storage_ratio"] = f"{self._count_bytes / self._count_bytes_stored:.1f}"
140147

141-
if self.count_chunks_initialized is not None:
142-
template += "\nChunks Initialized : {count_chunks_initialized}"
148+
if self._count_chunks_initialized is not None:
149+
template += "\nChunks Initialized : {_count_chunks_initialized}"
143150
return template.format(**kwargs)

src/zarr/core/array.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ def __repr__(self) -> str:
13341334
return f"<AsyncArray {self.store_path} shape={self.shape} dtype={self.dtype}>"
13351335

13361336
@property
1337-
def info(self) -> ArrayInfo:
1337+
def info(self) -> Any:
13381338
"""
13391339
Return the statically known information for an array.
13401340
@@ -1350,17 +1350,17 @@ def info(self) -> ArrayInfo:
13501350
"""
13511351
return self._info()
13521352

1353-
async def info_complete(self) -> ArrayInfo:
1353+
async def info_complete(self) -> Any:
13541354
# TODO: get the size of the object from the store.
13551355
extra = {
1356-
"count_chunks_initialized": self.nchunks_initialized, # this should be async?
1356+
"count_chunks_initialized": await self.nchunks_initialized(),
13571357
# count_bytes_stored isn't yet implemented.
13581358
}
13591359
return self._info(extra=extra)
13601360

13611361
raise NotImplementedError
13621362

1363-
def _info(self, extra: dict[str, int] | None = None) -> ArrayInfo:
1363+
def _info(self, extra: dict[str, int] | None = None) -> Any:
13641364
kwargs: dict[str, Any] = {}
13651365
if self.metadata.zarr_format == 2:
13661366
assert isinstance(self.metadata, ArrayV2Metadata)
@@ -1383,12 +1383,12 @@ def _info(self, extra: dict[str, int] | None = None) -> ArrayInfo:
13831383
)
13841384

13851385
return ArrayInfo(
1386-
zarr_format=self.metadata.zarr_format,
1387-
shape=self.shape,
1388-
order=self.order,
1389-
read_only=self.store_path.store.mode.readonly,
1390-
store_type=type(self.store_path.store).__name__,
1391-
count_bytes=self.dtype.itemsize * self.size,
1386+
_zarr_format=self.metadata.zarr_format,
1387+
_shape=self.shape,
1388+
_order=self.order,
1389+
_read_only=self.store_path.store.mode.readonly,
1390+
_store_type=type(self.store_path.store).__name__,
1391+
_count_bytes=self.dtype.itemsize * self.size,
13921392
**kwargs,
13931393
)
13941394

@@ -3157,7 +3157,7 @@ def __repr__(self) -> str:
31573157
return f"<Array {self.store_path} shape={self.shape} dtype={self.dtype}>"
31583158

31593159
@property
3160-
def info(self) -> ArrayInfo:
3160+
def info(self) -> Any:
31613161
"""
31623162
Return the statically known information for an array.
31633163
@@ -3188,7 +3188,7 @@ def info(self) -> ArrayInfo:
31883188
"""
31893189
return self._async_array.info
31903190

3191-
def info_complete(self) -> ArrayInfo:
3191+
def info_complete(self) -> Any:
31923192
"""
31933193
Returns all the information about an array, including information from the Store.
31943194

src/zarr/core/group.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,12 @@ def attrs(self) -> dict[str, Any]:
806806
return self.metadata.attributes
807807

808808
@property
809-
def info(self) -> GroupInfo:
809+
def info(self) -> Any:
810810
"""
811-
Return the statically known information for a group.
811+
Return a visual representation of the statically known information about a group.
812+
813+
Note that this doesn't include dynamic information, like the number of child
814+
Groups or Arrays.
812815
813816
Returns
814817
-------
@@ -818,7 +821,6 @@ def info(self) -> GroupInfo:
818821
--------
819822
AsyncGroup.info_complete
820823
All information about a group, including dynamic information
821-
like the children members.
822824
"""
823825

824826
if self.metadata.consolidated_metadata:
@@ -827,12 +829,13 @@ def info(self) -> GroupInfo:
827829
members = None
828830
return self._info(members=members)
829831

830-
async def info_complete(self) -> GroupInfo:
832+
async def info_complete(self) -> Any:
831833
"""
832-
Return information for a group.
834+
Return all the information for a group.
833835
834-
If this group doesn't contain consolidated metadata then
835-
this will need to read from the backing Store.
836+
This includes dynamic information like the number
837+
of child Groups or Arrays. If this group doesn't contain consolidated
838+
metadata then this will need to read from the backing Store.
836839
837840
Returns
838841
-------
@@ -847,25 +850,25 @@ async def info_complete(self) -> GroupInfo:
847850

848851
def _info(
849852
self, members: list[ArrayV2Metadata | ArrayV3Metadata | GroupMetadata] | None = None
850-
) -> GroupInfo:
853+
) -> Any:
851854
kwargs = {}
852855
if members is not None:
853-
kwargs["count_members"] = len(members)
856+
kwargs["_count_members"] = len(members)
854857
count_arrays = 0
855858
count_groups = 0
856859
for member in members:
857860
if isinstance(member, GroupMetadata):
858861
count_groups += 1
859862
else:
860863
count_arrays += 1
861-
kwargs["count_arrays"] = count_arrays
862-
kwargs["count_groups"] = count_groups
864+
kwargs["_count_arrays"] = count_arrays
865+
kwargs["_count_groups"] = count_groups
863866

864867
return GroupInfo(
865-
name=self.store_path.path,
866-
read_only=self.store_path.store.mode.readonly,
867-
store_type=type(self.store_path.store).__name__,
868-
zarr_format=self.metadata.zarr_format,
868+
_name=self.store_path.path,
869+
_read_only=self.store_path.store.mode.readonly,
870+
_store_type=type(self.store_path.store).__name__,
871+
_zarr_format=self.metadata.zarr_format,
869872
# maybe do a typeddict
870873
**kwargs, # type: ignore[arg-type]
871874
)
@@ -1516,7 +1519,7 @@ def attrs(self) -> Attributes:
15161519
return Attributes(self)
15171520

15181521
@property
1519-
def info(self) -> GroupInfo:
1522+
def info(self) -> Any:
15201523
"""
15211524
Return the statically known information for a group.
15221525
@@ -1532,7 +1535,7 @@ def info(self) -> GroupInfo:
15321535
"""
15331536
return self._async_group.info
15341537

1535-
def info_complete(self) -> GroupInfo:
1538+
def info_complete(self) -> Any:
15361539
"""
15371540
Return information for a group.
15381541

tests/test_array.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -424,30 +424,30 @@ def test_info_v2(self) -> None:
424424
arr = zarr.create(shape=(4, 4), chunks=(2, 2), zarr_format=2)
425425
result = arr.info
426426
expected = ArrayInfo(
427-
zarr_format=2,
428-
data_type="float64",
429-
shape=(4, 4),
430-
chunk_shape=(2, 2),
431-
order="C",
432-
read_only=False,
433-
store_type="MemoryStore",
434-
count_bytes=128,
427+
_zarr_format=2,
428+
_data_type="float64",
429+
_shape=(4, 4),
430+
_chunk_shape=(2, 2),
431+
_order="C",
432+
_read_only=False,
433+
_store_type="MemoryStore",
434+
_count_bytes=128,
435435
)
436436
assert result == expected
437437

438438
def test_info_v3(self) -> None:
439439
arr = zarr.create(shape=(4, 4), chunks=(2, 2), zarr_format=3)
440440
result = arr.info
441441
expected = ArrayInfo(
442-
zarr_format=3,
443-
data_type="DataType.float64",
444-
shape=(4, 4),
445-
chunk_shape=(2, 2),
446-
order="C",
447-
read_only=False,
448-
store_type="MemoryStore",
449-
codecs="[BytesCodec(endian=<Endian.little: 'little'>)]",
450-
count_bytes=128,
442+
_zarr_format=3,
443+
_data_type="DataType.float64",
444+
_shape=(4, 4),
445+
_chunk_shape=(2, 2),
446+
_order="C",
447+
_read_only=False,
448+
_store_type="MemoryStore",
449+
_codecs="[BytesCodec(endian=<Endian.little: 'little'>)]",
450+
_count_bytes=128,
451451
)
452452
assert result == expected
453453

0 commit comments

Comments
 (0)