Skip to content

Commit 080bcd5

Browse files
rabernatd-v-bjhamman
committed
implement .chunks on v3 arrays (zarr-developers#1929)
* implement .chunks on v3 arrays * remove noqa: B009 * make mypy happy * only return chunks for regular chunk grids --------- Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com> Co-authored-by: Joseph Hamman <joe@earthmover.io>
1 parent 1cb6179 commit 080bcd5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/zarr/array.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ def ndim(self) -> int:
366366
def shape(self) -> ChunkCoords:
367367
return self.metadata.shape
368368

369+
@property
370+
def chunks(self) -> ChunkCoords:
371+
if isinstance(self.metadata.chunk_grid, RegularChunkGrid):
372+
return self.metadata.chunk_grid.chunk_shape
373+
else:
374+
raise ValueError(
375+
f"chunk attribute is only available for RegularChunkGrid, this array has a {self.metadata.chunk_grid}"
376+
)
377+
369378
@property
370379
def size(self) -> int:
371380
return np.prod(self.metadata.shape).item()
@@ -639,6 +648,10 @@ def ndim(self) -> int:
639648
def shape(self) -> ChunkCoords:
640649
return self._async_array.shape
641650

651+
@property
652+
def chunks(self) -> ChunkCoords:
653+
return self._async_array.chunks
654+
642655
@property
643656
def size(self) -> int:
644657
return self._async_array.size

tests/v3/test_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_group(store: MemoryStore | LocalStore) -> None:
7979
assert arr.dtype == data.dtype
8080

8181
# TODO: update this once the array api settles down
82-
# assert arr.chunk_shape == (2, 2)
82+
assert arr.chunks == (2, 2)
8383

8484
bar2 = foo["bar"]
8585
assert dict(bar2.attrs) == {"baz": "qux"}

0 commit comments

Comments
 (0)