From ebaefb7265552d8bb02dbb760fc2f19d9678eb6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Diridollou?= Date: Wed, 13 Aug 2025 16:28:14 -0400 Subject: [PATCH 1/2] Clean up timefuncs tests, fix nightly due to new errors --- tests/series/test_series.py | 18 +++++++++++++----- tests/test_frame.py | 17 +++++++++++++---- tests/test_indexes.py | 4 +++- tests/test_timefuncs.py | 35 ++++++++++++++++++++++------------- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 4d1486dcc..442b76d10 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -3855,11 +3855,19 @@ def test_series_reindex() -> None: def test_series_reindex_like() -> None: s = pd.Series([1, 2, 3], index=[0, 1, 2]) other = pd.Series([1, 2], index=[1, 0]) - with pytest_warns_bounded( - FutureWarning, - "the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", - lower="2.3.99", - upper="3.0.99", + with ( + pytest_warns_bounded( + FutureWarning, + "the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", + lower="2.3.99", + upper="2.99", + ), + pytest_warns_bounded( + Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0 + "the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", + lower="2.99", + upper="3.0.99", + ), ): check( assert_type( diff --git a/tests/test_frame.py b/tests/test_frame.py index 4dc9b82c0..aa6eee1e7 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -3254,10 +3254,19 @@ def test_frame_reindex_like() -> None: # GH 84 df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2]) other = pd.DataFrame({"a": [1, 2]}, index=[1, 0]) - with pytest_warns_bounded( - FutureWarning, - "the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", - lower="2.3.99", + with ( + pytest_warns_bounded( + FutureWarning, + "the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", + lower="2.3.99", + upper="2.99", + ), + pytest_warns_bounded( + Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0 + "the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", + lower="2.99", + upper="3.0.99", + ), ): check( assert_type( diff --git a/tests/test_indexes.py b/tests/test_indexes.py index f1add38b1..3db7dddd0 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -1372,7 +1372,9 @@ def test_datetimeindex_shift() -> None: def test_timedeltaindex_shift() -> None: ind = pd.date_range("1/1/2021", "1/5/2021") - pd.Timestamp("1/3/2019") - check(assert_type(ind.shift(1), pd.TimedeltaIndex), pd.TimedeltaIndex) + if PD_LTE_23: + # cannot shift with no freq starting in pandas 3.0.0 + check(assert_type(ind.shift(1), pd.TimedeltaIndex), pd.TimedeltaIndex) def test_index_insert() -> None: diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 05f6edb5e..f1e006832 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -95,9 +95,9 @@ def test_types_init() -> None: def test_types_arithmetic() -> None: - ts: pd.Timestamp = pd.to_datetime("2021-03-01") - ts2: pd.Timestamp = pd.to_datetime("2021-01-01") - delta: pd.Timedelta = pd.to_timedelta("1 day") + ts = pd.to_datetime("2021-03-01") + ts2 = pd.to_datetime("2021-01-01") + delta = pd.to_timedelta("1 day") check(assert_type(ts - ts2, pd.Timedelta), pd.Timedelta) check(assert_type(ts + delta, pd.Timestamp), pd.Timestamp) @@ -106,8 +106,8 @@ def test_types_arithmetic() -> None: def test_types_comparison() -> None: - ts: pd.Timestamp = pd.to_datetime("2021-03-01") - ts2: pd.Timestamp = pd.to_datetime("2021-01-01") + ts = pd.to_datetime("2021-03-01") + ts2 = pd.to_datetime("2021-01-01") check(assert_type(ts < ts2, bool), bool) check(assert_type(ts > ts2, bool), bool) @@ -136,7 +136,7 @@ def test_types_timestamp_series_comparisons() -> None: def test_types_pydatetime() -> None: - ts: pd.Timestamp = pd.Timestamp("2021-03-01T12") + ts = pd.Timestamp("2021-03-01T12") check(assert_type(ts.to_pydatetime(), dt.datetime), dt.datetime) check(assert_type(ts.to_pydatetime(False), dt.datetime), dt.datetime) @@ -152,9 +152,9 @@ def test_to_timedelta() -> None: def test_timedelta_arithmetic() -> None: - td1: pd.Timedelta = pd.to_timedelta(3, "days") - td2: pd.Timedelta = pd.to_timedelta(4, "hours") - td3: pd.Timedelta = td1 + td2 + td1 = pd.to_timedelta(3, "days") + td2 = pd.to_timedelta(4, "hours") + td3 = td1 + td2 check(assert_type(td1 - td2, pd.Timedelta), pd.Timedelta) check(assert_type(td1 * 4.3, pd.Timedelta), pd.Timedelta) check(assert_type(td3 / 10.2, pd.Timedelta), pd.Timedelta) @@ -541,10 +541,19 @@ def test_series_dt_accessors() -> None: check(assert_type(s2.dt.microseconds, "pd.Series[int]"), pd.Series, np.integer) check(assert_type(s2.dt.nanoseconds, "pd.Series[int]"), pd.Series, np.integer) check(assert_type(s2.dt.components, pd.DataFrame), pd.DataFrame) - with pytest_warns_bounded( - FutureWarning, - "The behavior of TimedeltaProperties.to_pytimedelta is deprecated", - lower="2.3.99", + with ( + pytest_warns_bounded( + FutureWarning, + "The behavior of TimedeltaProperties.to_pytimedelta is deprecated", + lower="2.3.99", + upper="2.99", + ), + pytest_warns_bounded( + Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0 + "The behavior of TimedeltaProperties.to_pytimedelta is deprecated", + lower="2.99", + upper="3.0.99", + ), ): check(assert_type(s2.dt.to_pytimedelta(), np.ndarray), np.ndarray) check(assert_type(s2.dt.total_seconds(), "pd.Series[float]"), pd.Series, float) From 9b8a51c35d709923a13f9f84737e834a67b4c011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Diridollou?= Date: Wed, 13 Aug 2025 19:47:12 -0400 Subject: [PATCH 2/2] PR feedback --- tests/series/test_series.py | 6 +++++- tests/test_frame.py | 7 ++++++- tests/test_indexes.py | 5 ++--- tests/test_timefuncs.py | 7 ++++++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 442b76d10..85114b4d8 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -98,6 +98,10 @@ TimestampSeries: TypeAlias = pd.Series OffsetSeries: TypeAlias = pd.Series +if not PD_LTE_23: + from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip +else: + Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] # Tests will use numpy 2.1 in python 3.10 or later # From Numpy 2.1 __init__.pyi @@ -3863,7 +3867,7 @@ def test_series_reindex_like() -> None: upper="2.99", ), pytest_warns_bounded( - Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0 + Pandas4Warning, "the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", lower="2.99", upper="3.0.99", diff --git a/tests/test_frame.py b/tests/test_frame.py index aa6eee1e7..fe5fa2985 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -72,6 +72,11 @@ else: _PandasNamedTuple: TypeAlias = tuple +if not PD_LTE_23: + from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip +else: + Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] + DF = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]}) @@ -3262,7 +3267,7 @@ def test_frame_reindex_like() -> None: upper="2.99", ), pytest_warns_bounded( - Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0 + Pandas4Warning, "the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", lower="2.99", upper="3.0.99", diff --git a/tests/test_indexes.py b/tests/test_indexes.py index 3db7dddd0..f6ad2a270 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -1372,9 +1372,8 @@ def test_datetimeindex_shift() -> None: def test_timedeltaindex_shift() -> None: ind = pd.date_range("1/1/2021", "1/5/2021") - pd.Timestamp("1/3/2019") - if PD_LTE_23: - # cannot shift with no freq starting in pandas 3.0.0 - check(assert_type(ind.shift(1), pd.TimedeltaIndex), pd.TimedeltaIndex) + # broken on 3.0.0.dev0 as of 20250813, fix with pandas-dev/pandas/issues/62094 + check(assert_type(ind.shift(1), pd.TimedeltaIndex), pd.TimedeltaIndex) def test_index_insert() -> None: diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index f1e006832..7e39e4a75 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -56,6 +56,11 @@ else: TimestampSeries: TypeAlias = pd.Series +if not PD_LTE_23: + from pandas.errors import Pandas4Warning # type: ignore[attr-defined] # pyright: ignore # isort: skip +else: + Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] + from tests import np_ndarray_bool @@ -549,7 +554,7 @@ def test_series_dt_accessors() -> None: upper="2.99", ), pytest_warns_bounded( - Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0 + Pandas4Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0 "The behavior of TimedeltaProperties.to_pytimedelta is deprecated", lower="2.99", upper="3.0.99",