Skip to content

Commit acb6c25

Browse files
committed
remove codecchain
1 parent b36a2d4 commit acb6c25

File tree

2 files changed

+2
-182
lines changed

2 files changed

+2
-182
lines changed

src/zarr/core/codec_pipeline.py

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

3-
from dataclasses import dataclass, field
3+
from dataclasses import dataclass
44
from itertools import islice, pairwise
5-
from typing import TYPE_CHECKING, Any, TypeVar, cast
5+
from typing import TYPE_CHECKING, Any, TypeVar
66
from warnings import warn
77

88
from zarr.abc.codec import (
@@ -13,7 +13,6 @@
1313
BytesBytesCodec,
1414
Codec,
1515
CodecPipeline,
16-
SupportsSyncCodec,
1716
)
1817
from zarr.core.common import concurrent_map
1918
from zarr.core.config import config
@@ -69,106 +68,6 @@ def fill_value_or_default(chunk_spec: ArraySpec) -> Any:
6968
return fill_value
7069

7170

72-
@dataclass(frozen=True, slots=True)
73-
class CodecChain:
74-
"""Codec chain with pre-resolved metadata specs.
75-
76-
Constructed from an iterable of codecs and a chunk ArraySpec.
77-
Resolves each codec against the spec so that encode/decode can
78-
run without re-resolving.
79-
"""
80-
81-
codecs: tuple[Codec, ...]
82-
chunk_spec: ArraySpec
83-
84-
_aa_codecs: tuple[ArrayArrayCodec, ...] = field(init=False, repr=False, compare=False)
85-
_aa_specs: tuple[ArraySpec, ...] = field(init=False, repr=False, compare=False)
86-
_ab_codec: ArrayBytesCodec = field(init=False, repr=False, compare=False)
87-
_ab_spec: ArraySpec = field(init=False, repr=False, compare=False)
88-
_bb_codecs: tuple[BytesBytesCodec, ...] = field(init=False, repr=False, compare=False)
89-
_bb_spec: ArraySpec = field(init=False, repr=False, compare=False)
90-
_all_sync: bool = field(init=False, repr=False, compare=False)
91-
92-
def __post_init__(self) -> None:
93-
aa, ab, bb = codecs_from_list(list(self.codecs))
94-
95-
aa_specs: list[ArraySpec] = []
96-
spec = self.chunk_spec
97-
for aa_codec in aa:
98-
aa_specs.append(spec)
99-
spec = aa_codec.resolve_metadata(spec)
100-
101-
object.__setattr__(self, "_aa_codecs", aa)
102-
object.__setattr__(self, "_aa_specs", tuple(aa_specs))
103-
object.__setattr__(self, "_ab_codec", ab)
104-
object.__setattr__(self, "_ab_spec", spec)
105-
106-
spec = ab.resolve_metadata(spec)
107-
object.__setattr__(self, "_bb_codecs", bb)
108-
object.__setattr__(self, "_bb_spec", spec)
109-
110-
object.__setattr__(
111-
self,
112-
"_all_sync",
113-
all(isinstance(c, SupportsSyncCodec) for c in self.codecs),
114-
)
115-
116-
@property
117-
def all_sync(self) -> bool:
118-
return self._all_sync
119-
120-
def decode_chunk(
121-
self,
122-
chunk_bytes: Buffer,
123-
) -> NDBuffer:
124-
"""Decode a single chunk through the full codec chain, synchronously.
125-
126-
Pure compute -- no IO. Only callable when all codecs support sync.
127-
"""
128-
bb_out: Any = chunk_bytes
129-
for bb_codec in reversed(self._bb_codecs):
130-
bb_out = cast("SupportsSyncCodec", bb_codec)._decode_sync(bb_out, self._bb_spec)
131-
132-
ab_out: Any = cast("SupportsSyncCodec", self._ab_codec)._decode_sync(bb_out, self._ab_spec)
133-
134-
for aa_codec, spec in zip(reversed(self._aa_codecs), reversed(self._aa_specs), strict=True):
135-
ab_out = cast("SupportsSyncCodec", aa_codec)._decode_sync(ab_out, spec)
136-
137-
return ab_out # type: ignore[no-any-return]
138-
139-
def encode_chunk(
140-
self,
141-
chunk_array: NDBuffer,
142-
) -> Buffer | None:
143-
"""Encode a single chunk through the full codec chain, synchronously.
144-
145-
Pure compute -- no IO. Only callable when all codecs support sync.
146-
"""
147-
aa_out: Any = chunk_array
148-
149-
for aa_codec, spec in zip(self._aa_codecs, self._aa_specs, strict=True):
150-
if aa_out is None:
151-
return None
152-
aa_out = cast("SupportsSyncCodec", aa_codec)._encode_sync(aa_out, spec)
153-
154-
if aa_out is None:
155-
return None
156-
bb_out: Any = cast("SupportsSyncCodec", self._ab_codec)._encode_sync(aa_out, self._ab_spec)
157-
158-
for bb_codec in self._bb_codecs:
159-
if bb_out is None:
160-
return None
161-
bb_out = cast("SupportsSyncCodec", bb_codec)._encode_sync(bb_out, self._bb_spec)
162-
163-
return bb_out # type: ignore[no-any-return]
164-
165-
def compute_encoded_size(self, byte_length: int, array_spec: ArraySpec) -> int:
166-
for codec in self.codecs:
167-
byte_length = codec.compute_encoded_size(byte_length, array_spec)
168-
array_spec = codec.resolve_metadata(array_spec)
169-
return byte_length
170-
171-
17271
@dataclass(frozen=True)
17372
class BatchedCodecPipeline(CodecPipeline):
17473
"""Default codec pipeline.

tests/test_sync_codec_pipeline.py

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)