Skip to content

Commit da0d165

Browse files
committed
BUG: OutOfBoundsTimedelta not raised for out-of-bounds Timedelta (pandas-dev#42235)
1 parent 9a25c3d commit da0d165

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

pandas/tests/scalar/timedelta/test_constructors.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,26 @@ def test_overflow_on_construction():
204204
Timedelta(timedelta(days=13 * 19999))
205205

206206

207-
def test_construction_out_of_bounds_td64():
207+
@pytest.mark.parametrize(
208+
"val, unit, name",
209+
[
210+
(3508, "M", " months"),
211+
(15251, "W", " weeks"), # 1
212+
(106752, "D", " days"), # change from previous:
213+
(2562048, "h", " hours"), # 0 hours
214+
(153722868, "m", " minutes"), # 13 minutes
215+
(9223372037, "s", " seconds"), # 44 seconds
216+
],
217+
)
218+
def test_construction_out_of_bounds_td64(val, unit, name):
208219
# TODO: parametrize over units just above/below the implementation bounds
209220
# once GH#38964 is resolved
210221

211222
# Timedelta.max is just under 106752 days
212-
td64 = np.timedelta64(106752, "D")
223+
td64 = np.timedelta64(val, unit)
213224
assert td64.astype("m8[ns]").view("i8") < 0 # i.e. naive astype will be wrong
214225

215-
msg = "106752 days"
226+
msg = str(val) + name
216227
with pytest.raises(OutOfBoundsTimedelta, match=msg):
217228
Timedelta(td64)
218229

@@ -222,7 +233,7 @@ def test_construction_out_of_bounds_td64():
222233
td64 *= -1
223234
assert td64.astype("m8[ns]").view("i8") > 0 # i.e. naive astype will be wrong
224235

225-
with pytest.raises(OutOfBoundsTimedelta, match=msg):
236+
with pytest.raises(OutOfBoundsTimedelta, match="-" + msg):
226237
Timedelta(td64)
227238

228239
# But just back in bounds and we are OK

0 commit comments

Comments
 (0)