Skip to content

Commit 4013237

Browse files
authored
Merge branch 'main' into chore/bytes-dtype
2 parents 1e83a9b + ee0e69a commit 4013237

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

changes/3603.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Correct the target bytes number for auto-chunking when auto-sharding.

src/zarr/core/chunk_grids.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

tests/test_array.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
10221040
def test_chunks_and_shards() -> None:
10231041
store = StorePath(MemoryStore())
10241042
shape = (100, 100)

0 commit comments

Comments
 (0)