4
4
import numpy as np
5
5
import pytest
6
6
7
- from pandas ._libs .tslibs import OutOfBoundsTimedelta
8
-
9
7
from pandas import (
10
8
Timedelta ,
11
9
offsets ,
@@ -204,15 +202,26 @@ def test_overflow_on_construction():
204
202
Timedelta (timedelta (days = 13 * 19999 ))
205
203
206
204
207
- def test_construction_out_of_bounds_td64 ():
205
+ @pytest .mark .parametrize (
206
+ "val, unit, name" ,
207
+ [
208
+ (3508 , "M" , " months" ),
209
+ (15251 , "W" , " weeks" ), # 1
210
+ (106752 , "D" , " days" ), # change from previous:
211
+ (2562048 , "h" , " hours" ), # 0 hours
212
+ (153722868 , "m" , " minutes" ), # 13 minutes
213
+ (9223372037 , "s" , " seconds" ), # 44 seconds
214
+ ],
215
+ )
216
+ def test_construction_out_of_bounds_td64 (val , unit , name ):
208
217
# TODO: parametrize over units just above/below the implementation bounds
209
218
# once GH#38964 is resolved
210
219
211
220
# Timedelta.max is just under 106752 days
212
- td64 = np .timedelta64 (106752 , "D" )
221
+ td64 = np .timedelta64 (val , unit )
213
222
assert td64 .astype ("m8[ns]" ).view ("i8" ) < 0 # i.e. naive astype will be wrong
214
223
215
- msg = "106752 days"
224
+ msg = str ( val ) + name
216
225
with pytest .raises (OutOfBoundsTimedelta , match = msg ):
217
226
Timedelta (td64 )
218
227
@@ -222,7 +231,7 @@ def test_construction_out_of_bounds_td64():
222
231
td64 *= - 1
223
232
assert td64 .astype ("m8[ns]" ).view ("i8" ) > 0 # i.e. naive astype will be wrong
224
233
225
- with pytest .raises (OutOfBoundsTimedelta , match = msg ):
234
+ with pytest .raises (OutOfBoundsTimedelta , match = "-" + msg ):
226
235
Timedelta (td64 )
227
236
228
237
# But just back in bounds and we are OK
0 commit comments