Skip to content

Commit

Permalink
rename base dtype, change type to kind
Browse files Browse the repository at this point in the history
  • Loading branch information
d-v-b committed Feb 26, 2025
1 parent d74e7a4 commit 5000dcb
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 105 deletions.
4 changes: 2 additions & 2 deletions src/zarr/core/_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec, BytesBytesCodec
from zarr.core.common import ZarrFormat
from zarr.core.metadata.dtype import BaseDataType
from zarr.core.metadata.dtype import DtypeBase

# from zarr.core.metadata.v3 import DataType

Expand Down Expand Up @@ -80,7 +80,7 @@ class ArrayInfo:

_type: Literal["Array"] = "Array"
_zarr_format: ZarrFormat
_data_type: np.dtype[Any] | BaseDataType
_data_type: np.dtype[Any] | DtypeBase
_shape: tuple[int, ...]
_shard_shape: tuple[int, ...] | None = None
_chunk_shape: tuple[int, ...] | None = None
Expand Down
12 changes: 6 additions & 6 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
ArrayV3MetadataDict,
T_ArrayMetadata,
)
from zarr.core.metadata.dtype import BaseDataType
from zarr.core.metadata.dtype import DtypeBase
from zarr.core.metadata.v2 import (
_default_compressor,
_default_filters,
Expand Down Expand Up @@ -679,7 +679,7 @@ def _create_metadata_v3(
"""

shape = parse_shapelike(shape)
codecs = list(codecs) if codecs is not None else _get_default_codecs(np.dtype(dtype))
codecs = list(codecs) if codecs is not None else _get_default_codecs(dtype)
chunk_key_encoding_parsed: ChunkKeyEncodingLike
if chunk_key_encoding is None:
chunk_key_encoding_parsed = {"name": "default", "separator": "/"}
Expand Down Expand Up @@ -1684,7 +1684,7 @@ async def info_complete(self) -> Any:
def _info(
self, count_chunks_initialized: int | None = None, count_bytes_stored: int | None = None
) -> Any:
_data_type: np.dtype[Any] | BaseDataType
_data_type: np.dtype[Any] | DtypeBase
if isinstance(self.metadata, ArrayV2Metadata):
_data_type = self.metadata.dtype
else:
Expand Down Expand Up @@ -4207,9 +4207,9 @@ def _get_default_chunk_encoding_v3(
"""
dtype = get_data_type_from_numpy(np_dtype)

default_filters = zarr_config.get("array.v3_default_filters").get(dtype.type)
default_serializer = zarr_config.get("array.v3_default_serializer").get(dtype.type)
default_compressors = zarr_config.get("array.v3_default_compressors").get(dtype.type)
default_filters = zarr_config.get("array.v3_default_filters").get(dtype.kind)
default_serializer = zarr_config.get("array.v3_default_serializer").get(dtype.kind)
default_compressors = zarr_config.get("array.v3_default_compressors").get(dtype.kind)

filters = tuple(_parse_array_array_codec(codec_dict) for codec_dict in default_filters)
serializer = _parse_array_bytes_codec(default_serializer)
Expand Down
9 changes: 1 addition & 8 deletions src/zarr/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import numpy as np

from zarr.core.config import config as zarr_config
from zarr.core.strings import _VLEN_STRING_DTYPE

if TYPE_CHECKING:
from collections.abc import Awaitable, Callable, Iterator
Expand Down Expand Up @@ -167,13 +166,7 @@ def parse_bool(data: Any) -> bool:
raise ValueError(f"Expected bool, got {data} instead.")


def parse_dtype(dtype: Any, zarr_format: ZarrFormat) -> np.dtype[Any]:
if dtype is str or dtype == "str":
if zarr_format == 2:
# special case as object
return np.dtype("object")
else:
return _VLEN_STRING_DTYPE
def parse_dtype(dtype: Any) -> np.dtype[Any]:
return np.dtype(dtype)


Expand Down
Loading

0 comments on commit 5000dcb

Please sign in to comment.