Skip to content

Commit 41e72eb

Browse files
committed
lint
1 parent 6c44c4e commit 41e72eb

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

numcodecs/zarr3.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@
2929
import math
3030
from dataclasses import dataclass, replace
3131
from functools import cached_property
32+
from importlib.metadata import version
3233
from typing import Any, Self
3334
from warnings import warn
3435

3536
import numpy as np
3637
from packaging.version import Version
37-
from importlib.metadata import version
38+
3839
import numcodecs
3940

4041
try:
41-
import zarr
42+
import zarr # noqa: F401
4243

4344
if Version(version('zarr')) < Version("3.0.0"): # pragma: no cover
4445
raise ImportError("zarr 3.0.0 or later is required to use the numcodecs zarr integration.")
@@ -56,6 +57,7 @@
5657

5758
CODEC_PREFIX = "numcodecs."
5859

60+
5961
def from_zarr_dtype(dtype: Any) -> np.dtype:
6062
"""
6163
Get a numpy data type from an array spec, depending on the zarr version.
@@ -64,12 +66,15 @@ def from_zarr_dtype(dtype: Any) -> np.dtype:
6466
return dtype.to_native_dtype()
6567
return dtype
6668

69+
6770
def to_zarr_dtype(dtype: np.dtype) -> Any:
6871
if Version(version('zarr')) >= Version("3.1.0"):
6972
from zarr.dtype import parse_data_type
70-
return parse_data_type(dtype)
73+
74+
return parse_data_type(dtype, zarr_format=3)
7175
return dtype
7276

77+
7378
def _expect_name_prefix(codec_name: str) -> str:
7479
if not codec_name.startswith(CODEC_PREFIX):
7580
raise ValueError(
@@ -247,8 +252,8 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Shuffle:
247252
class Delta(_NumcodecsArrayArrayCodec, codec_name="delta"):
248253
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
249254
if astype := self.codec_config.get("astype"):
250-
dtype = to_zarr_dtype(np.dtype(astype))
251-
return replace(chunk_spec, dtype=dtype) # type: ignore[call-overload]
255+
dtype = to_zarr_dtype(np.dtype(astype)) # type: ignore[call-overload]
256+
return replace(chunk_spec, dtype=dtype)
252257
return chunk_spec
253258

254259

@@ -259,8 +264,8 @@ class BitRound(_NumcodecsArrayArrayCodec, codec_name="bitround"):
259264
class FixedScaleOffset(_NumcodecsArrayArrayCodec, codec_name="fixedscaleoffset"):
260265
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
261266
if astype := self.codec_config.get("astype"):
262-
dtype = to_zarr_dtype(np.dtype(astype))
263-
return replace(chunk_spec, dtype=dtype) # type: ignore[call-overload]
267+
dtype = to_zarr_dtype(np.dtype(astype)) # type: ignore[call-overload]
268+
return replace(chunk_spec, dtype=dtype)
264269
return chunk_spec
265270

266271
def evolve_from_array_spec(self, array_spec: ArraySpec) -> FixedScaleOffset:
@@ -286,19 +291,19 @@ def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
286291
return replace(
287292
chunk_spec,
288293
shape=(1 + math.ceil(product(chunk_spec.shape) / 8),),
289-
dtype=np.dtype("uint8"),
294+
dtype=to_zarr_dtype(np.dtype("uint8")),
290295
)
291296

292-
def validate(self, *, dtype: np.dtype[Any], **_kwargs) -> None:
297+
def validate(self, *, dtype: np.dtype[Any], **_kwargs) -> None: # type: ignore[override]
293298
_dtype = from_zarr_dtype(dtype)
294299
if _dtype != np.dtype("bool"):
295300
raise ValueError(f"Packbits filter requires bool dtype. Got {dtype}.")
296301

297302

298303
class AsType(_NumcodecsArrayArrayCodec, codec_name="astype"):
299304
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
300-
dtype = to_zarr_dtype(np.dtype(self.codec_config["encode_dtype"]))
301-
return replace(chunk_spec, dtype=dtype) # type: ignore[arg-type]
305+
dtype = to_zarr_dtype(np.dtype(self.codec_config["encode_dtype"])) # type: ignore[arg-type]
306+
return replace(chunk_spec, dtype=dtype)
302307

303308
def evolve_from_array_spec(self, array_spec: ArraySpec) -> AsType:
304309
if self.codec_config.get("decode_dtype") is None:

0 commit comments

Comments
 (0)