Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pandas/tests/scalar/timedelta/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,26 @@ def test_overflow_on_construction():
Timedelta(timedelta(days=13 * 19999))


def test_construction_out_of_bounds_td64():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was already here and should have caught #36615.
I parametrized it, but this is still a bit puzzling

@pytest.mark.parametrize(
"val, unit, name",
[
(3508, "M", " months"),
(15251, "W", " weeks"), # 1
(106752, "D", " days"), # change from previous:
(2562048, "h", " hours"), # 0 hours
(153722868, "m", " minutes"), # 13 minutes
(9223372037, "s", " seconds"), # 44 seconds
],
)
def test_construction_out_of_bounds_td64(val, unit, name):
# TODO: parametrize over units just above/below the implementation bounds
# once GH#38964 is resolved

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

msg = "106752 days"
msg = str(val) + name
with pytest.raises(OutOfBoundsTimedelta, match=msg):
Timedelta(td64)

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

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

# But just back in bounds and we are OK
Expand Down