Skip to content

Commit 14f5bdf

Browse files
get current tests passing
1 parent 4b58319 commit 14f5bdf

File tree

5 files changed

+30
-35
lines changed

5 files changed

+30
-35
lines changed

pandas/tests/scalar/conftest.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
3+
4+
@pytest.fixture(name="td_overflow_msg")
5+
def fixture_td_overflow_msg() -> str:
6+
return R"outside allowed range \[-9223372036854775807ns, 9223372036854775807ns\]"

pandas/tests/scalar/timedelta/test_arithmetic.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,11 @@ def test_td_add_datetimelike_scalar(self, op):
9898
result = op(td, NaT)
9999
assert result is NaT
100100

101-
def test_td_add_timestamp_overflow(self):
102-
msg = "int too (large|big) to convert"
103-
with pytest.raises(OverflowError, match=msg):
101+
def test_td_add_timestamp_overflow(self, td_overflow_msg: str):
102+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
104103
Timestamp("1700-01-01") + Timedelta(13 * 19999, unit="D")
105104

106-
with pytest.raises(OutOfBoundsTimedelta, match=msg):
105+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
107106
Timestamp("1700-01-01") + timedelta(days=13 * 19999)
108107

109108
@pytest.mark.parametrize("op", [operator.add, ops.radd])

pandas/tests/scalar/timedelta/test_constructors.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@
1313
)
1414

1515

16-
def test_construct_from_td64_with_unit():
16+
def test_construct_from_td64_with_unit(td_overflow_msg: str):
1717
# ignore the unit, as it may cause silently overflows leading to incorrect
1818
# results, and in non-overflow cases is irrelevant GH#46827
1919
obj = np.timedelta64(123456789, "h")
2020

21-
with pytest.raises(OutOfBoundsTimedelta, match="123456789 hours"):
22-
Timedelta(obj, unit="ps")
23-
24-
with pytest.raises(OutOfBoundsTimedelta, match="123456789 hours"):
21+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
2522
Timedelta(obj, unit="ns")
2623

27-
with pytest.raises(OutOfBoundsTimedelta, match="123456789 hours"):
24+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
2825
Timedelta(obj)
2926

3027

@@ -203,19 +200,17 @@ def test_td_from_repr_roundtrip(val):
203200
assert Timedelta(td._repr_base()) == td
204201

205202

206-
def test_overflow_on_construction():
207-
msg = "int too (large|big) to convert"
208-
203+
def test_overflow_on_construction(td_overflow_msg: str):
209204
# GH#3374
210205
value = Timedelta("1day").value * 20169940
211-
with pytest.raises(OverflowError, match=msg):
206+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
212207
Timedelta(value)
213208

214209
# xref GH#17637
215-
with pytest.raises(OverflowError, match=msg):
210+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
216211
Timedelta(7 * 19999, unit="D")
217212

218-
with pytest.raises(OutOfBoundsTimedelta, match=msg):
213+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
219214
Timedelta(timedelta(days=13 * 19999))
220215

221216

pandas/tests/scalar/timedelta/test_timedelta.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
NaT,
1414
iNaT,
1515
)
16+
from pandas._libs.tslibs.np_datetime import OutOfBoundsTimedelta
1617

1718
import pandas as pd
1819
from pandas import (
@@ -646,7 +647,7 @@ def test_timedelta_hash_equality(self):
646647
ns_td = Timedelta(1, "ns")
647648
assert hash(ns_td) != hash(ns_td.to_pytimedelta())
648649

649-
def test_implementation_limits(self):
650+
def test_implementation_limits(self, td_overflow_msg: str):
650651
min_td = Timedelta(Timedelta.min)
651652
max_td = Timedelta(Timedelta.max)
652653

@@ -656,23 +657,22 @@ def test_implementation_limits(self):
656657
assert max_td.value == lib.i8max
657658

658659
# Beyond lower limit, a NAT before the Overflow
659-
assert (min_td - Timedelta(1, "ns")) is NaT
660+
assert (min_td - Timedelta(1, "ns")) is NaT # type: ignore[comparison-overlap]
660661

661-
msg = "int too (large|big) to convert"
662-
with pytest.raises(OverflowError, match=msg):
662+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
663663
min_td - Timedelta(2, "ns")
664664

665-
with pytest.raises(OverflowError, match=msg):
665+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
666666
max_td + Timedelta(1, "ns")
667667

668668
# Same tests using the internal nanosecond values
669669
td = Timedelta(min_td.value - 1, "ns")
670-
assert td is NaT
670+
assert td is NaT # type: ignore[comparison-overlap]
671671

672-
with pytest.raises(OverflowError, match=msg):
672+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
673673
Timedelta(min_td.value - 2, "ns")
674674

675-
with pytest.raises(OverflowError, match=msg):
675+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
676676
Timedelta(max_td.value + 1, "ns")
677677

678678
def test_total_seconds_precision(self):

pandas/tests/scalar/timestamp/test_arithmetic.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pytest
99

1010
from pandas._libs.tslibs import (
11-
OutOfBoundsDatetime,
11+
OutOfBoundsTimedelta,
1212
Timedelta,
1313
Timestamp,
1414
offsets,
@@ -33,25 +33,20 @@ def test_overflow_offset(self):
3333
expected = Timestamp("1999/09/23")
3434
assert stamp - offset_no_overflow == expected
3535

36-
def test_overflow_offset_raises(self):
36+
def test_overflow_offset_raises(self, td_overflow_msg: str):
3737
# xref https://github.com/statsmodels/statsmodels/issues/3374
3838
# ends up multiplying really large numbers which overflow
3939

4040
stamp = Timestamp("2017-01-13 00:00:00")
4141
offset_overflow = 20169940 * offsets.Day(1)
42-
msg = (
43-
"the add operation between "
44-
r"\<-?\d+ \* Days\> and \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} "
45-
"will overflow"
46-
)
4742
lmsg = "|".join(
4843
["Python int too large to convert to C long", "int too big to convert"]
4944
)
5045

5146
with pytest.raises(OverflowError, match=lmsg):
5247
stamp + offset_overflow
5348

54-
with pytest.raises(OverflowError, match=msg):
49+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
5550
offset_overflow + stamp
5651

5752
with pytest.raises(OverflowError, match=lmsg):
@@ -61,12 +56,12 @@ def test_overflow_offset_raises(self):
6156
# used to crash, so check for proper overflow exception
6257

6358
stamp = Timestamp("2000/1/1")
64-
offset_overflow = to_offset("D") * 100**5
59+
offset_overflow = offsets.Day() * 100**5
6560

6661
with pytest.raises(OverflowError, match=lmsg):
6762
stamp + offset_overflow
6863

69-
with pytest.raises(OverflowError, match=msg):
64+
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
7065
offset_overflow + stamp
7166

7267
with pytest.raises(OverflowError, match=lmsg):
@@ -78,7 +73,7 @@ def test_overflow_timestamp_raises(self):
7873
a = Timestamp("2101-01-01 00:00:00")
7974
b = Timestamp("1688-01-01 00:00:00")
8075

81-
with pytest.raises(OutOfBoundsDatetime, match=msg):
76+
with pytest.raises(OutOfBoundsTimedelta, match=msg):
8277
a - b
8378

8479
# but we're OK for timestamp and datetime.datetime

0 commit comments

Comments
 (0)