Skip to content

Commit 0ecc8ea

Browse files
Clean up timefuncs tests, fix nightly due to new errors (#1322)
* Clean up timefuncs tests, fix nightly due to new errors * PR feedback
1 parent fe3b81a commit 0ecc8ea

File tree

4 files changed

+63
-22
lines changed

4 files changed

+63
-22
lines changed

tests/series/test_series.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
TimestampSeries: TypeAlias = pd.Series
9999
OffsetSeries: TypeAlias = pd.Series
100100

101+
if not PD_LTE_23:
102+
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip
103+
else:
104+
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]
101105

102106
# Tests will use numpy 2.1 in python 3.10 or later
103107
# From Numpy 2.1 __init__.pyi
@@ -3855,11 +3859,19 @@ def test_series_reindex() -> None:
38553859
def test_series_reindex_like() -> None:
38563860
s = pd.Series([1, 2, 3], index=[0, 1, 2])
38573861
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",
3862+
with (
3863+
pytest_warns_bounded(
3864+
FutureWarning,
3865+
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3866+
lower="2.3.99",
3867+
upper="2.99",
3868+
),
3869+
pytest_warns_bounded(
3870+
Pandas4Warning,
3871+
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3872+
lower="2.99",
3873+
upper="3.0.99",
3874+
),
38633875
):
38643876
check(
38653877
assert_type(

tests/test_frame.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
else:
7373
_PandasNamedTuple: TypeAlias = tuple
7474

75+
if not PD_LTE_23:
76+
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip
77+
else:
78+
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]
79+
7580
DF = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
7681

7782

@@ -3254,10 +3259,19 @@ def test_frame_reindex_like() -> None:
32543259
# GH 84
32553260
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2])
32563261
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",
3262+
with (
3263+
pytest_warns_bounded(
3264+
FutureWarning,
3265+
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3266+
lower="2.3.99",
3267+
upper="2.99",
3268+
),
3269+
pytest_warns_bounded(
3270+
Pandas4Warning,
3271+
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3272+
lower="2.99",
3273+
upper="3.0.99",
3274+
),
32613275
):
32623276
check(
32633277
assert_type(

tests/test_indexes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ 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+
# broken on 3.0.0.dev0 as of 20250813, fix with pandas-dev/pandas/issues/62094
13751376
check(assert_type(ind.shift(1), pd.TimedeltaIndex), pd.TimedeltaIndex)
13761377

13771378

tests/test_timefuncs.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
else:
5757
TimestampSeries: TypeAlias = pd.Series
5858

59+
if not PD_LTE_23:
60+
from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip
61+
else:
62+
Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef]
63+
5964
from tests import np_ndarray_bool
6065

6166

@@ -95,9 +100,9 @@ def test_types_init() -> None:
95100

96101

97102
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")
103+
ts = pd.to_datetime("2021-03-01")
104+
ts2 = pd.to_datetime("2021-01-01")
105+
delta = pd.to_timedelta("1 day")
101106

102107
check(assert_type(ts - ts2, pd.Timedelta), pd.Timedelta)
103108
check(assert_type(ts + delta, pd.Timestamp), pd.Timestamp)
@@ -106,8 +111,8 @@ def test_types_arithmetic() -> None:
106111

107112

108113
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")
114+
ts = pd.to_datetime("2021-03-01")
115+
ts2 = pd.to_datetime("2021-01-01")
111116

112117
check(assert_type(ts < ts2, bool), bool)
113118
check(assert_type(ts > ts2, bool), bool)
@@ -136,7 +141,7 @@ def test_types_timestamp_series_comparisons() -> None:
136141

137142

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

141146
check(assert_type(ts.to_pydatetime(), dt.datetime), dt.datetime)
142147
check(assert_type(ts.to_pydatetime(False), dt.datetime), dt.datetime)
@@ -152,9 +157,9 @@ def test_to_timedelta() -> None:
152157

153158

154159
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
160+
td1 = pd.to_timedelta(3, "days")
161+
td2 = pd.to_timedelta(4, "hours")
162+
td3 = td1 + td2
158163
check(assert_type(td1 - td2, pd.Timedelta), pd.Timedelta)
159164
check(assert_type(td1 * 4.3, pd.Timedelta), pd.Timedelta)
160165
check(assert_type(td3 / 10.2, pd.Timedelta), pd.Timedelta)
@@ -541,10 +546,19 @@ def test_series_dt_accessors() -> None:
541546
check(assert_type(s2.dt.microseconds, "pd.Series[int]"), pd.Series, np.integer)
542547
check(assert_type(s2.dt.nanoseconds, "pd.Series[int]"), pd.Series, np.integer)
543548
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",
549+
with (
550+
pytest_warns_bounded(
551+
FutureWarning,
552+
"The behavior of TimedeltaProperties.to_pytimedelta is deprecated",
553+
lower="2.3.99",
554+
upper="2.99",
555+
),
556+
pytest_warns_bounded(
557+
Pandas4Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0
558+
"The behavior of TimedeltaProperties.to_pytimedelta is deprecated",
559+
lower="2.99",
560+
upper="3.0.99",
561+
),
548562
):
549563
check(assert_type(s2.dt.to_pytimedelta(), np.ndarray), np.ndarray)
550564
check(assert_type(s2.dt.total_seconds(), "pd.Series[float]"), pd.Series, float)

0 commit comments

Comments
 (0)