@@ -31,14 +31,15 @@ def endianness_to_numpy_str(endianness: Endianness | None) -> Literal[">", "<",
3131 )
3232
3333
34- def check_str (data : JSON ) -> TypeGuard [bool ]:
34+ def check_json_bool (data : JSON ) -> TypeGuard [bool ]:
3535 return bool (isinstance (data , bool ))
3636
37+ def check_json_str (data : JSON ) -> TypeGuard [str ]:
38+ return bool (isinstance (data , str ))
3739
38- def check_int (data : JSON ) -> TypeGuard [int ]:
40+ def check_json_int (data : JSON ) -> TypeGuard [int ]:
3941 return bool (isinstance (data , int ))
4042
41-
4243def check_json_float (data : JSON ) -> TypeGuard [float ]:
4344 if data == "NaN" or data == "Infinity" or data == "-Infinity" :
4445 return True
@@ -56,10 +57,6 @@ def check_json_complex_float(data: JSON) -> TypeGuard[tuple[JSONFloat, JSONFloat
5657 )
5758
5859
59- def check_str (data : JSON ) -> TypeGuard [str ]:
60- return bool (isinstance (data , str ))
61-
62-
6360def float_to_json_v2 (data : float | np .floating [Any ]) -> JSONFloat :
6461 if np .isnan (data ):
6562 return "NaN"
@@ -221,7 +218,7 @@ def to_json_value(self, data: np.generic, zarr_format: ZarrFormat) -> bool:
221218 def from_json_value (
222219 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
223220 ) -> np .bool_ :
224- if check_str (data ):
221+ if check_json_bool (data ):
225222 return self .to_numpy (endianness = endianness ).type (data )
226223 raise TypeError (f"Invalid type: { data } . Expected a boolean." )
227224
@@ -246,7 +243,7 @@ def to_json_value(self, data: np.generic, zarr_format: ZarrFormat) -> int:
246243 def from_json_value (
247244 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
248245 ) -> np .int8 :
249- if check_int (data ):
246+ if check_json_int (data ):
250247 return self .to_numpy (endianness = endianness ).type (data )
251248 raise TypeError (f"Invalid type: { data } . Expected an integer." )
252249
@@ -271,7 +268,7 @@ def to_json_value(self, data: np.generic, zarr_format: ZarrFormat) -> int:
271268 def from_json_value (
272269 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
273270 ) -> np .uint8 :
274- if check_int (data ):
271+ if check_json_int (data ):
275272 return self .to_numpy (endianness = endianness ).type (data )
276273 raise TypeError (f"Invalid type: { data } . Expected an integer." )
277274
@@ -296,7 +293,7 @@ def to_json_value(self, data: np.generic, zarr_format: ZarrFormat) -> int:
296293 def from_json_value (
297294 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
298295 ) -> np .int16 :
299- if check_int (data ):
296+ if check_json_int (data ):
300297 return self .to_numpy (endianness = endianness ).type (data )
301298 raise TypeError (f"Invalid type: { data } . Expected an integer." )
302299
@@ -321,7 +318,7 @@ def to_json_value(self, data: np.generic, zarr_format: ZarrFormat) -> int:
321318 def from_json_value (
322319 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
323320 ) -> np .uint16 :
324- if check_int (data ):
321+ if check_json_int (data ):
325322 return self .to_numpy (endianness = endianness ).type (data )
326323 raise TypeError (f"Invalid type: { data } . Expected an integer." )
327324
@@ -346,7 +343,7 @@ def to_json_value(self, data: np.generic, zarr_format: ZarrFormat) -> int:
346343 def from_json_value (
347344 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
348345 ) -> np .int32 :
349- if check_int (data ):
346+ if check_json_int (data ):
350347 return self .to_numpy (endianness = endianness ).type (data )
351348 raise TypeError (f"Invalid type: { data } . Expected an integer." )
352349
@@ -371,7 +368,7 @@ def to_json_value(self, data: np.generic, zarr_format: ZarrFormat) -> int:
371368 def from_json_value (
372369 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
373370 ) -> np .uint32 :
374- if check_int (data ):
371+ if check_json_int (data ):
375372 return self .to_numpy (endianness = endianness ).type (data )
376373 raise TypeError (f"Invalid type: { data } . Expected an integer." )
377374
@@ -396,7 +393,7 @@ def to_json_value(self, data: np.generic, zarr_format: ZarrFormat) -> int:
396393 def from_json_value (
397394 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
398395 ) -> np .int64 :
399- if check_int (data ):
396+ if check_json_int (data ):
400397 return self .to_numpy (endianness = endianness ).type (data )
401398 raise TypeError (f"Invalid type: { data } . Expected an integer." )
402399
@@ -421,7 +418,7 @@ def to_json_value(self, data: np.generic, zarr_format: ZarrFormat) -> int:
421418 def from_json_value (
422419 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
423420 ) -> np .uint64 :
424- if check_int (data ):
421+ if check_json_int (data ):
425422 return self .to_numpy (endianness = endianness ).type (data )
426423 raise TypeError (f"Invalid type: { data } . Expected an integer." )
427424
@@ -592,7 +589,7 @@ def to_json_value(
592589 def from_json_value (
593590 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
594591 ) -> np .bytes_ :
595- if check_str (data ):
592+ if check_json_bool (data ):
596593 return self .to_numpy (endianness = endianness ).type (data .encode ("ascii" ))
597594 raise TypeError (f"Invalid type: { data } . Expected a string." )
598595
@@ -722,7 +719,7 @@ def to_json_value(self, data: np.generic, *, zarr_format: ZarrFormat) -> str:
722719 def from_json_value (
723720 self , data : JSON , * , zarr_format : ZarrFormat , endianness : Endianness | None = None
724721 ) -> np .str_ :
725- if not check_str (data ):
722+ if not check_json_bool (data ):
726723 raise TypeError (f"Invalid type: { data } . Expected a string." )
727724 return self .to_numpy (endianness = endianness ).type (data )
728725
0 commit comments