@@ -277,6 +277,69 @@ async def test_getitem_consolidated(self, v2_consolidated_metadata):
277
277
assert air .metadata .shape == (730 ,)
278
278
279
279
280
+ @pytest .mark .parametrize ("dtype_str" , ["datetime64[s]" , "timedelta64[ms]" ])
281
+ def test_parse_v2_fill_value_nat_integer (dtype_str : str ) -> None :
282
+ """Verify parsing V2 metadata where NaT is stored as its int64 representation."""
283
+ nat_int_repr = np .iinfo (np .int64 ).min # -9223372036854775808
284
+ dtype = np .dtype (dtype_str )
285
+ metadata_dict = {
286
+ "zarr_format" : 2 ,
287
+ "shape" : (10 ,),
288
+ "chunks" : (5 ,),
289
+ "dtype" : dtype .str ,
290
+ "compressor" : None ,
291
+ "filters" : None ,
292
+ "fill_value" : nat_int_repr ,
293
+ "order" : "C" ,
294
+ }
295
+ meta = ArrayV2Metadata .from_dict (metadata_dict )
296
+ assert np .isnat (meta .fill_value )
297
+ assert meta .fill_value .dtype .kind == dtype .kind
298
+
299
+
300
+ @pytest .mark .parametrize ("dtype_str" , ["datetime64[s]" , "timedelta64[ms]" ])
301
+ def test_parse_v2_fill_value_nat_string (dtype_str : str ) -> None :
302
+ """Verify parsing V2 metadata where NaT is stored as the string 'NaT'."""
303
+ dtype = np .dtype (dtype_str )
304
+ metadata_dict = {
305
+ "zarr_format" : 2 ,
306
+ "shape" : (10 ,),
307
+ "chunks" : (5 ,),
308
+ "dtype" : dtype .str ,
309
+ "compressor" : None ,
310
+ "filters" : None ,
311
+ "fill_value" : "NaT" ,
312
+ "order" : "C" ,
313
+ }
314
+ meta = ArrayV2Metadata .from_dict (metadata_dict )
315
+ assert np .isnat (meta .fill_value )
316
+ assert meta .fill_value .dtype .kind == dtype .kind
317
+
318
+
319
+ @pytest .mark .parametrize ("dtype_str" , ["datetime64[s]" , "timedelta64[ms]" ])
320
+ def test_parse_v2_fill_value_non_nat (dtype_str : str ) -> None :
321
+ """Verify parsing V2 metadata with a non-NaT datetime/timedelta fill value."""
322
+ dtype = np .dtype (dtype_str )
323
+ # Use a valid integer representation for the dtype
324
+ # Note: zarr v2 serializes non-NaT datetimes/timedeltas as integers
325
+ fill_value_int = 1234567890 if dtype .kind == "M" else 12345
326
+ expected_value = np .array (fill_value_int , dtype = dtype )[()]
327
+
328
+ metadata_dict = {
329
+ "zarr_format" : 2 ,
330
+ "shape" : (10 ,),
331
+ "chunks" : (5 ,),
332
+ "dtype" : dtype .str ,
333
+ "compressor" : None ,
334
+ "filters" : None ,
335
+ "fill_value" : fill_value_int ,
336
+ "order" : "C" ,
337
+ }
338
+ meta = ArrayV2Metadata .from_dict (metadata_dict )
339
+ assert meta .fill_value == expected_value
340
+ assert meta .fill_value .dtype == dtype
341
+
342
+
280
343
def test_from_dict_extra_fields () -> None :
281
344
data = {
282
345
"_nczarr_array" : {"dimrefs" : ["/dim1" , "/dim2" ], "storage" : "chunked" },
0 commit comments