Skip to content

Commit 3c232a4

Browse files
committed
push into v2
1 parent 703e0e1 commit 3c232a4

File tree

7 files changed

+17
-20
lines changed

7 files changed

+17
-20
lines changed

src/zarr/api/asynchronous.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
_default_zarr_format,
2222
_warn_order_kwarg,
2323
_warn_write_empty_chunks_kwarg,
24-
parse_dtype,
2524
)
2625
from zarr.core.group import (
2726
AsyncGroup,
@@ -980,7 +979,7 @@ async def create(
980979
_handle_zarr_version_or_format(zarr_version=zarr_version, zarr_format=zarr_format)
981980
or _default_zarr_format()
982981
)
983-
dtype_wrapped = parse_dtype(dtype, zarr_format=zarr_format)
982+
dtype_wrapped = get_data_type_from_numpy(dtype)
984983
if zarr_format == 2:
985984
if chunks is None:
986985
chunks = shape

src/zarr/core/array.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
_default_zarr_format,
5959
_warn_order_kwarg,
6060
concurrent_map,
61-
parse_dtype,
6261
parse_order,
6362
parse_shapelike,
6463
product,
@@ -1034,7 +1033,7 @@ def compressors(self) -> tuple[numcodecs.abc.Codec, ...] | tuple[BytesBytesCodec
10341033
)
10351034

10361035
@property
1037-
def dtype(self) -> np.dtype[Any]:
1036+
def dtype(self) -> DTypeWrapper[Any, Any]:
10381037
"""Returns the data type of the array.
10391038
10401039
Returns
@@ -3918,7 +3917,7 @@ async def init_array(
39183917

39193918
from zarr.codecs.sharding import ShardingCodec, ShardingCodecIndexLocation
39203919

3921-
dtype_wrapped = parse_dtype(dtype, zarr_format=zarr_format)
3920+
dtype_wrapped = get_data_type_from_numpy(dtype)
39223921
shape_parsed = parse_shapelike(shape)
39233922
chunk_key_encoding_parsed = _parse_chunk_key_encoding(
39243923
chunk_key_encoding, zarr_format=zarr_format

src/zarr/core/buffer/cpu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def create(
151151
cls,
152152
*,
153153
shape: Iterable[int],
154-
dtype: DTypeWrapper[Any, Any],
154+
dtype: np.dtype[Any],
155155
order: Literal["C", "F"] = "C",
156156
fill_value: Any | None = None,
157157
) -> Self:
@@ -160,7 +160,7 @@ def create(
160160
else:
161161
return cls(
162162
np.full(
163-
shape=tuple(shape), fill_value=fill_value, dtype=dtype.unwrap(), order=order
163+
shape=tuple(shape), fill_value=fill_value, dtype=dtype, order=order
164164
)
165165
)
166166

src/zarr/core/common.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ def parse_bool(data: Any) -> bool:
166166
raise ValueError(f"Expected bool, got {data} instead.")
167167

168168

169-
def parse_dtype(dtype: Any, zarr_format: ZarrFormat) -> DTypeWrapper[Any, Any]:
170-
from zarr.registry import get_data_type_from_numpy
171-
172-
return get_data_type_from_numpy(np.dtype(dtype))
173-
174-
175169
def _warn_write_empty_chunks_kwarg() -> None:
176170
# TODO: link to docs page on array configuration in this message
177171
msg = (

src/zarr/core/metadata/v2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def __init__(
7575
"""
7676
shape_parsed = parse_shapelike(shape)
7777
chunks_parsed = parse_shapelike(chunks)
78-
78+
# TODO: remove this
79+
if not isinstance(dtype, DTypeWrapper):
80+
raise TypeError
7981
compressor_parsed = parse_compressor(compressor)
8082
order_parsed = parse_indexing_order(order)
8183
dimension_separator_parsed = parse_separator(dimension_separator)

src/zarr/core/metadata/v3.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44

55
from zarr.abc.metadata import Metadata
66
from zarr.core.buffer.core import default_buffer_prototype
7-
7+
from zarr.core.metadata.dtype import DTypeWrapper
88
if TYPE_CHECKING:
99
from collections.abc import Callable
1010
from typing import Self
1111

1212
from zarr.core.buffer import Buffer, BufferPrototype
1313
from zarr.core.chunk_grids import ChunkGrid
1414
from zarr.core.common import JSON, ChunkCoords
15-
from zarr.core.metadata.dtype import (
16-
DTypeWrapper,
17-
)
15+
1816

1917
import json
2018
from collections.abc import Iterable
@@ -262,6 +260,10 @@ def __init__(
262260
"""
263261
Because the class is a frozen dataclass, we set attributes using object.__setattr__
264262
"""
263+
264+
# TODO: remove this
265+
if not isinstance(data_type, DTypeWrapper):
266+
raise TypeError
265267
shape_parsed = parse_shapelike(shape)
266268
chunk_grid_parsed = ChunkGrid.from_dict(chunk_grid)
267269
chunk_key_encoding_parsed = ChunkKeyEncoding.from_dict(chunk_key_encoding)

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
_parse_chunk_key_encoding,
1919
)
2020
from zarr.core.chunk_grids import RegularChunkGrid, _auto_partition
21-
from zarr.core.common import JSON, parse_dtype, parse_shapelike
21+
from zarr.core.common import JSON, parse_shapelike
2222
from zarr.core.config import config as zarr_config
2323
from zarr.core.metadata.v2 import ArrayV2Metadata
2424
from zarr.core.metadata.v3 import ArrayV3Metadata
2525
from zarr.core.sync import sync
26+
from zarr.registry import get_data_type_from_numpy
2627
from zarr.storage import FsspecStore, LocalStore, MemoryStore, StorePath, ZipStore
2728

2829
if TYPE_CHECKING:
@@ -252,7 +253,7 @@ def create_array_metadata(
252253
"""
253254
Create array metadata
254255
"""
255-
dtype_parsed = parse_dtype(dtype, zarr_format=zarr_format)
256+
dtype_parsed = get_data_type_from_numpy(dtype)
256257
shape_parsed = parse_shapelike(shape)
257258
chunk_key_encoding_parsed = _parse_chunk_key_encoding(
258259
chunk_key_encoding, zarr_format=zarr_format

0 commit comments

Comments
 (0)