Skip to content

Commit 367372e

Browse files
remove fixture
1 parent 7027687 commit 367372e

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

pandas/tests/scalar/conftest.py

-6
This file was deleted.

pandas/tests/scalar/timedelta/test_arithmetic.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
import pandas._testing as tm
2323
from pandas.core import ops
2424

25+
TD_OVERFLOW_MSG = (
26+
r"outside allowed range \[-9223372036854775807ns, 9223372036854775807ns\]"
27+
)
28+
2529

2630
class TestTimedeltaAdditionSubtraction:
2731
"""
@@ -98,11 +102,11 @@ def test_td_add_datetimelike_scalar(self, op):
98102
result = op(td, NaT)
99103
assert result is NaT
100104

101-
def test_td_add_timestamp_overflow(self, td_overflow_msg: str):
102-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
105+
def test_td_add_timestamp_overflow(self):
106+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
103107
Timestamp("1700-01-01") + Timedelta(13 * 19999, unit="D")
104108

105-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
109+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
106110
Timestamp("1700-01-01") + timedelta(days=13 * 19999)
107111

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

pandas/tests/scalar/timedelta/test_constructors.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@
1212
to_timedelta,
1313
)
1414

15+
TD_OVERFLOW_MSG = (
16+
r"outside allowed range \[-9223372036854775807ns, 9223372036854775807ns\]"
17+
)
18+
1519

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

21-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
25+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
2226
Timedelta(obj, unit="ns")
2327

24-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
28+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
2529
Timedelta(obj)
2630

2731

@@ -200,17 +204,17 @@ def test_td_from_repr_roundtrip(val):
200204
assert Timedelta(td._repr_base()) == td
201205

202206

203-
def test_overflow_on_construction(td_overflow_msg: str):
207+
def test_overflow_on_construction():
204208
# GH#3374
205209
value = Timedelta("1day").value * 20169940
206-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
210+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
207211
Timedelta(value)
208212

209213
# xref GH#17637
210-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
214+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
211215
Timedelta(7 * 19999, unit="D")
212216

213-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
217+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
214218
Timedelta(timedelta(days=13 * 19999))
215219

216220

@@ -225,15 +229,15 @@ def test_overflow_on_construction(td_overflow_msg: str):
225229
(9223372037, "s", " seconds"), # 44 seconds
226230
],
227231
)
228-
def test_construction_out_of_bounds_td64(val, unit, name, td_overflow_msg: str):
232+
def test_construction_out_of_bounds_td64(val, unit, name):
229233
# TODO: parametrize over units just above/below the implementation bounds
230234
# once GH#38964 is resolved
231235

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

236-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
240+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
237241
Timedelta(td64)
238242

239243
# But just back in bounds and we are OK
@@ -242,7 +246,7 @@ def test_construction_out_of_bounds_td64(val, unit, name, td_overflow_msg: str):
242246
td64 *= -1
243247
assert td64.astype("m8[ns]").view("i8") > 0 # i.e. naive astype will be wrong
244248

245-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
249+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
246250
Timedelta(td64)
247251

248252
# But just back in bounds and we are OK

pandas/tests/scalar/timedelta/test_timedelta.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
)
2525
import pandas._testing as tm
2626

27+
TD_OVERFLOW_MSG = (
28+
r"outside allowed range \[-9223372036854775807ns, 9223372036854775807ns\]"
29+
)
30+
2731

2832
class TestNonNano:
2933
@pytest.fixture(params=[7, 8, 9])
@@ -647,7 +651,7 @@ def test_timedelta_hash_equality(self):
647651
ns_td = Timedelta(1, "ns")
648652
assert hash(ns_td) != hash(ns_td.to_pytimedelta())
649653

650-
def test_implementation_limits(self, td_overflow_msg: str):
654+
def test_implementation_limits(self):
651655
min_td = Timedelta(Timedelta.min)
652656
max_td = Timedelta(Timedelta.max)
653657

@@ -659,20 +663,20 @@ def test_implementation_limits(self, td_overflow_msg: str):
659663
# Beyond lower limit, a NAT before the Overflow
660664
assert (min_td - Timedelta(1, "ns")) is NaT # type: ignore[comparison-overlap]
661665

662-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
666+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
663667
min_td - Timedelta(2, "ns")
664668

665-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
669+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
666670
max_td + Timedelta(1, "ns")
667671

668672
# Same tests using the internal nanosecond values
669673
td = Timedelta(min_td.value - 1, "ns")
670674
assert td is NaT # type: ignore[comparison-overlap]
671675

672-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
676+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
673677
Timedelta(min_td.value - 2, "ns")
674678

675-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
679+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
676680
Timedelta(max_td.value + 1, "ns")
677681

678682
def test_total_seconds_precision(self):

pandas/tests/scalar/timestamp/test_arithmetic.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
import pandas._testing as tm
1919

20+
TD_OVERFLOW_MSG = (
21+
r"outside allowed range \[-9223372036854775807ns, 9223372036854775807ns\]"
22+
)
23+
2024

2125
class TestTimestampArithmetic:
2226
def test_overflow_offset(self):
@@ -33,7 +37,7 @@ def test_overflow_offset(self):
3337
expected = Timestamp("1999/09/23")
3438
assert stamp - offset_no_overflow == expected
3539

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

@@ -46,7 +50,7 @@ def test_overflow_offset_raises(self, td_overflow_msg: str):
4650
with pytest.raises(OverflowError, match=lmsg):
4751
stamp + offset_overflow
4852

49-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
53+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
5054
offset_overflow + stamp
5155

5256
with pytest.raises(OverflowError, match=lmsg):
@@ -61,7 +65,7 @@ def test_overflow_offset_raises(self, td_overflow_msg: str):
6165
with pytest.raises(OverflowError, match=lmsg):
6266
stamp + offset_overflow
6367

64-
with pytest.raises(OutOfBoundsTimedelta, match=td_overflow_msg):
68+
with pytest.raises(OutOfBoundsTimedelta, match=TD_OVERFLOW_MSG):
6569
offset_overflow + stamp
6670

6771
with pytest.raises(OverflowError, match=lmsg):

0 commit comments

Comments
 (0)