diff --git a/src/zarr/codecs/blosc.py b/src/zarr/codecs/blosc.py index 2fcc041a6b..15869ebfde 100644 --- a/src/zarr/codecs/blosc.py +++ b/src/zarr/codecs/blosc.py @@ -87,25 +87,25 @@ def parse_blocksize(data: JSON) -> int: class BloscCodec(BytesBytesCodec): is_fixed_size = False - typesize: int | None + typesize: int cname: BloscCname = BloscCname.zstd clevel: int = 5 - shuffle: BloscShuffle | None = BloscShuffle.noshuffle + shuffle: BloscShuffle blocksize: int = 0 def __init__( self, *, - typesize: int | None = None, + typesize: int, cname: BloscCname | str = BloscCname.zstd, clevel: int = 5, - shuffle: BloscShuffle | str | None = None, + shuffle: BloscShuffle | str, blocksize: int = 0, ) -> None: - typesize_parsed = parse_typesize(typesize) if typesize is not None else None + typesize_parsed = parse_typesize(typesize) cname_parsed = parse_enum(cname, BloscCname) clevel_parsed = parse_clevel(clevel) - shuffle_parsed = parse_enum(shuffle, BloscShuffle) if shuffle is not None else None + shuffle_parsed = parse_enum(shuffle, BloscShuffle) blocksize_parsed = parse_blocksize(blocksize) object.__setattr__(self, "typesize", typesize_parsed) @@ -120,10 +120,6 @@ def from_dict(cls, data: dict[str, JSON]) -> Self: return cls(**configuration_parsed) # type: ignore[arg-type] def to_dict(self) -> dict[str, JSON]: - if self.typesize is None: - raise ValueError("`typesize` needs to be set for serialization.") - if self.shuffle is None: - raise ValueError("`shuffle` needs to be set for serialization.") return { "name": "blosc", "configuration": { @@ -141,17 +137,11 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self: if new_codec.typesize is None: new_codec = replace(new_codec, typesize=dtype.itemsize) if new_codec.shuffle is None: - new_codec = replace( - new_codec, - shuffle=(BloscShuffle.bitshuffle if dtype.itemsize == 1 else BloscShuffle.shuffle), - ) - + new_codec = replace(new_codec,shuffle=(BloscShuffle.bitshuffle if dtype.itemsize == 1 else BloscShuffle.shuffle),) return new_codec @cached_property def _blosc_codec(self) -> Blosc: - if self.shuffle is None: - raise ValueError("`shuffle` needs to be set for decoding and encoding.") map_shuffle_str_to_int = { BloscShuffle.noshuffle: 0, BloscShuffle.shuffle: 1, diff --git a/src/zarr/codecs/bytes.py b/src/zarr/codecs/bytes.py index 78c7b22fbc..f223c39094 100644 --- a/src/zarr/codecs/bytes.py +++ b/src/zarr/codecs/bytes.py @@ -34,26 +34,22 @@ class Endian(Enum): class BytesCodec(ArrayBytesCodec): is_fixed_size = True - endian: Endian | None + endian: Endian - def __init__(self, *, endian: Endian | str | None = default_system_endian) -> None: - endian_parsed = None if endian is None else parse_enum(endian, Endian) + def __init__(self, *, endian: Endian | str = default_system_endian) -> None: + endian_parsed = parse_enum(endian, Endian) object.__setattr__(self, "endian", endian_parsed) @classmethod def from_dict(cls, data: dict[str, JSON]) -> Self: _, configuration_parsed = parse_named_configuration( - data, "bytes", require_configuration=False + data, "bytes", require_configuration=True ) - configuration_parsed = configuration_parsed or {} return cls(**configuration_parsed) # type: ignore[arg-type] def to_dict(self) -> dict[str, JSON]: - if self.endian is None: - return {"name": "bytes"} - else: - return {"name": "bytes", "configuration": {"endian": self.endian.value}} + return {"name": "bytes", "configuration": {"endian": self.endian.value}} def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self: if array_spec.dtype.itemsize == 0: @@ -104,7 +100,6 @@ async def _encode_single( assert isinstance(chunk_array, NDBuffer) if ( chunk_array.dtype.itemsize > 1 - and self.endian is not None and self.endian != chunk_array.byteorder ): # type-ignore is a numpy bug