33import numpy as np
44import pytest
55
6- from zarr .core .chunk_grids import _guess_regular_chunks , normalize_chunks_nd
6+ from zarr .core .chunk_grids import (
7+ _guess_regular_chunks ,
8+ normalize_chunks_nd ,
9+ resolve_outer_and_inner_chunks ,
10+ )
711
812
913@pytest .mark .parametrize (
@@ -42,6 +46,9 @@ def test_guess_chunks(shape: tuple[int, ...], itemsize: int) -> None:
4246 (((100 , 100 , 100 ), (50 , 50 )), (300 , 100 ), ((100 , 100 , 100 ), (50 , 50 ))),
4347 (((100 , 100 , 50 ),), (250 ,), ((100 , 100 , 50 ),)),
4448 (((100 ,),), (100 ,), ((100 ,),)),
49+ # no chunking (False means each dimension is one chunk spanning the full extent)
50+ (False , (100 ,), ((100 ,),)),
51+ (False , (100 , 50 ), ((100 ,), (50 ,))),
4552 # sentinel values
4653 (- 1 , (100 ,), ((100 ,),)),
4754 ((30 , - 1 , None ), (100 , 20 , 10 ), ((30 , 30 , 30 , 30 ), (20 ,), (10 ,))),
@@ -57,6 +64,34 @@ def test_normalize_chunks(
5764 assert expected == normalize_chunks_nd (chunks , shape )
5865
5966
67+ @pytest .mark .parametrize (
68+ ("array_shape" , "chunks_input" , "shard_shape" , "expected_outer" , "expected_inner" ),
69+ [
70+ # no sharding: outer = chunks, inner = None
71+ ((100 ,), (10 ,), None , ((10 ,) * 10 ,), None ),
72+ # explicit regular shards
73+ ((100 ,), (10 ,), (50 ,), ((50 , 50 ),), ((10 ,) * 10 ,)),
74+ # rectilinear shards
75+ ((100 ,), (10 ,), ((60 , 40 ),), ((60 , 40 ),), ((10 ,) * 10 ,)),
76+ # dict-style shards
77+ ((100 , 100 ), (10 , 10 ), {"shape" : (50 , 50 )}, ((50 , 50 ), (50 , 50 )), ((10 ,) * 10 , (10 ,) * 10 )),
78+ ],
79+ )
80+ def test_resolve_outer_and_inner_chunks (
81+ array_shape : tuple [int , ...],
82+ chunks_input : tuple [int , ...],
83+ shard_shape : Any ,
84+ expected_outer : tuple [tuple [int , ...], ...],
85+ expected_inner : tuple [tuple [int , ...], ...] | None ,
86+ ) -> None :
87+ chunks = normalize_chunks_nd (chunks_input , array_shape )
88+ result = resolve_outer_and_inner_chunks (
89+ array_shape = array_shape , chunks = chunks , shard_shape = shard_shape , item_size = 1
90+ )
91+ assert result .outer_chunks == expected_outer
92+ assert result .inner_chunks == expected_inner
93+
94+
6095def test_normalize_chunks_errors () -> None :
6196 with pytest .raises (ValueError , match = "does not accept None" ):
6297 normalize_chunks_nd (None , (100 ,))
0 commit comments