diff --git a/tests/test_frame.py b/tests/test_frame.py index 32f23e240..a8b03e76f 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1446,7 +1446,13 @@ def test_types_to_html() -> None: def test_types_resample() -> None: df = pd.DataFrame({"values": [2, 11, 3, 13, 14, 18, 17, 19]}) df["date"] = pd.date_range("01/01/2018", periods=8, freq="W") - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): df.resample("M", on="date") df.resample("20min", origin="epoch", offset=pd.Timedelta(2, "minutes"), on="date") df.resample("20min", origin="epoch", offset=datetime.timedelta(2), on="date") @@ -1583,8 +1589,14 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame: assert isinstance(resampler, Resampler) return pd.DataFrame(resampler) - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): - val = ( + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): + ( pd.DataFrame( { "price": [10, 11, 9, 13, 14, 18, 17, 19], @@ -1596,6 +1608,18 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame: .pipe(resampler_foo) ) + val = ( + pd.DataFrame( + { + "price": [10, 11, 9, 13, 14, 18, 17, 19], + "volume": [50, 60, 40, 100, 50, 100, 40, 50], + } + ) + .assign(week_starting=pd.date_range("01/01/2018", periods=8, freq="W")) + .resample("MS", on="week_starting") + .pipe(resampler_foo) + ) + def foo(df: pd.DataFrame) -> pd.DataFrame: return pd.DataFrame(df) @@ -1854,11 +1878,22 @@ def test_types_regressions() -> None: d: datetime.date = pd.Timestamp("2021-01-01") tslist: list[pd.Timestamp] = list(pd.to_datetime(["2022-01-01", "2022-01-02"])) sseries: pd.Series = pd.Series(tslist) - sseries_plus1: pd.Series = sseries + pd.Timedelta(1, "d") + with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"): + sseries + pd.Timedelta(1, "d") + + sseries_plus1: pd.Series = sseries + pd.Timedelta(1, "D") # https://github.com/microsoft/pylance-release/issues/2133 - with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"): - dr = pd.date_range(start="2021-12-01", periods=24, freq="H") + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): + pd.date_range(start="2021-12-01", periods=24, freq="H") + + dr = pd.date_range(start="2021-12-01", periods=24, freq="h") time = dr.strftime("%H:%M:%S") # https://github.com/microsoft/python-type-stubs/issues/115 @@ -2885,8 +2920,16 @@ def test_quantile_150_changes() -> None: def test_resample_150_changes() -> None: idx = pd.date_range("2020-1-1", periods=700) frame = pd.DataFrame(np.random.standard_normal((700, 1)), index=idx, columns=["a"]) - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): - resampler = frame.resample("M", group_keys=True) + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): + frame.resample("M", group_keys=True) + + resampler = frame.resample("MS", group_keys=True) check( assert_type(resampler, "DatetimeIndexResampler[pd.DataFrame]"), DatetimeIndexResampler, diff --git a/tests/test_indexes.py b/tests/test_indexes.py index e59fc0ca3..85edc3b57 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -259,7 +259,13 @@ def test_interval_range(): pd.IntervalIndex, pd.Interval, ) - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type( pd.interval_range( @@ -577,9 +583,18 @@ def test_interval_index_arrays(): pd.IntervalIndex, pd.Interval, ) - with pytest_warns_bounded(FutureWarning, "'Y' is deprecated", lower="2.1.99"): - left_s_ts = pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="Y")) - right_s_ts = pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="Y")) + with pytest_warns_bounded( + FutureWarning, + "'Y' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): + pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="Y")) + pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="Y")) + + left_s_ts = pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="YS")) + right_s_ts = pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="YS")) check( assert_type( pd.IntervalIndex.from_arrays(left_s_ts, right_s_ts), @@ -989,7 +1004,13 @@ def test_index_constructors(): def test_iter() -> None: # GH 723 - with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): for ts in pd.date_range(start="1/1/2023", end="1/08/2023", freq="6H"): check(assert_type(ts, pd.Timestamp), pd.Timestamp) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 3cd36af71..cafa4fba5 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1980,7 +1980,13 @@ def g(x: pd.Series) -> int: }, index=idx, ) - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type( pd.pivot_table( @@ -1990,7 +1996,13 @@ def g(x: pd.Series) -> int: ), pd.DataFrame, ) - with pytest_warns_bounded(FutureWarning, "'(M|A)' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'(M|A)' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type( pd.pivot_table( diff --git a/tests/test_scalars.py b/tests/test_scalars.py index 70479da79..30315a22d 100644 --- a/tests/test_scalars.py +++ b/tests/test_scalars.py @@ -386,9 +386,11 @@ def test_interval_cmp(): def test_timedelta_construction() -> None: check(assert_type(pd.Timedelta(1, "W"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.Timedelta(1, "w"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'w' is deprecated", lower="2.2.99"): + check(assert_type(pd.Timedelta(1, "w"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "D"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.Timedelta(1, "d"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"): + check(assert_type(pd.Timedelta(1, "d"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "days"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "day"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "hours"), pd.Timedelta), pd.Timedelta) @@ -421,9 +423,11 @@ def test_timedelta_construction() -> None: check(assert_type(pd.Timedelta(1, "nanosecond"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 W"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.Timedelta("1 w"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'w' is deprecated", lower="2.2.99"): + check(assert_type(pd.Timedelta("1 w"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 D"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.Timedelta("1 d"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"): + check(assert_type(pd.Timedelta("1 d"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 days"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 day"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 hours"), pd.Timedelta), pd.Timedelta) @@ -1518,7 +1522,13 @@ def test_timestamp_misc_methods() -> None: check(assert_type(ts2.round("1s", ambiguous=False), pd.Timestamp), pd.Timestamp) check(assert_type(ts2.round("1s", ambiguous="NaT"), pd.Timestamp), pd.Timestamp) - with pytest_warns_bounded(FutureWarning, "'H' is deprecated ", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated ", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type(ts2.round("2H", nonexistent="shift_forward"), pd.Timestamp), pd.Timestamp, @@ -1553,7 +1563,13 @@ def test_timestamp_misc_methods() -> None: check(assert_type(ts2.ceil("1s", ambiguous=False), pd.Timestamp), pd.Timestamp) check(assert_type(ts2.ceil("1s", ambiguous="NaT"), pd.Timestamp), pd.Timestamp) - with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type(ts2.ceil("2H", nonexistent="shift_forward"), pd.Timestamp), pd.Timestamp, @@ -1587,7 +1603,13 @@ def test_timestamp_misc_methods() -> None: check(assert_type(ts2.floor("1s", ambiguous=False), pd.Timestamp), pd.Timestamp) check(assert_type(ts2.floor("1s", ambiguous="NaT"), pd.Timestamp), pd.Timestamp) - with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type(ts2.floor("2H", nonexistent="shift_forward"), pd.Timestamp), pd.Timestamp, diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index a61bb92ca..eabbc3707 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -757,11 +757,13 @@ def test_types_to_numpy() -> None: check(assert_type(td_s.to_numpy(na_value=pd.Timedelta(0)), np.ndarray), np.ndarray) -def test_to_timdelta_units() -> None: +def test_to_timedelta_units() -> None: check(assert_type(pd.to_timedelta(1, "W"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.to_timedelta(1, "w"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'w' is deprecated", lower="2.2.99"): + check(assert_type(pd.to_timedelta(1, "w"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "D"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.to_timedelta(1, "d"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"): + check(assert_type(pd.to_timedelta(1, "d"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "days"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "day"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "hours"), pd.Timedelta), pd.Timedelta) diff --git a/tests/test_utility.py b/tests/test_utility.py index beb3d7592..3d668daaa 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -10,6 +10,7 @@ from tests import ( NUMPY20, + PD_LTE_22, check, pytest_warns_bounded, ) @@ -23,7 +24,7 @@ def test_show_version(): version_str=platform.python_version(), ): context: AbstractContextManager - if NUMPY20: # https://github.com/PyTables/PyTables/issues/1172 + if PD_LTE_22 and NUMPY20: # https://github.com/PyTables/PyTables/issues/1172 context = pytest.raises(ValueError) else: context = nullcontext()