@@ -496,7 +496,7 @@ def from_json_value(self, data: JSON, *, zarr_format: ZarrFormat) -> np.complex1
496496@dataclass (frozen = True , kw_only = True )
497497class FixedLengthAsciiString (DTypeWrapper [np .dtypes .BytesDType [Any ], np .bytes_ ]):
498498 dtype_cls = np .dtypes .BytesDType
499- _zarr_v3_name = "numpy.static_byte_string "
499+ _zarr_v3_name = "fixed_length_ascii "
500500 item_size_bits : ClassVar [int ] = 8
501501 length : int = 1
502502
@@ -523,20 +523,20 @@ def from_json_value(self, data: JSON, *, zarr_format: ZarrFormat) -> np.bytes_:
523523
524524
525525@dataclass (frozen = True , kw_only = True )
526- class FixedLengthBytes (DTypeWrapper [np .dtypes .VoidDType [ Any ] , np .void ]):
526+ class FixedLengthBytes (DTypeWrapper [np .dtypes .VoidDType , np .void ]):
527527 dtype_cls = np .dtypes .VoidDType
528528 _zarr_v3_name = "r*"
529529 item_size_bits : ClassVar [int ] = 8
530530 length : int = 1
531531
532532 @classmethod
533- def _from_dtype_unsafe (cls , dtype : np .dtypes .VoidDType [ Any ] ) -> Self :
533+ def _from_dtype_unsafe (cls , dtype : np .dtypes .VoidDType ) -> Self :
534534 return cls (length = dtype .itemsize // (cls .item_size_bits // 8 ))
535535
536536 def default_value (self ) -> np .void :
537537 return self .cast_value (("\x00 " * self .length ).encode ("ascii" ))
538538
539- def to_dtype (self ) -> np .dtypes .VoidDType [ Any ] :
539+ def to_dtype (self ) -> np .dtypes .VoidDType :
540540 # Numpy does not allow creating a void type
541541 # by invoking np.dtypes.VoidDType directly
542542 return np .dtype (f"V{ self .length } " )
@@ -577,7 +577,7 @@ def check_dict(cls, data: dict[str, JSON]) -> TypeGuard[dict[str, JSON]]:
577577 isinstance (data , dict )
578578 and "name" in data
579579 and isinstance (data ["name" ], str )
580- and re .match (r"^r\d+$" , data ["name" ])
580+ and ( re .match (r"^r\d+$" , data ["name" ]) is not None )
581581 )
582582
583583 def to_json_value (self , data : np .void , * , zarr_format : ZarrFormat ) -> str :
@@ -592,7 +592,7 @@ def from_json_value(self, data: JSON, *, zarr_format: ZarrFormat) -> np.void:
592592@dataclass (frozen = True , kw_only = True )
593593class FixedLengthUnicodeString (DTypeWrapper [np .dtypes .StrDType [int ], np .str_ ]):
594594 dtype_cls = np .dtypes .StrDType
595- _zarr_v3_name = "numpy.fixed_length_unicode_string "
595+ _zarr_v3_name = "fixed_length_ucs4 "
596596 item_size_bits : ClassVar [int ] = 32 # UCS4 is 32 bits per code point
597597 endianness : Endianness | None = "native"
598598 length : int = 1
@@ -605,7 +605,10 @@ def _from_dtype_unsafe(cls, dtype: np.dtypes.StrDType[int]) -> Self:
605605 )
606606
607607 def to_dtype (self ) -> np .dtypes .StrDType [int ]:
608- return self .dtype_cls (self .length ).newbyteorder (endianness_to_numpy_str (self .endianness ))
608+ return cast (
609+ np .dtypes .StrDType [int ],
610+ self .dtype_cls (self .length ).newbyteorder (endianness_to_numpy_str (self .endianness )),
611+ )
609612
610613 def default_value (self ) -> np .str_ :
611614 return np .str_ ("" )
@@ -627,7 +630,7 @@ def from_json_value(self, data: JSON, *, zarr_format: ZarrFormat) -> np.str_:
627630 @dataclass (frozen = True , kw_only = True )
628631 class VariableLengthString (DTypeWrapper [np .dtypes .StringDType , str ]):
629632 dtype_cls = np .dtypes .StringDType
630- _zarr_v3_name = "numpy.variable_length_string "
633+ _zarr_v3_name = "variable_length_utf8 "
631634
632635 @classmethod
633636 def _from_dtype_unsafe (cls , dtype : np .dtypes .StringDType ) -> Self :
@@ -658,14 +661,14 @@ def from_json_value(self, data: JSON, *, zarr_format: ZarrFormat) -> str:
658661 @dataclass (frozen = True , kw_only = True )
659662 class VariableLengthString (DTypeWrapper [np .dtypes .ObjectDType , str ]):
660663 dtype_cls = np .dtypes .ObjectDType
661- _zarr_v3_name = "numpy.variable_length_string "
664+ _zarr_v3_name = "variable_length_utf8 "
662665
663666 @classmethod
664667 def _from_dtype_unsafe (cls , dtype : np .dtypes .ObjectDType ) -> Self :
665668 return cls ()
666669
667670 def to_dtype (self ) -> np .dtypes .ObjectDType :
668- return self .dtype_cls ()
671+ return cast ( np . dtypes . ObjectDType , self .dtype_cls () )
669672
670673 def cast_value (self , value : object ) -> str :
671674 return str (value )
@@ -695,7 +698,7 @@ def from_json_value(self, data: JSON, *, zarr_format: ZarrFormat) -> str:
695698@dataclass (frozen = True , kw_only = True )
696699class DateTime64 (DTypeWrapper [np .dtypes .DateTime64DType , np .datetime64 ]):
697700 dtype_cls = np .dtypes .DateTime64DType
698- _zarr_v3_name = "numpy. datetime64"
701+ _zarr_v3_name = "datetime64"
699702 unit : DateUnit | TimeUnit = "s"
700703 endianness : Endianness = "native"
701704
@@ -713,7 +716,7 @@ def _from_dtype_unsafe(cls, dtype: np.dtypes.DateTime64DType) -> Self:
713716 return cls (unit = unit , endianness = endianness_from_numpy_str (dtype .byteorder ))
714717
715718 def cast_value (self , value : object ) -> np .datetime64 :
716- return self .to_dtype ().type (value , self .unit )
719+ return cast ( np . datetime64 , self .to_dtype ().type (value , self .unit ) )
717720
718721 def to_dtype (self ) -> np .dtypes .DateTime64DType :
719722 # Numpy does not allow creating datetime64 via
@@ -734,14 +737,14 @@ def to_json_value(self, data: np.datetime64, *, zarr_format: ZarrFormat) -> int:
734737@dataclass (frozen = True , kw_only = True )
735738class Structured (DTypeWrapper [np .dtypes .VoidDType , np .void ]):
736739 dtype_cls = np .dtypes .VoidDType
737- _zarr_v3_name = "numpy. structured"
740+ _zarr_v3_name = "structured"
738741 fields : tuple [tuple [str , DTypeWrapper [Any , Any ]], ...]
739742
740743 def default_value (self ) -> np .void :
741744 return self .cast_value (0 )
742745
743746 def cast_value (self , value : object ) -> np .void :
744- return np .array ([value ], dtype = self .to_dtype ())[0 ]
747+ return cast ( np .void , np . array ([value ], dtype = self .to_dtype ())[0 ])
745748
746749 @classmethod
747750 def check_dtype (cls , dtype : np .dtypes .DTypeLike ) -> TypeGuard [np .dtypes .VoidDType ]:
@@ -787,7 +790,7 @@ def to_dict(self) -> dict[str, JSON]:
787790 return base_dict
788791
789792 @classmethod
790- def check_dict (cls , data : JSON ) -> bool :
793+ def check_dict (cls , data : JSON ) -> TypeGuard [ JSON ] :
791794 return (
792795 isinstance (data , dict )
793796 and "name" in data
0 commit comments