@@ -257,6 +257,7 @@ def update_attributes(self, attributes: dict[str, JSON]) -> Self:
257257FLOAT = np .float16 | np .float32 | np .float64
258258COMPLEX_DTYPE = np .dtypes .Complex64DType | np .dtypes .Complex128DType
259259COMPLEX = np .complex64 | np .complex128
260+ DATETIME_DTYPE = np .dtypes .DateTime64DType
260261
261262
262263@overload
@@ -275,6 +276,10 @@ def parse_fill_value(fill_value: object, dtype: FLOAT_DTYPE) -> FLOAT: ...
275276def parse_fill_value (fill_value : object , dtype : COMPLEX_DTYPE ) -> COMPLEX : ...
276277
277278
279+ @overload
280+ def parse_fill_value (fill_value : object , dtype : DATETIME_DTYPE ) -> DATETIME_DTYPE : ...
281+
282+
278283@overload
279284def parse_fill_value (fill_value : object , dtype : np .dtype [Any ]) -> Any :
280285 # This dtype[Any] is unfortunately necessary right now.
@@ -314,7 +319,7 @@ def parse_fill_value(
314319 if fill_value is None :
315320 return dtype .type (0 )
316321 if isinstance (fill_value , Sequence ) and not isinstance (fill_value , str ):
317- if dtype in (np .complex64 , np .complex128 ):
322+ if dtype . type in (np .complex64 , np .complex128 ):
318323 dtype = cast (COMPLEX_DTYPE , dtype )
319324 if len (fill_value ) == 2 :
320325 # complex datatypes serialize to JSON arrays with two elements
@@ -328,7 +333,12 @@ def parse_fill_value(
328333 raise ValueError (msg )
329334 msg = f"Cannot parse non-string sequence { fill_value } as a scalar with type { dtype } ."
330335 raise TypeError (msg )
331- return dtype .type (fill_value ) # type: ignore[arg-type]
336+ if np .issubdtype (dtype , np .datetime64 ):
337+ if TYPE_CHECKING :
338+ assert isinstance (dtype .type , np .datetime64 )
339+ return dtype .type (fill_value , np .datetime_data (dtype )) # type: ignore[unreachable]
340+ else :
341+ return dtype .type (fill_value ) # type: ignore[arg-type]
332342
333343
334344# For type checking
0 commit comments