Skip to content

Commit ebaefb7

Browse files
Clean up timefuncs tests, fix nightly due to new errors
1 parent df9fc86 commit ebaefb7

File tree

4 files changed

+51
-23
lines changed

4 files changed

+51
-23
lines changed

tests/series/test_series.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3855,11 +3855,19 @@ def test_series_reindex() -> None:
38553855
def test_series_reindex_like() -> None:
38563856
s = pd.Series([1, 2, 3], index=[0, 1, 2])
38573857
other = pd.Series([1, 2], index=[1, 0])
3858-
with pytest_warns_bounded(
3859-
FutureWarning,
3860-
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3861-
lower="2.3.99",
3862-
upper="3.0.99",
3858+
with (
3859+
pytest_warns_bounded(
3860+
FutureWarning,
3861+
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3862+
lower="2.3.99",
3863+
upper="2.99",
3864+
),
3865+
pytest_warns_bounded(
3866+
Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0
3867+
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3868+
lower="2.99",
3869+
upper="3.0.99",
3870+
),
38633871
):
38643872
check(
38653873
assert_type(

tests/test_frame.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3254,10 +3254,19 @@ def test_frame_reindex_like() -> None:
32543254
# GH 84
32553255
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2])
32563256
other = pd.DataFrame({"a": [1, 2]}, index=[1, 0])
3257-
with pytest_warns_bounded(
3258-
FutureWarning,
3259-
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3260-
lower="2.3.99",
3257+
with (
3258+
pytest_warns_bounded(
3259+
FutureWarning,
3260+
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3261+
lower="2.3.99",
3262+
upper="2.99",
3263+
),
3264+
pytest_warns_bounded(
3265+
Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0
3266+
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3267+
lower="2.99",
3268+
upper="3.0.99",
3269+
),
32613270
):
32623271
check(
32633272
assert_type(

tests/test_indexes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,9 @@ def test_datetimeindex_shift() -> None:
13721372

13731373
def test_timedeltaindex_shift() -> None:
13741374
ind = pd.date_range("1/1/2021", "1/5/2021") - pd.Timestamp("1/3/2019")
1375-
check(assert_type(ind.shift(1), pd.TimedeltaIndex), pd.TimedeltaIndex)
1375+
if PD_LTE_23:
1376+
# cannot shift with no freq starting in pandas 3.0.0
1377+
check(assert_type(ind.shift(1), pd.TimedeltaIndex), pd.TimedeltaIndex)
13761378

13771379

13781380
def test_index_insert() -> None:

tests/test_timefuncs.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def test_types_init() -> None:
9595

9696

9797
def test_types_arithmetic() -> None:
98-
ts: pd.Timestamp = pd.to_datetime("2021-03-01")
99-
ts2: pd.Timestamp = pd.to_datetime("2021-01-01")
100-
delta: pd.Timedelta = pd.to_timedelta("1 day")
98+
ts = pd.to_datetime("2021-03-01")
99+
ts2 = pd.to_datetime("2021-01-01")
100+
delta = pd.to_timedelta("1 day")
101101

102102
check(assert_type(ts - ts2, pd.Timedelta), pd.Timedelta)
103103
check(assert_type(ts + delta, pd.Timestamp), pd.Timestamp)
@@ -106,8 +106,8 @@ def test_types_arithmetic() -> None:
106106

107107

108108
def test_types_comparison() -> None:
109-
ts: pd.Timestamp = pd.to_datetime("2021-03-01")
110-
ts2: pd.Timestamp = pd.to_datetime("2021-01-01")
109+
ts = pd.to_datetime("2021-03-01")
110+
ts2 = pd.to_datetime("2021-01-01")
111111

112112
check(assert_type(ts < ts2, bool), bool)
113113
check(assert_type(ts > ts2, bool), bool)
@@ -136,7 +136,7 @@ def test_types_timestamp_series_comparisons() -> None:
136136

137137

138138
def test_types_pydatetime() -> None:
139-
ts: pd.Timestamp = pd.Timestamp("2021-03-01T12")
139+
ts = pd.Timestamp("2021-03-01T12")
140140

141141
check(assert_type(ts.to_pydatetime(), dt.datetime), dt.datetime)
142142
check(assert_type(ts.to_pydatetime(False), dt.datetime), dt.datetime)
@@ -152,9 +152,9 @@ def test_to_timedelta() -> None:
152152

153153

154154
def test_timedelta_arithmetic() -> None:
155-
td1: pd.Timedelta = pd.to_timedelta(3, "days")
156-
td2: pd.Timedelta = pd.to_timedelta(4, "hours")
157-
td3: pd.Timedelta = td1 + td2
155+
td1 = pd.to_timedelta(3, "days")
156+
td2 = pd.to_timedelta(4, "hours")
157+
td3 = td1 + td2
158158
check(assert_type(td1 - td2, pd.Timedelta), pd.Timedelta)
159159
check(assert_type(td1 * 4.3, pd.Timedelta), pd.Timedelta)
160160
check(assert_type(td3 / 10.2, pd.Timedelta), pd.Timedelta)
@@ -541,10 +541,19 @@ def test_series_dt_accessors() -> None:
541541
check(assert_type(s2.dt.microseconds, "pd.Series[int]"), pd.Series, np.integer)
542542
check(assert_type(s2.dt.nanoseconds, "pd.Series[int]"), pd.Series, np.integer)
543543
check(assert_type(s2.dt.components, pd.DataFrame), pd.DataFrame)
544-
with pytest_warns_bounded(
545-
FutureWarning,
546-
"The behavior of TimedeltaProperties.to_pytimedelta is deprecated",
547-
lower="2.3.99",
544+
with (
545+
pytest_warns_bounded(
546+
FutureWarning,
547+
"The behavior of TimedeltaProperties.to_pytimedelta is deprecated",
548+
lower="2.3.99",
549+
upper="2.99",
550+
),
551+
pytest_warns_bounded(
552+
Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0
553+
"The behavior of TimedeltaProperties.to_pytimedelta is deprecated",
554+
lower="2.99",
555+
upper="3.0.99",
556+
),
548557
):
549558
check(assert_type(s2.dt.to_pytimedelta(), np.ndarray), np.ndarray)
550559
check(assert_type(s2.dt.total_seconds(), "pd.Series[float]"), pd.Series, float)

0 commit comments

Comments
 (0)