File tree 4 files changed +24
-14
lines changed
4 files changed +24
-14
lines changed Original file line number Diff line number Diff line change @@ -178,11 +178,15 @@ cpdef int64_t delta_to_nanoseconds(delta) except? -1:
178
178
if is_integer_object(delta):
179
179
return delta
180
180
if PyDelta_Check(delta):
181
- return (
182
- delta.days * 24 * 60 * 60 * 1 _000_000
183
- + delta.seconds * 1 _000_000
184
- + delta.microseconds
185
- ) * 1000
181
+ try :
182
+ return (
183
+ delta.days * 24 * 60 * 60 * 1 _000_000
184
+ + delta.seconds * 1 _000_000
185
+ + delta.microseconds
186
+ ) * 1000
187
+ except OverflowError as err:
188
+ from pandas._libs.tslibs.conversion import OutOfBoundsTimedelta
189
+ raise OutOfBoundsTimedelta(* err.args) from err
186
190
187
191
raise TypeError (type (delta))
188
192
@@ -246,7 +250,7 @@ cdef object ensure_td64ns(object ts):
246
250
td64_value = td64_value * mult
247
251
except OverflowError as err:
248
252
from pandas._libs.tslibs.conversion import OutOfBoundsTimedelta
249
- raise OutOfBoundsTimedelta(ts)
253
+ raise OutOfBoundsTimedelta(ts) from err
250
254
251
255
return np.timedelta64(td64_value, " ns" )
252
256
Original file line number Diff line number Diff line change 11
11
import pytest
12
12
13
13
from pandas .compat import is_numpy_dev
14
+ from pandas .errors import OutOfBoundsTimedelta
14
15
15
16
import pandas as pd
16
17
from pandas import (
@@ -104,7 +105,7 @@ def test_td_add_timestamp_overflow(self):
104
105
with pytest .raises (OverflowError , match = msg ):
105
106
Timestamp ("1700-01-01" ) + Timedelta (13 * 19999 , unit = "D" )
106
107
107
- with pytest .raises (OverflowError , match = msg ):
108
+ with pytest .raises (OutOfBoundsTimedelta , match = msg ):
108
109
Timestamp ("1700-01-01" ) + timedelta (days = 13 * 19999 )
109
110
110
111
@pytest .mark .parametrize ("op" , [operator .add , ops .radd ])
Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ def test_overflow_on_construction():
200
200
with pytest .raises (OverflowError , match = msg ):
201
201
Timedelta (7 * 19999 , unit = "D" )
202
202
203
- with pytest .raises (OverflowError , match = msg ):
203
+ with pytest .raises (OutOfBoundsTimedelta , match = msg ):
204
204
Timedelta (timedelta (days = 13 * 19999 ))
205
205
206
206
Original file line number Diff line number Diff line change 20
20
iNaT ,
21
21
parsing ,
22
22
)
23
- from pandas .errors import OutOfBoundsDatetime
23
+ from pandas .errors import (
24
+ OutOfBoundsDatetime ,
25
+ OutOfBoundsTimedelta ,
26
+ )
24
27
import pandas .util ._test_decorators as td
25
28
26
29
from pandas .core .dtypes .common import is_datetime64_ns_dtype
@@ -1675,12 +1678,14 @@ def test_to_datetime_overflow(self):
1675
1678
# gh-17637
1676
1679
# we are overflowing Timedelta range here
1677
1680
1678
- msg = (
1679
- "(Python int too large to convert to C long)|"
1680
- "(long too big to convert)|"
1681
- "(int too big to convert)"
1681
+ msg = "|" .join (
1682
+ [
1683
+ "Python int too large to convert to C long" ,
1684
+ "long too big to convert" ,
1685
+ "int too big to convert" ,
1686
+ ]
1682
1687
)
1683
- with pytest .raises (OverflowError , match = msg ):
1688
+ with pytest .raises (OutOfBoundsTimedelta , match = msg ):
1684
1689
date_range (start = "1/1/1700" , freq = "B" , periods = 100000 )
1685
1690
1686
1691
@pytest .mark .parametrize ("cache" , [True , False ])
You can’t perform that action at this time.
0 commit comments