diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 4d1486dc..85114b4d 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 @@ -3855,11 +3859,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( + 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", + ), ): check( assert_type( diff --git a/tests/test_frame.py b/tests/test_frame.py index 4dc9b82c..fe5fa298 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]}) @@ -3254,10 +3259,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( + 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", + ), ): check( assert_type( diff --git a/tests/test_indexes.py b/tests/test_indexes.py index f1add38b..f6ad2a27 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -1372,6 +1372,7 @@ 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") + # 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) diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 05f6edb5..7e39e4a7 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 @@ -95,9 +100,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 +111,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 +141,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 +157,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 +546,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( + 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", + ), ): check(assert_type(s2.dt.to_pytimedelta(), np.ndarray), np.ndarray) check(assert_type(s2.dt.total_seconds(), "pd.Series[float]"), pd.Series, float)