6161 _check_codecjson_v2 ,
6262 product ,
6363)
64- from zarr .dtype import UInt8 , ZDType , parse_dtype
64+ from zarr .dtype import UInt8 , ZDType
6565from zarr .errors import ZarrUserWarning
6666from zarr .registry import get_numcodec
6767
7575 from zarr .codecs .zstd import ZstdConfig_V3 , ZstdJSON_V2 , ZstdJSON_V3
7676 from zarr .core .array_spec import ArraySpec
7777 from zarr .core .buffer import Buffer , BufferPrototype , NDBuffer
78- from zarr .core .dtype .common import DTypeSpec_V2 , DTypeSpec_V3
7978
8079
8180# TypedDict definitions for V2 and V3 JSON representations
@@ -159,20 +158,6 @@ class BitRoundConfig(TypedDict):
159158 keepbits : int
160159
161160
162- class FixedScaleOffsetConfig_V2 (TypedDict ):
163- dtype : NotRequired [DTypeSpec_V2 ]
164- astype : NotRequired [DTypeSpec_V2 ]
165- scale : NotRequired [float ]
166- offset : NotRequired [float ]
167-
168-
169- class FixedScaleOffsetConfig_V3 (TypedDict ):
170- dtype : NotRequired [DTypeSpec_V3 ]
171- astype : NotRequired [DTypeSpec_V2 ]
172- scale : NotRequired [float ]
173- offset : NotRequired [float ]
174-
175-
176161class QuantizeConfig (TypedDict ):
177162 digits : int
178163 dtype : NotRequired [str ]
@@ -182,11 +167,6 @@ class PackBitsConfig(TypedDict):
182167 pass # PackBits has no configuration parameters
183168
184169
185- class AsTypeConfig (TypedDict ):
186- encode_dtype : str
187- decode_dtype : str
188-
189-
190170class BitRoundJSON_V2 (BitRoundConfig ):
191171 """JSON representation of BitRound codec for Zarr V2."""
192172
@@ -197,18 +177,6 @@ class BitRoundJSON_V3(NamedRequiredConfig[Literal["bitround"], BitRoundConfig]):
197177 """JSON representation of BitRound codec for Zarr V3."""
198178
199179
200- class FixedScaleOffsetJSON_V2 (FixedScaleOffsetConfig_V2 ):
201- """JSON representation of FixedScaleOffset codec for Zarr V2."""
202-
203- id : ReadOnly [Literal ["fixedscaleoffset" ]]
204-
205-
206- class FixedScaleOffsetJSON_V3 (
207- NamedRequiredConfig [Literal ["fixedscaleoffset" ], FixedScaleOffsetConfig_V3 ]
208- ):
209- """JSON representation of FixedScaleOffset codec for Zarr V3."""
210-
211-
212180class QuantizeJSON_V2 (QuantizeConfig ):
213181 """JSON representation of Quantize codec for Zarr V2."""
214182
@@ -229,16 +197,6 @@ class PackBitsJSON_V3(NamedRequiredConfig[Literal["packbits"], PackBitsConfig]):
229197 """JSON representation of PackBits codec for Zarr V3."""
230198
231199
232- class AsTypeJSON_V2 (AsTypeConfig ):
233- """JSON representation of AsType codec for Zarr V2."""
234-
235- id : ReadOnly [Literal ["astype" ]]
236-
237-
238- class AsTypeJSON_V3 (NamedRequiredConfig [Literal ["astype" ], AsTypeConfig ]):
239- """JSON representation of AsType codec for Zarr V3."""
240-
241-
242200# Checksum codec JSON representations
243201class Crc32Config (TypedDict ):
244202 """Configuration parameters for CRC32 codec."""
@@ -601,32 +559,6 @@ def to_json(self, zarr_format: ZarrFormat) -> BitRoundJSON_V2 | BitRoundJSON_V3:
601559 return super ().to_json (zarr_format ) # type: ignore[return-value]
602560
603561
604- class FixedScaleOffset (_NumcodecsArrayArrayCodec ):
605- codec_name = "numcodecs.fixedscaleoffset"
606- _codec_id = "fixedscaleoffset"
607- codec_config : FixedScaleOffsetConfig_V2
608-
609- @overload
610- def to_json (self , zarr_format : Literal [2 ]) -> FixedScaleOffsetJSON_V2 : ...
611- @overload
612- def to_json (self , zarr_format : Literal [3 ]) -> FixedScaleOffsetJSON_V3 : ...
613- def to_json (self , zarr_format : ZarrFormat ) -> FixedScaleOffsetJSON_V2 | FixedScaleOffsetJSON_V3 :
614- _warn_unstable_specification (self )
615- return super ().to_json (zarr_format ) # type: ignore[return-value]
616-
617- def resolve_metadata (self , chunk_spec : ArraySpec ) -> ArraySpec :
618- if astype := self .codec_config .get ("astype" ):
619- dtype = parse_dtype (np .dtype (astype ), zarr_format = 3 ) # type: ignore[arg-type]
620- return replace (chunk_spec , dtype = dtype )
621- return chunk_spec
622-
623- def evolve_from_array_spec (self , array_spec : ArraySpec ) -> Self :
624- if self .codec_config .get ("dtype" ) is None :
625- dtype = array_spec .dtype .to_native_dtype ()
626- return type (self )(** {** self .codec_config , "dtype" : str (dtype )})
627- return self
628-
629-
630562class Quantize (_NumcodecsArrayArrayCodec ):
631563 codec_name = "numcodecs.quantize"
632564 _codec_id = "quantize"
@@ -676,31 +608,6 @@ def validate(self, *, dtype: ZDType[Any, Any], **_kwargs: Any) -> None:
676608 raise ValueError (f"Packbits filter requires bool dtype. Got { dtype } ." )
677609
678610
679- class AsType (_NumcodecsArrayArrayCodec ):
680- codec_name = "numcodecs.astype"
681- _codec_id = "astype"
682- codec_config : AsTypeConfig
683-
684- @overload
685- def to_json (self , zarr_format : Literal [2 ]) -> AsTypeJSON_V2 : ...
686- @overload
687- def to_json (self , zarr_format : Literal [3 ]) -> AsTypeJSON_V3 : ...
688- def to_json (self , zarr_format : ZarrFormat ) -> AsTypeJSON_V2 | AsTypeJSON_V3 :
689- _warn_unstable_specification (self )
690- return super ().to_json (zarr_format ) # type: ignore[return-value]
691-
692- def resolve_metadata (self , chunk_spec : ArraySpec ) -> ArraySpec :
693- dtype = parse_dtype (np .dtype (self .codec_config ["encode_dtype" ]), zarr_format = 3 )
694- return replace (chunk_spec , dtype = dtype )
695-
696- def evolve_from_array_spec (self , array_spec : ArraySpec ) -> AsType :
697- if self .codec_config .get ("decode_dtype" ) is None :
698- # TODO: remove these coverage exemptions the correct way, i.e. with tests
699- dtype = array_spec .dtype .to_native_dtype () # pragma: no cover
700- return AsType (** {** self .codec_config , "decode_dtype" : str (dtype )}) # pragma: no cover
701- return self
702-
703-
704611# bytes-to-bytes checksum codecs
705612class _NumcodecsChecksumCodec (_NumcodecsBytesBytesCodec ):
706613 def compute_encoded_size (self , input_byte_length : int , chunk_spec : ArraySpec ) -> int :
0 commit comments