27
27
import asyncio
28
28
import math
29
29
from dataclasses import dataclass , replace
30
- from functools import cached_property
31
30
from typing import (
32
31
TYPE_CHECKING ,
33
32
Any ,
83
82
84
83
# Configuration classes for codec parameters
85
84
class LZ4Config (TypedDict ):
86
- acceleration : NotRequired [ int ]
85
+ acceleration : int
87
86
88
87
89
88
class ZlibConfig (TypedDict ):
90
- level : NotRequired [ int ]
89
+ level : int
91
90
92
91
93
92
class BZ2Config (TypedDict ):
94
- level : NotRequired [ int ]
93
+ level : int
95
94
96
95
97
96
class LZMAConfig (TypedDict ):
98
- format : NotRequired [ int ]
99
- check : NotRequired [ int ]
100
- preset : NotRequired [ int ]
101
- filters : NotRequired [ list [dict [str , Any ]]]
97
+ format : int
98
+ check : int
99
+ preset : int | None
100
+ filters : list [dict [str , Any ]] | None
102
101
103
102
104
103
class ShuffleConfig (TypedDict ):
105
- elementsize : NotRequired [ int ]
104
+ elementsize : int
106
105
107
106
108
107
class LZ4JSON_V2 (LZ4Config ):
@@ -158,7 +157,7 @@ class ShuffleJSON_V3(NamedRequiredConfig[Literal["shuffle"], ShuffleConfig]):
158
157
# Array-to-array codec configuration classes
159
158
class DeltaConfig (TypedDict ):
160
159
dtype : str
161
- astype : NotRequired [ str ]
160
+ astype : str
162
161
163
162
164
163
class BitRoundConfig (TypedDict ):
@@ -183,7 +182,7 @@ class PackBitsConfig(TypedDict):
183
182
184
183
class AsTypeConfig (TypedDict ):
185
184
encode_dtype : str
186
- decode_dtype : NotRequired [ str ]
185
+ decode_dtype : str
187
186
188
187
189
188
# Array-to-array codec JSON representations
@@ -364,18 +363,16 @@ def _warn_unstable_specification(obj: _NumcodecsCodec) -> None:
364
363
class _NumcodecsCodec :
365
364
codec_name : str
366
365
_codec_id : ClassVar [str ]
366
+ _codec : Numcodec
367
367
codec_config : Mapping [str , Any ]
368
368
369
369
def __init__ (self , ** codec_config : Any ) -> None :
370
- object .__setattr__ (self , "codec_config" , codec_config )
370
+ object .__setattr__ (self , "_codec" , get_numcodec ({"id" : self ._codec_id , ** codec_config })) # type: ignore[typeddict-item]
371
+ object .__setattr__ (self , "codec_config" , self ._codec .get_config ())
371
372
372
373
def to_dict (self ) -> dict [str , JSON ]:
373
374
return cast (dict [str , JSON ], self .to_json (zarr_format = 3 ))
374
375
375
- @cached_property
376
- def _codec (self ) -> Numcodec :
377
- return get_numcodec ({"id" : self ._codec_id , ** self .codec_config }) # type: ignore[typeddict-item]
378
-
379
376
@classmethod
380
377
def _from_json_v2 (cls , data : CodecJSON_V2 ) -> Self :
381
378
return cls (** data )
0 commit comments