@@ -246,19 +246,18 @@ def _datetime(
246
246
scalar ,
247
247
match_fn = re .compile (r"\s*(?P<year>\d+)-(?P<month>\d+)-(?P<day>\d+)\s*$" ).match ,
248
248
) -> Optional [numpy .datetime64 ]:
249
- if isinstance (scalar , numpy .datetime64 ):
250
- return scalar
251
-
252
249
# Convert pyarrow values to datetime.date.
253
250
if isinstance (scalar , (pyarrow .Date32Scalar , pyarrow .Date64Scalar )):
254
251
scalar = scalar .as_py ()
255
252
256
253
if pandas .isna (scalar ):
257
254
return numpy .datetime64 ("NaT" )
255
+ elif isinstance (scalar , numpy .datetime64 ):
256
+ dateObj = pandas .Timestamp (scalar )
258
257
elif isinstance (scalar , datetime .date ):
259
- return pandas .Timestamp (
258
+ dateObj = pandas .Timestamp (
260
259
year = scalar .year , month = scalar .month , day = scalar .day
261
- ). to_datetime64 ()
260
+ )
262
261
elif isinstance (scalar , str ):
263
262
match = match_fn (scalar )
264
263
if not match :
@@ -272,14 +271,16 @@ def _datetime(
272
271
month = month ,
273
272
day = day ,
274
273
)
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
280
274
else :
281
275
raise TypeError ("Invalid value type" , scalar )
282
276
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
+
283
284
def _box_func (self , x ):
284
285
if pandas .isna (x ):
285
286
return pandas .NaT
0 commit comments