@@ -281,3 +281,42 @@ class TestUInt64(BaseTestZDType):
281281 )
282282 invalid_scalar_params = ((UInt64 (), {"set!" }), (UInt64 (), ("tuple" ,)))
283283 item_size_params = (UInt64 (),)
284+
285+
286+ def test_check_json_intish_str () -> None :
287+ """Test the check_json_intish_str function."""
288+ from zarr .core .dtype .npy .common import check_json_intish_str
289+
290+ # Test valid string integers
291+ assert check_json_intish_str ("0" )
292+ assert check_json_intish_str ("42" )
293+ assert check_json_intish_str ("-5" )
294+ assert check_json_intish_str ("123" )
295+
296+ # Test invalid cases
297+ assert not check_json_intish_str ("3.14" )
298+ assert not check_json_intish_str ("not_a_number" )
299+ assert not check_json_intish_str ("" )
300+ assert not check_json_intish_str (42 ) # actual int, not string
301+ assert not check_json_intish_str (3.14 ) # float
302+ assert not check_json_intish_str (None )
303+
304+
305+ def test_string_integer_from_json_scalar () -> None :
306+ """Test that string representations of integers can be parsed by from_json_scalar."""
307+ # Test the specific reproducer case
308+ dtype_instance = Int32 ()
309+ result = dtype_instance .from_json_scalar ("0" , zarr_format = 3 )
310+ assert result == np .int32 (0 )
311+ assert isinstance (result , np .int32 )
312+
313+ # Test other cases
314+ result = dtype_instance .from_json_scalar ("42" , zarr_format = 3 )
315+ assert result == np .int32 (42 )
316+
317+ result = dtype_instance .from_json_scalar ("-5" , zarr_format = 3 )
318+ assert result == np .int32 (- 5 )
319+
320+ # Test that it works for v2 format too
321+ result = dtype_instance .from_json_scalar ("123" , zarr_format = 2 )
322+ assert result == np .int32 (123 )
0 commit comments