Skip to content

Commit c798806

Browse files
author
Joeperdefloep
committed
moved and parametrized test
1 parent 7bbe4a5 commit c798806

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

pandas/tests/scalar/timedelta/test_constructors.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import numpy as np
55
import pytest
66

7-
from pandas._libs.tslibs import OutOfBoundsTimedelta
8-
97
from pandas import (
108
Timedelta,
119
offsets,
@@ -204,15 +202,26 @@ def test_overflow_on_construction():
204202
Timedelta(timedelta(days=13 * 19999))
205203

206204

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):
208217
# TODO: parametrize over units just above/below the implementation bounds
209218
# once GH#38964 is resolved
210219

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

215-
msg = "106752 days"
224+
msg = str(val) + name
216225
with pytest.raises(OutOfBoundsTimedelta, match=msg):
217226
Timedelta(td64)
218227

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

225-
with pytest.raises(OutOfBoundsTimedelta, match=msg):
234+
with pytest.raises(OutOfBoundsTimedelta, match="-" + msg):
226235
Timedelta(td64)
227236

228237
# But just back in bounds and we are OK

pandas/tests/tslibs/test_timedeltas.py

-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
offsets,
99
)
1010

11-
from pandas.errors import OutOfBoundsTimedelta
12-
1311

1412
@pytest.mark.parametrize(
1513
"obj,expected",
@@ -39,9 +37,3 @@ def test_huge_nanoseconds_overflow():
3937
# GH 32402
4038
assert delta_to_nanoseconds(Timedelta(1e10)) == 1e10
4139
assert delta_to_nanoseconds(Timedelta(nanoseconds=1e10)) == 1e10
42-
43-
44-
def test_out_of_bounds():
45-
# GH 36615
46-
with pytest.raises(OutOfBoundsTimedelta, match="200000 days"):
47-
Timedelta(np.timedelta64(200000, "D"))

0 commit comments

Comments
 (0)