@@ -47,7 +47,6 @@ from datetime cimport (
4747 npy_datetime,
4848 is_leapyear,
4949 dayofweek,
50- check_dts_bounds,
5150 PANDAS_FR_ns,
5251 PyDateTime_Check, PyDate_Check,
5352 PyDateTime_IMPORT,
@@ -58,6 +57,9 @@ from datetime cimport (
5857from datetime import timedelta, datetime
5958from datetime import time as datetime_time
6059
60+ from tslibs.np_datetime cimport check_dts_bounds
61+ from tslibs.np_datetime import OutOfBoundsDatetime
62+
6163from khash cimport (
6264 khiter_t,
6365 kh_destroy_int64, kh_put_int64,
@@ -732,7 +734,7 @@ class Timestamp(_Timestamp):
732734 ts = convert_datetime_to_tsobject(ts_input, _tzinfo)
733735 value = ts.value + (dts.ps // 1000 )
734736 if value != NPY_NAT:
735- _check_dts_bounds (& dts)
737+ check_dts_bounds (& dts)
736738
737739 return create_timestamp_from_ts(value, dts, _tzinfo, self .freq)
738740
@@ -1645,7 +1647,7 @@ cdef convert_to_tsobject(object ts, object tz, object unit,
16451647 ' Timestamp' .format(ts, type (ts)))
16461648
16471649 if obj.value != NPY_NAT:
1648- _check_dts_bounds (& obj.dts)
1650+ check_dts_bounds (& obj.dts)
16491651
16501652 if tz is not None :
16511653 _localize_tso(obj, tz)
@@ -1726,7 +1728,7 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz,
17261728 obj.value += nanos
17271729 obj.dts.ps = nanos * 1000
17281730
1729- _check_dts_bounds (& obj.dts)
1731+ check_dts_bounds (& obj.dts)
17301732 return obj
17311733
17321734
@@ -1762,12 +1764,12 @@ cpdef convert_str_to_tsobject(object ts, object tz, object unit,
17621764 _string_to_dts(ts, & obj.dts, & out_local, & out_tzoffset)
17631765 obj.value = pandas_datetimestruct_to_datetime(
17641766 PANDAS_FR_ns, & obj.dts)
1765- _check_dts_bounds (& obj.dts)
1767+ check_dts_bounds (& obj.dts)
17661768 if out_local == 1 :
17671769 obj.tzinfo = pytz.FixedOffset(out_tzoffset)
17681770 obj.value = tz_convert_single(obj.value, obj.tzinfo, ' UTC' )
17691771 if tz is None :
1770- _check_dts_bounds (& obj.dts)
1772+ check_dts_bounds (& obj.dts)
17711773 return obj
17721774 else :
17731775 # Keep the converter same as PyDateTime's
@@ -1810,7 +1812,7 @@ def _test_parse_iso8601(object ts):
18101812
18111813 _string_to_dts(ts, & obj.dts, & out_local, & out_tzoffset)
18121814 obj.value = pandas_datetimestruct_to_datetime(PANDAS_FR_ns, & obj.dts)
1813- _check_dts_bounds (& obj.dts)
1815+ check_dts_bounds (& obj.dts)
18141816 if out_local == 1 :
18151817 obj.tzinfo = pytz.FixedOffset(out_tzoffset)
18161818 obj.value = tz_convert_single(obj.value, obj.tzinfo, ' UTC' )
@@ -1897,18 +1899,6 @@ cpdef inline object _localize_pydatetime(object dt, object tz):
18971899 return dt.replace(tzinfo = tz)
18981900
18991901
1900- class OutOfBoundsDatetime (ValueError ):
1901- pass
1902-
1903- cdef inline _check_dts_bounds(pandas_datetimestruct * dts):
1904- if check_dts_bounds(dts):
1905- fmt = ' %d -%.2d -%.2d %.2d :%.2d :%.2d ' % (dts.year, dts.month,
1906- dts.day, dts.hour,
1907- dts.min, dts.sec)
1908- raise OutOfBoundsDatetime(
1909- ' Out of bounds nanosecond timestamp: %s ' % fmt)
1910-
1911-
19121902def datetime_to_datetime64 (ndarray[object] values ):
19131903 cdef:
19141904 Py_ssize_t i, n = len (values)
@@ -1933,13 +1923,13 @@ def datetime_to_datetime64(ndarray[object] values):
19331923
19341924 _ts = convert_datetime_to_tsobject(val, None )
19351925 iresult[i] = _ts.value
1936- _check_dts_bounds (& _ts.dts)
1926+ check_dts_bounds (& _ts.dts)
19371927 else :
19381928 if inferred_tz is not None :
19391929 raise ValueError (' Cannot mix tz-aware with '
19401930 ' tz-naive values' )
19411931 iresult[i] = _pydatetime_to_dts(val, & dts)
1942- _check_dts_bounds (& dts)
1932+ check_dts_bounds (& dts)
19431933 else :
19441934 raise TypeError (' Unrecognized value type: %s ' % type (val))
19451935
@@ -2252,7 +2242,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
22522242 _ts = convert_datetime_to_tsobject(val, None )
22532243 iresult[i] = _ts.value
22542244 try :
2255- _check_dts_bounds (& _ts.dts)
2245+ check_dts_bounds (& _ts.dts)
22562246 except ValueError :
22572247 if is_coerce:
22582248 iresult[i] = NPY_NAT
@@ -2267,7 +2257,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
22672257 if is_timestamp(val):
22682258 iresult[i] += val.nanosecond
22692259 try :
2270- _check_dts_bounds (& dts)
2260+ check_dts_bounds (& dts)
22712261 except ValueError :
22722262 if is_coerce:
22732263 iresult[i] = NPY_NAT
@@ -2277,7 +2267,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
22772267 elif PyDate_Check(val):
22782268 iresult[i] = _date_to_datetime64(val, & dts)
22792269 try :
2280- _check_dts_bounds (& dts)
2270+ check_dts_bounds (& dts)
22812271 seen_datetime = 1
22822272 except ValueError :
22832273 if is_coerce:
@@ -2334,7 +2324,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
23342324 tz = pytz.FixedOffset(out_tzoffset)
23352325 value = tz_convert_single(value, tz, ' UTC' )
23362326 iresult[i] = value
2337- _check_dts_bounds (& dts)
2327+ check_dts_bounds (& dts)
23382328 except ValueError :
23392329 # if requiring iso8601 strings, skip trying other formats
23402330 if require_iso8601:
@@ -2433,7 +2423,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
24332423 oresult[i] = parse_datetime_string(val, dayfirst = dayfirst,
24342424 yearfirst = yearfirst)
24352425 _pydatetime_to_dts(oresult[i], & dts)
2436- _check_dts_bounds (& dts)
2426+ check_dts_bounds (& dts)
24372427 except Exception :
24382428 if is_raise:
24392429 raise
@@ -3239,7 +3229,7 @@ cdef inline _get_datetime64_nanos(object val):
32393229
32403230 if unit != PANDAS_FR_ns:
32413231 pandas_datetime_to_datetimestruct(ival, unit, & dts)
3242- _check_dts_bounds (& dts)
3232+ check_dts_bounds (& dts)
32433233 return pandas_datetimestruct_to_datetime(PANDAS_FR_ns, & dts)
32443234 else :
32453235 return ival
@@ -3267,7 +3257,7 @@ def cast_to_nanoseconds(ndarray arr):
32673257 if ivalues[i] != NPY_NAT:
32683258 pandas_datetime_to_datetimestruct(ivalues[i], unit, & dts)
32693259 iresult[i] = pandas_datetimestruct_to_datetime(PANDAS_FR_ns, & dts)
3270- _check_dts_bounds (& dts)
3260+ check_dts_bounds (& dts)
32713261 else :
32723262 iresult[i] = NPY_NAT
32733263
0 commit comments