@@ -47,7 +47,6 @@ from datetime cimport (
47
47
npy_datetime,
48
48
is_leapyear,
49
49
dayofweek,
50
- check_dts_bounds,
51
50
PANDAS_FR_ns,
52
51
PyDateTime_Check, PyDate_Check,
53
52
PyDateTime_IMPORT,
@@ -58,6 +57,9 @@ from datetime cimport (
58
57
from datetime import timedelta, datetime
59
58
from datetime import time as datetime_time
60
59
60
+ from tslibs.np_datetime cimport check_dts_bounds
61
+ from tslibs.np_datetime import OutOfBoundsDatetime
62
+
61
63
from khash cimport (
62
64
khiter_t,
63
65
kh_destroy_int64, kh_put_int64,
@@ -732,7 +734,7 @@ class Timestamp(_Timestamp):
732
734
ts = convert_datetime_to_tsobject(ts_input, _tzinfo)
733
735
value = ts.value + (dts.ps // 1000 )
734
736
if value != NPY_NAT:
735
- _check_dts_bounds (& dts)
737
+ check_dts_bounds (& dts)
736
738
737
739
return create_timestamp_from_ts(value, dts, _tzinfo, self .freq)
738
740
@@ -1645,7 +1647,7 @@ cdef convert_to_tsobject(object ts, object tz, object unit,
1645
1647
' Timestamp' .format(ts, type (ts)))
1646
1648
1647
1649
if obj.value != NPY_NAT:
1648
- _check_dts_bounds (& obj.dts)
1650
+ check_dts_bounds (& obj.dts)
1649
1651
1650
1652
if tz is not None :
1651
1653
_localize_tso(obj, tz)
@@ -1726,7 +1728,7 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz,
1726
1728
obj.value += nanos
1727
1729
obj.dts.ps = nanos * 1000
1728
1730
1729
- _check_dts_bounds (& obj.dts)
1731
+ check_dts_bounds (& obj.dts)
1730
1732
return obj
1731
1733
1732
1734
@@ -1762,12 +1764,12 @@ cpdef convert_str_to_tsobject(object ts, object tz, object unit,
1762
1764
_string_to_dts(ts, & obj.dts, & out_local, & out_tzoffset)
1763
1765
obj.value = pandas_datetimestruct_to_datetime(
1764
1766
PANDAS_FR_ns, & obj.dts)
1765
- _check_dts_bounds (& obj.dts)
1767
+ check_dts_bounds (& obj.dts)
1766
1768
if out_local == 1 :
1767
1769
obj.tzinfo = pytz.FixedOffset(out_tzoffset)
1768
1770
obj.value = tz_convert_single(obj.value, obj.tzinfo, ' UTC' )
1769
1771
if tz is None :
1770
- _check_dts_bounds (& obj.dts)
1772
+ check_dts_bounds (& obj.dts)
1771
1773
return obj
1772
1774
else :
1773
1775
# Keep the converter same as PyDateTime's
@@ -1810,7 +1812,7 @@ def _test_parse_iso8601(object ts):
1810
1812
1811
1813
_string_to_dts(ts, & obj.dts, & out_local, & out_tzoffset)
1812
1814
obj.value = pandas_datetimestruct_to_datetime(PANDAS_FR_ns, & obj.dts)
1813
- _check_dts_bounds (& obj.dts)
1815
+ check_dts_bounds (& obj.dts)
1814
1816
if out_local == 1 :
1815
1817
obj.tzinfo = pytz.FixedOffset(out_tzoffset)
1816
1818
obj.value = tz_convert_single(obj.value, obj.tzinfo, ' UTC' )
@@ -1897,18 +1899,6 @@ cpdef inline object _localize_pydatetime(object dt, object tz):
1897
1899
return dt.replace(tzinfo = tz)
1898
1900
1899
1901
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
-
1912
1902
def datetime_to_datetime64 (ndarray[object] values ):
1913
1903
cdef:
1914
1904
Py_ssize_t i, n = len (values)
@@ -1933,13 +1923,13 @@ def datetime_to_datetime64(ndarray[object] values):
1933
1923
1934
1924
_ts = convert_datetime_to_tsobject(val, None )
1935
1925
iresult[i] = _ts.value
1936
- _check_dts_bounds (& _ts.dts)
1926
+ check_dts_bounds (& _ts.dts)
1937
1927
else :
1938
1928
if inferred_tz is not None :
1939
1929
raise ValueError (' Cannot mix tz-aware with '
1940
1930
' tz-naive values' )
1941
1931
iresult[i] = _pydatetime_to_dts(val, & dts)
1942
- _check_dts_bounds (& dts)
1932
+ check_dts_bounds (& dts)
1943
1933
else :
1944
1934
raise TypeError (' Unrecognized value type: %s ' % type (val))
1945
1935
@@ -2252,7 +2242,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
2252
2242
_ts = convert_datetime_to_tsobject(val, None )
2253
2243
iresult[i] = _ts.value
2254
2244
try :
2255
- _check_dts_bounds (& _ts.dts)
2245
+ check_dts_bounds (& _ts.dts)
2256
2246
except ValueError :
2257
2247
if is_coerce:
2258
2248
iresult[i] = NPY_NAT
@@ -2267,7 +2257,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
2267
2257
if is_timestamp(val):
2268
2258
iresult[i] += val.nanosecond
2269
2259
try :
2270
- _check_dts_bounds (& dts)
2260
+ check_dts_bounds (& dts)
2271
2261
except ValueError :
2272
2262
if is_coerce:
2273
2263
iresult[i] = NPY_NAT
@@ -2277,7 +2267,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
2277
2267
elif PyDate_Check(val):
2278
2268
iresult[i] = _date_to_datetime64(val, & dts)
2279
2269
try :
2280
- _check_dts_bounds (& dts)
2270
+ check_dts_bounds (& dts)
2281
2271
seen_datetime = 1
2282
2272
except ValueError :
2283
2273
if is_coerce:
@@ -2334,7 +2324,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
2334
2324
tz = pytz.FixedOffset(out_tzoffset)
2335
2325
value = tz_convert_single(value, tz, ' UTC' )
2336
2326
iresult[i] = value
2337
- _check_dts_bounds (& dts)
2327
+ check_dts_bounds (& dts)
2338
2328
except ValueError :
2339
2329
# if requiring iso8601 strings, skip trying other formats
2340
2330
if require_iso8601:
@@ -2433,7 +2423,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
2433
2423
oresult[i] = parse_datetime_string(val, dayfirst = dayfirst,
2434
2424
yearfirst = yearfirst)
2435
2425
_pydatetime_to_dts(oresult[i], & dts)
2436
- _check_dts_bounds (& dts)
2426
+ check_dts_bounds (& dts)
2437
2427
except Exception :
2438
2428
if is_raise:
2439
2429
raise
@@ -3239,7 +3229,7 @@ cdef inline _get_datetime64_nanos(object val):
3239
3229
3240
3230
if unit != PANDAS_FR_ns:
3241
3231
pandas_datetime_to_datetimestruct(ival, unit, & dts)
3242
- _check_dts_bounds (& dts)
3232
+ check_dts_bounds (& dts)
3243
3233
return pandas_datetimestruct_to_datetime(PANDAS_FR_ns, & dts)
3244
3234
else :
3245
3235
return ival
@@ -3267,7 +3257,7 @@ def cast_to_nanoseconds(ndarray arr):
3267
3257
if ivalues[i] != NPY_NAT:
3268
3258
pandas_datetime_to_datetimestruct(ivalues[i], unit, & dts)
3269
3259
iresult[i] = pandas_datetimestruct_to_datetime(PANDAS_FR_ns, & dts)
3270
- _check_dts_bounds (& dts)
3260
+ check_dts_bounds (& dts)
3271
3261
else :
3272
3262
iresult[i] = NPY_NAT
3273
3263
0 commit comments