Skip to content

Commit 05dd0d8

Browse files
committed
add dtype parsing, and tweak auto_partitioning func
1 parent 489e2a2 commit 05dd0d8

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/zarr/api/asynchronous.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ChunkCoords,
1919
MemoryOrder,
2020
ZarrFormat,
21+
parse_dtype,
2122
)
2223
from zarr.core.config import config
2324
from zarr.core.group import AsyncGroup, ConsolidatedMetadata, GroupMetadata
@@ -972,7 +973,7 @@ async def create_array(
972973

973974
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
974975
sub_codecs = (*filters, BytesCodec(), *compressors)
975-
976+
_dtype_parsed = parse_dtype(dtype, zarr_format=zarr_format)
976977
if zarr_format == 2:
977978
if shard_shape is not None or shard_shape != "auto":
978979
msg = (
@@ -988,7 +989,7 @@ async def create_array(
988989
return await AsyncArray._create_v2(
989990
store_path=store_path,
990991
shape=shape,
991-
dtype=dtype,
992+
dtype=_dtype_parsed,
992993
chunks=chunk_shape,
993994
dimension_separator="/",
994995
fill_value=fill_value,
@@ -1018,7 +1019,7 @@ async def create_array(
10181019
return await AsyncArray._create_v3(
10191020
store_path=store_path,
10201021
shape=shape,
1021-
dtype=dtype,
1022+
dtype=_dtype_parsed,
10221023
fill_value=fill_value,
10231024
attributes=attributes,
10241025
chunk_shape=chunks_out,

src/zarr/core/chunk_grids.py

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

31+
3032
def _guess_chunks(
3133
shape: ShapeLike,
3234
typesize: int,
@@ -144,7 +146,6 @@ def normalize_chunks(chunks: Any, shape: tuple[int, ...], typesize: int) -> tupl
144146
return tuple(int(c) for c in chunks)
145147

146148

147-
148149
def _auto_partition(
149150
shape: tuple[int, ...],
150151
dtype: npt.DTypeLike,
@@ -170,12 +171,13 @@ def _auto_partition(
170171
else:
171172
if chunk_shape == "auto":
172173
# aim for a 1MiB chunk
173-
_chunks_out = _guess_chunks(shape, item_size, max_bytes=1024**2)
174+
_chunks_out = _guess_chunks(shape, item_size, max_bytes=1024)
174175
else:
175176
_chunks_out = chunk_shape
177+
176178
if shard_shape == "auto":
177179
# TODO: fix me! this should be capped at some sane shard shape
178-
_shards_out = tuple(c * 8 for c in _chunks_out)
180+
_shards_out = tuple(c * 2 for c in _chunks_out)
179181
else:
180182
_shards_out = shard_shape
181183

0 commit comments

Comments
 (0)