Skip to content

Commit 489e2a2

Browse files
committed
make logic of _auto_partition better for shard shape
1 parent 215ff96 commit 489e2a2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/zarr/core/chunk_grids.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
if TYPE_CHECKING:
2626
from collections.abc import Iterator
2727
from typing import Self
28-
28+
import numpy.typing as npt
2929

3030
def _guess_chunks(
3131
shape: ShapeLike,
@@ -144,8 +144,6 @@ def normalize_chunks(chunks: Any, shape: tuple[int, ...], typesize: int) -> tupl
144144
return tuple(int(c) for c in chunks)
145145

146146

147-
import numpy.typing as npt
148-
149147

150148
def _auto_partition(
151149
shape: tuple[int, ...],
@@ -170,14 +168,17 @@ def _auto_partition(
170168
else:
171169
_chunks_out = chunk_shape
172170
else:
173-
if shard_shape == "auto":
174-
_shards_out = _guess_chunks(shape, item_size)
175-
else:
176-
_shards_out = shard_shape
177171
if chunk_shape == "auto":
178-
_chunks_out = _guess_chunks(_shards_out, item_size)
172+
# aim for a 1MiB chunk
173+
_chunks_out = _guess_chunks(shape, item_size, max_bytes=1024**2)
179174
else:
180175
_chunks_out = chunk_shape
176+
if shard_shape == "auto":
177+
# TODO: fix me! this should be capped at some sane shard shape
178+
_shards_out = tuple(c * 8 for c in _chunks_out)
179+
else:
180+
_shards_out = shard_shape
181+
181182
return _shards_out, _chunks_out
182183

183184

0 commit comments

Comments
 (0)