@@ -30,6 +30,7 @@ from pandas._libs.tslibs.np_datetime cimport (
3030 NPY_DATETIMEUNIT,
3131 NPY_FR_ns,
3232 check_dts_bounds,
33+ get_datetime64_value,
3334 npy_datetimestruct,
3435 npy_datetimestruct_to_datetime,
3536 pandas_datetime_to_datetimestruct,
@@ -630,6 +631,8 @@ cpdef array_to_datetime(
630631 continue
631632 elif is_raise:
632633 raise
634+ if isinstance (ex, OutOfBoundsDatetime):
635+ return ignore_errors_out_of_bounds_fallback(values), tz_out
633636 return values, None
634637
635638 except TypeError :
@@ -654,6 +657,46 @@ cpdef array_to_datetime(
654657 return result, tz_out
655658
656659
660+ @ cython.wraparound (False )
661+ @ cython.boundscheck (False )
662+ cdef ndarray[object ] ignore_errors_out_of_bounds_fallback(ndarray[object ] values):
663+ """
664+ Fallback for array_to_datetime if an OutOfBoundsDatetime is raised
665+ and errors == "ignore"
666+
667+ Parameters
668+ ----------
669+ values : ndarray[object]
670+
671+ Returns
672+ -------
673+ ndarray[object]
674+ """
675+ cdef:
676+ Py_ssize_t i, n = len (values)
677+ object val
678+
679+ oresult = cnp.PyArray_EMPTY(values.ndim, values.shape, cnp.NPY_OBJECT, 0 )
680+
681+ for i in range (n):
682+ val = values[i]
683+
684+ # set as nan except if its a NaT
685+ if checknull_with_nat_and_na(val):
686+ if isinstance (val, float ):
687+ oresult[i] = np.nan
688+ else :
689+ oresult[i] = NaT
690+ elif is_datetime64_object(val):
691+ if get_datetime64_value(val) == NPY_NAT:
692+ oresult[i] = NaT
693+ else :
694+ oresult[i] = val.item()
695+ else :
696+ oresult[i] = val
697+ return oresult
698+
699+
657700@ cython.wraparound (False )
658701@ cython.boundscheck (False )
659702cdef _array_to_datetime_object(
0 commit comments