Skip to content

Commit 26e545a

Browse files
Resolves issue #2881 by removing partial codec initialization
1 parent 71a7768 commit 26e545a

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

src/zarr/codecs/blosc.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,25 @@ def parse_blocksize(data: JSON) -> int:
8787
class BloscCodec(BytesBytesCodec):
8888
is_fixed_size = False
8989

90-
typesize: int | None
90+
typesize: int
9191
cname: BloscCname = BloscCname.zstd
9292
clevel: int = 5
93-
shuffle: BloscShuffle | None = BloscShuffle.noshuffle
93+
shuffle: BloscShuffle
9494
blocksize: int = 0
9595

9696
def __init__(
9797
self,
9898
*,
99-
typesize: int | None = None,
99+
typesize: int,
100100
cname: BloscCname | str = BloscCname.zstd,
101101
clevel: int = 5,
102-
shuffle: BloscShuffle | str | None = None,
102+
shuffle: BloscShuffle | str,
103103
blocksize: int = 0,
104104
) -> None:
105-
typesize_parsed = parse_typesize(typesize) if typesize is not None else None
105+
typesize_parsed = parse_typesize(typesize)
106106
cname_parsed = parse_enum(cname, BloscCname)
107107
clevel_parsed = parse_clevel(clevel)
108-
shuffle_parsed = parse_enum(shuffle, BloscShuffle) if shuffle is not None else None
108+
shuffle_parsed = parse_enum(shuffle, BloscShuffle)
109109
blocksize_parsed = parse_blocksize(blocksize)
110110

111111
object.__setattr__(self, "typesize", typesize_parsed)
@@ -120,10 +120,6 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
120120
return cls(**configuration_parsed) # type: ignore[arg-type]
121121

122122
def to_dict(self) -> dict[str, JSON]:
123-
if self.typesize is None:
124-
raise ValueError("`typesize` needs to be set for serialization.")
125-
if self.shuffle is None:
126-
raise ValueError("`shuffle` needs to be set for serialization.")
127123
return {
128124
"name": "blosc",
129125
"configuration": {
@@ -141,17 +137,11 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
141137
if new_codec.typesize is None:
142138
new_codec = replace(new_codec, typesize=dtype.itemsize)
143139
if new_codec.shuffle is None:
144-
new_codec = replace(
145-
new_codec,
146-
shuffle=(BloscShuffle.bitshuffle if dtype.itemsize == 1 else BloscShuffle.shuffle),
147-
)
148-
140+
new_codec = replace(new_codec,shuffle=(BloscShuffle.bitshuffle if dtype.itemsize == 1 else BloscShuffle.shuffle),)
149141
return new_codec
150142

151143
@cached_property
152144
def _blosc_codec(self) -> Blosc:
153-
if self.shuffle is None:
154-
raise ValueError("`shuffle` needs to be set for decoding and encoding.")
155145
map_shuffle_str_to_int = {
156146
BloscShuffle.noshuffle: 0,
157147
BloscShuffle.shuffle: 1,

src/zarr/codecs/bytes.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,22 @@ class Endian(Enum):
3434
class BytesCodec(ArrayBytesCodec):
3535
is_fixed_size = True
3636

37-
endian: Endian | None
37+
endian: Endian
3838

39-
def __init__(self, *, endian: Endian | str | None = default_system_endian) -> None:
40-
endian_parsed = None if endian is None else parse_enum(endian, Endian)
39+
def __init__(self, *, endian: Endian | str = default_system_endian) -> None:
40+
endian_parsed = parse_enum(endian, Endian)
4141

4242
object.__setattr__(self, "endian", endian_parsed)
4343

4444
@classmethod
4545
def from_dict(cls, data: dict[str, JSON]) -> Self:
4646
_, configuration_parsed = parse_named_configuration(
47-
data, "bytes", require_configuration=False
47+
data, "bytes", require_configuration=True
4848
)
49-
configuration_parsed = configuration_parsed or {}
5049
return cls(**configuration_parsed) # type: ignore[arg-type]
5150

5251
def to_dict(self) -> dict[str, JSON]:
53-
if self.endian is None:
54-
return {"name": "bytes"}
55-
else:
56-
return {"name": "bytes", "configuration": {"endian": self.endian.value}}
52+
return {"name": "bytes", "configuration": {"endian": self.endian.value}}
5753

5854
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
5955
if array_spec.dtype.itemsize == 0:
@@ -104,7 +100,6 @@ async def _encode_single(
104100
assert isinstance(chunk_array, NDBuffer)
105101
if (
106102
chunk_array.dtype.itemsize > 1
107-
and self.endian is not None
108103
and self.endian != chunk_array.byteorder
109104
):
110105
# type-ignore is a numpy bug

0 commit comments

Comments
 (0)