Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/3251.fix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure that all abstract methods of ``ZDType`` raise a ``NotImplementedError`` when invoked.
24 changes: 12 additions & 12 deletions src/zarr/core/dtype/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ def from_native_dtype(cls: type[Self], dtype: TBaseDType) -> Self:
"""
Create a ZDType instance from a native data type.

The base implementation first performs a type check via ``cls._check_native_dtype``.
If that type check succeeds, the ZDType class instance is created.

This method is used when taking a user-provided native data type, like a NumPy data type,
and creating the corresponding ZDType instance from them.

Expand All @@ -123,7 +120,7 @@ def from_native_dtype(cls: type[Self], dtype: TBaseDType) -> Self:
TypeError
If the native data type is not consistent with the wrapped data type.
"""
...
raise NotImplementedError # pragma: no cover

@abstractmethod
def to_native_dtype(self: Self) -> TDType_co:
Expand All @@ -135,15 +132,17 @@ def to_native_dtype(self: Self) -> TDType_co:
TDType
The native data type wrapped by this ZDType.
"""
...
raise NotImplementedError # pragma: no cover

@classmethod
@abstractmethod
def _from_json_v2(cls: type[Self], data: DTypeJSON) -> Self: ...
def _from_json_v2(cls: type[Self], data: DTypeJSON) -> Self:
raise NotImplementedError # pragma: no cover

@classmethod
@abstractmethod
def _from_json_v3(cls: type[Self], data: DTypeJSON) -> Self: ...
def _from_json_v3(cls: type[Self], data: DTypeJSON) -> Self:
raise NotImplementedError # pragma: no cover

@classmethod
def from_json(cls: type[Self], data: DTypeJSON, *, zarr_format: ZarrFormat) -> Self:
Expand Down Expand Up @@ -190,7 +189,7 @@ def to_json(self, zarr_format: ZarrFormat) -> DTypeSpec_V2 | DTypeSpec_V3:
DTypeJSON_V2 | DTypeJSON_V3
The JSON-serializable representation of the wrapped data type
"""
...
raise NotImplementedError # pragma: no cover

@abstractmethod
def _check_scalar(self, data: object) -> bool:
Expand All @@ -207,7 +206,7 @@ def _check_scalar(self, data: object) -> bool:
Bool
True if the object is valid, False otherwise.
"""
...
raise NotImplementedError # pragma: no cover

@abstractmethod
def cast_scalar(self, data: object) -> TScalar_co:
Expand All @@ -227,6 +226,7 @@ def cast_scalar(self, data: object) -> TScalar_co:
TScalar
The cast value.
"""
raise NotImplementedError # pragma: no cover

@abstractmethod
def default_scalar(self) -> TScalar_co:
Expand All @@ -242,7 +242,7 @@ def default_scalar(self) -> TScalar_co:
TScalar
The default value for this data type.
"""
...
raise NotImplementedError # pragma: no cover

@abstractmethod
def from_json_scalar(self: Self, data: JSON, *, zarr_format: ZarrFormat) -> TScalar_co:
Expand All @@ -262,7 +262,7 @@ def from_json_scalar(self: Self, data: JSON, *, zarr_format: ZarrFormat) -> TSca
TScalar
The deserialized scalar value.
"""
...
raise NotImplementedError # pragma: no cover

@abstractmethod
def to_json_scalar(self, data: object, *, zarr_format: ZarrFormat) -> JSON:
Expand All @@ -285,7 +285,7 @@ def to_json_scalar(self, data: object, *, zarr_format: ZarrFormat) -> JSON:
JSON
The JSON-serialized scalar.
"""
...
raise NotImplementedError # pragma: no cover


def scalar_failed_type_check_msg(
Expand Down
Loading