@@ -167,3 +167,47 @@ class TestFloat64(_BaseTestFloat):
167167        ("0x3ff0000000000000" , 1.0 ),
168168    )
169169    item_size_params  =  (Float64 (),)
170+ 
171+ 
172+ def  test_check_json_floatish_str () ->  None :
173+     """Test the check_json_floatish_str function.""" 
174+     from  zarr .core .dtype .npy .common  import  check_json_floatish_str 
175+ 
176+     # Test valid string floats 
177+     assert  check_json_floatish_str ("3.14" )
178+     assert  check_json_floatish_str ("0.0" )
179+     assert  check_json_floatish_str ("-2.5" )
180+     assert  check_json_floatish_str ("1.0" )
181+ 
182+     # Test invalid cases 
183+     assert  not  check_json_floatish_str ("not_a_number" )
184+     assert  not  check_json_floatish_str ("" )
185+     assert  not  check_json_floatish_str (3.14 )  # actual float, not string 
186+     assert  not  check_json_floatish_str (42 )  # int 
187+     assert  not  check_json_floatish_str (None )
188+ 
189+     # Test that special cases still work via float() conversion 
190+     # (these will be handled by existing functions first in practice) 
191+     assert  check_json_floatish_str ("NaN" )
192+     assert  check_json_floatish_str ("Infinity" )
193+     assert  check_json_floatish_str ("-Infinity" )
194+ 
195+ 
196+ def  test_string_float_from_json_scalar () ->  None :
197+     """Test that string representations of floats can be parsed by from_json_scalar.""" 
198+     # Test with Float32 
199+     dtype_instance  =  Float32 ()
200+     result  =  dtype_instance .from_json_scalar ("3.14" , zarr_format = 3 )
201+     assert  abs (result  -  np .float32 (3.14 )) <  1e-6 
202+     assert  isinstance (result , np .float32 )
203+ 
204+     # Test other cases 
205+     result  =  dtype_instance .from_json_scalar ("0.0" , zarr_format = 3 )
206+     assert  result  ==  np .float32 (0.0 )
207+ 
208+     result  =  dtype_instance .from_json_scalar ("-2.5" , zarr_format = 3 )
209+     assert  result  ==  np .float32 (- 2.5 )
210+ 
211+     # Test that it works for v2 format too 
212+     result  =  dtype_instance .from_json_scalar ("1.5" , zarr_format = 2 )
213+     assert  result  ==  np .float32 (1.5 )
0 commit comments