@@ -246,19 +246,18 @@ def _datetime(
246246 scalar ,
247247 match_fn = re .compile (r"\s*(?P<year>\d+)-(?P<month>\d+)-(?P<day>\d+)\s*$" ).match ,
248248 ) -> Optional [numpy .datetime64 ]:
249- if isinstance (scalar , numpy .datetime64 ):
250- return scalar
251-
252249 # Convert pyarrow values to datetime.date.
253250 if isinstance (scalar , (pyarrow .Date32Scalar , pyarrow .Date64Scalar )):
254251 scalar = scalar .as_py ()
255252
256253 if pandas .isna (scalar ):
257254 return numpy .datetime64 ("NaT" )
255+ elif isinstance (scalar , numpy .datetime64 ):
256+ dateObj = pandas .Timestamp (scalar )
258257 elif isinstance (scalar , datetime .date ):
259- return pandas .Timestamp (
258+ dateObj = pandas .Timestamp (
260259 year = scalar .year , month = scalar .month , day = scalar .day
261- ). to_datetime64 ()
260+ )
262261 elif isinstance (scalar , str ):
263262 match = match_fn (scalar )
264263 if not match :
@@ -272,14 +271,16 @@ def _datetime(
272271 month = month ,
273272 day = day ,
274273 )
275- if pandas .Timestamp .min < dateObj < pandas .Timestamp .max :
276- return dateObj .to_datetime64 ()
277- else : # pragma: NO COVER
278- # TODO(#166): Include these lines in coverage when pandas 2.0 is released.
279- raise OutOfBoundsDatetime ("Out of bounds" , scalar ) # pragma: NO COVER
280274 else :
281275 raise TypeError ("Invalid value type" , scalar )
282276
277+ # TODO(#64): Support larger ranges with other units.
278+ if pandas .Timestamp .min < dateObj < pandas .Timestamp .max :
279+ return dateObj .to_datetime64 ()
280+ else : # pragma: NO COVER
281+ # TODO(#166): Include these lines in coverage when pandas 2.0 is released.
282+ raise OutOfBoundsDatetime ("Out of bounds" , scalar ) # pragma: NO COVER
283+
283284 def _box_func (self , x ):
284285 if pandas .isna (x ):
285286 return pandas .NaT
0 commit comments