File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 1+ Correct the target bytes number for auto-chunking when auto-sharding.
Original file line number Diff line number Diff line change @@ -62,6 +62,8 @@ def _guess_chunks(
6262 tuple[int, ...]
6363
6464 """
65+ if min_bytes >= max_bytes :
66+ raise ValueError (f"Cannot have more min_bytes ({ min_bytes } ) than max_bytes ({ max_bytes } )" )
6567 if isinstance (shape , int ):
6668 shape = (shape ,)
6769
@@ -264,7 +266,7 @@ def _auto_partition(
264266 else :
265267 if chunk_shape == "auto" :
266268 # aim for a 1MiB chunk
267- _chunks_out = _guess_chunks (array_shape , item_size , max_bytes = 1024 )
269+ _chunks_out = _guess_chunks (array_shape , item_size , max_bytes = 1048576 )
268270 else :
269271 _chunks_out = chunk_shape
270272
Original file line number Diff line number Diff line change @@ -1019,6 +1019,24 @@ def test_auto_partition_auto_shards(
10191019 assert auto_shards == expected_shards
10201020
10211021
1022+ def test_auto_partition_auto_shards_with_auto_chunks_should_be_close_to_1MiB () -> None :
1023+ """
1024+ Test that automatically picking a shard size and a chunk size gives roughly 1MiB chunks.
1025+ """
1026+ with pytest .warns (
1027+ ZarrUserWarning ,
1028+ match = "Automatic shard shape inference is experimental and may change without notice." ,
1029+ ):
1030+ with zarr .config .set ({"array.target_shard_size_bytes" : 10_000_000 }):
1031+ _ , chunk_shape = _auto_partition (
1032+ array_shape = (10_000_000 ,),
1033+ chunk_shape = "auto" ,
1034+ shard_shape = "auto" ,
1035+ item_size = 1 ,
1036+ )
1037+ assert chunk_shape == (625000 ,)
1038+
1039+
10221040def test_chunks_and_shards () -> None :
10231041 store = StorePath (MemoryStore ())
10241042 shape = (100 , 100 )
You can’t perform that action at this time.
0 commit comments