Skip to content

Commit 2d5a84e

Browse files
committed
make codec_pipeline a cached property of sharding codec
1 parent 6755488 commit 2d5a84e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/zarr/codecs/sharding.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from collections.abc import Iterable, Mapping, MutableMapping
44
from dataclasses import dataclass, field, replace
55
from enum import Enum
6-
from functools import lru_cache
6+
from functools import cached_property, lru_cache
77
from operator import itemgetter
88
from typing import TYPE_CHECKING, Any, NamedTuple
99

@@ -329,6 +329,10 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
329329
_, configuration_parsed = parse_named_configuration(data, "sharding_indexed")
330330
return cls(**configuration_parsed) # type: ignore[arg-type]
331331

332+
@cached_property
333+
def codec_pipeline(self) -> BatchedCodecPipeline:
334+
return BatchedCodecPipeline.from_list(self.codecs)
335+
332336
def to_dict(self) -> dict[str, JSON]:
333337
return {
334338
"name": "sharding_indexed",
@@ -393,7 +397,7 @@ async def _decode_single(
393397
return out
394398

395399
# decoding chunks and writing them into the output buffer
396-
await BatchedCodecPipeline.from_list(self.codecs).read(
400+
await self.codec_pipeline.read(
397401
[
398402
(
399403
_ShardingByteGetter(shard_dict, chunk_coords),
@@ -461,7 +465,7 @@ async def _decode_partial_single(
461465
shard_dict[chunk_coords] = chunk_bytes
462466

463467
# decoding chunks and writing them into the output buffer
464-
await BatchedCodecPipeline.from_list(self.codecs).read(
468+
await self.codec_pipeline.read(
465469
[
466470
(
467471
_ShardingByteGetter(shard_dict, chunk_coords),
@@ -495,7 +499,7 @@ async def _encode_single(
495499

496500
shard_builder = _ShardBuilder.create_empty(chunks_per_shard)
497501

498-
await BatchedCodecPipeline.from_list(self.codecs).write(
502+
await self.codec_pipeline.write(
499503
[
500504
(
501505
_ShardingByteSetter(shard_builder, chunk_coords),
@@ -538,7 +542,7 @@ async def _encode_partial_single(
538542
)
539543
)
540544

541-
await BatchedCodecPipeline.from_list(self.codecs).write(
545+
await self.codec_pipeline.write(
542546
[
543547
(
544548
_ShardingByteSetter(shard_dict, chunk_coords),

0 commit comments

Comments
 (0)