diff --git a/tests/test_frame.py b/tests/test_frame.py index b7108d1a5..19736de36 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1299,7 +1299,7 @@ def test_groupby_series_methods() -> None: gb.min().loc[2] gb.nlargest().loc[2] gb.nsmallest().loc[2] - gb.nth(0).loc[2] + gb.nth(0).loc[1] def test_indexslice_setitem(): diff --git a/tests/test_indexes.py b/tests/test_indexes.py index 18e8e0203..1eab40612 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -7,10 +7,12 @@ from numpy import typing as npt import pandas as pd from pandas.core.indexes.numeric import NumericIndex -import pytest from typing_extensions import assert_type -from tests import check +from tests import ( + check, + pytest_warns_bounded, +) def test_index_unique() -> None: @@ -166,7 +168,7 @@ def test_index_relops() -> None: def test_range_index_union(): - with pytest.warns(FutureWarning, match="pandas.Int64Index"): + with pytest_warns_bounded(FutureWarning, match="pandas.Int64Index", upper="1.5.99"): check( assert_type( pd.RangeIndex(0, 10).union(pd.RangeIndex(10, 20)), diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 456f94947..507e42125 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -23,6 +23,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + pytest_warns_bounded, ) @@ -752,14 +753,20 @@ def test_factorize() -> None: def test_index_unqiue() -> None: ci = pd.CategoricalIndex(["a", "b", "a", "c"]) dti = pd.DatetimeIndex([pd.Timestamp(2000, 1, 1)]) - with pytest.warns(FutureWarning, match="pandas.Float64Index is deprecated"): + with pytest_warns_bounded( + FutureWarning, match="pandas.Float64Index is deprecated", upper="1.5.99" + ): fi = pd.Float64Index([1.0, 2.0]) i = pd.Index(["a", "b", "c", "a"]) - with pytest.warns(FutureWarning, match="pandas.Int64Index is deprecated"): + with pytest_warns_bounded( + FutureWarning, match="pandas.Int64Index is deprecated", upper="1.5.99" + ): i64i = pd.Int64Index([1, 2, 3, 4]) pi = pd.period_range("2000Q1", periods=2, freq="Q") ri = pd.RangeIndex(0, 10) - with pytest.warns(FutureWarning, match="pandas.UInt64Index is deprecated"): + with pytest_warns_bounded( + FutureWarning, match="pandas.UInt64Index is deprecated", upper="1.5.99" + ): ui = pd.UInt64Index([0, 1, 2, 3, 5]) tdi = pd.timedelta_range("1 day", "10 days", periods=10) mi = pd.MultiIndex.from_product([["a", "b"], ["apple", "banana"]]) diff --git a/tests/test_scalars.py b/tests/test_scalars.py index 5c788909d..812fef04b 100644 --- a/tests/test_scalars.py +++ b/tests/test_scalars.py @@ -13,7 +13,6 @@ import numpy as np from numpy import typing as npt import pandas as pd -import pytest import pytz from typing_extensions import ( TypeAlias, @@ -29,6 +28,7 @@ from tests import ( TYPE_CHECKING_INVALID_USAGE, check, + pytest_warns_bounded, ) from pandas.tseries.offsets import Day @@ -338,7 +338,7 @@ def test_timedelta_add_sub() -> None: def test_timedelta_mul_div() -> None: td = pd.Timedelta("1 day") - with pytest.warns(FutureWarning): + with pytest_warns_bounded(FutureWarning, upper="1.5.99", match=""): i_idx = cast(pd.Int64Index, pd.Index([1, 2, 3], dtype=int)) f_idx = cast(pd.Float64Index, pd.Index([1.2, 2.2, 3.4], dtype=float)) @@ -455,7 +455,7 @@ def test_timedelta_mul_div() -> None: def test_timedelta_mod_abs_unary() -> None: td = pd.Timedelta("1 day") - with pytest.warns(FutureWarning): + with pytest_warns_bounded(FutureWarning, upper="1.5.99", match=""): i_idx = cast(pd.Int64Index, pd.Index([1, 2, 3], dtype=int)) f_idx = cast(pd.Float64Index, pd.Index([1.2, 2.2, 3.4], dtype=float)) diff --git a/tests/test_series.py b/tests/test_series.py index f37631d6a..a7ba5d02a 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -36,6 +36,7 @@ PD_LTE_15, TYPE_CHECKING_INVALID_USAGE, check, + pytest_warns_bounded, ) if TYPE_CHECKING: @@ -260,15 +261,25 @@ def test_types_shift() -> None: def test_types_rank() -> None: s = pd.Series([1, 1, 2, 5, 6, np.nan, "milion"]) - with pytest.warns(FutureWarning, match="Dropping of nuisance columns"): + with pytest_warns_bounded( + FutureWarning, match="Dropping of nuisance columns", upper="1.5.99" + ): s.rank() - with pytest.warns(FutureWarning, match="Dropping of nuisance columns"): + with pytest_warns_bounded( + FutureWarning, match="Dropping of nuisance columns", upper="1.5.99" + ): s.rank(axis=0, na_option="bottom") - with pytest.warns(FutureWarning, match="Dropping of nuisance columns"): + with pytest_warns_bounded( + FutureWarning, match="Dropping of nuisance columns", upper="1.5.99" + ): s.rank(method="min", pct=True) - with pytest.warns(FutureWarning, match="Dropping of nuisance columns"): + with pytest_warns_bounded( + FutureWarning, match="Dropping of nuisance columns", upper="1.5.99" + ): s.rank(method="dense", ascending=True) - with pytest.warns(FutureWarning, match="Calling Series.rank with numeric_only"): + with pytest_warns_bounded( + FutureWarning, match="Calling Series.rank with numeric_only", upper="1.5.99" + ): s.rank(method="first", numeric_only=True) s2 = pd.Series([1, 1, 2, 5, 6, np.nan]) s2.rank(method="first", numeric_only=True) @@ -643,17 +654,25 @@ def test_types_transform() -> None: def test_types_describe() -> None: s = pd.Series([1, 2, 3, np.datetime64("2000-01-01")]) - with pytest.warns(DeprecationWarning, match="elementwise comparison failed"): + with pytest_warns_bounded( + DeprecationWarning, match="elementwise comparison failed", upper="1.5.99" + ): s.describe() - with pytest.warns(DeprecationWarning, match="elementwise comparison failed"): + with pytest_warns_bounded( + DeprecationWarning, match="elementwise comparison failed", upper="1.5.99" + ): s.describe(percentiles=[0.5], include="all") - with pytest.warns(DeprecationWarning, match="elementwise comparison failed"): + with pytest_warns_bounded( + DeprecationWarning, match="elementwise comparison failed", upper="1.5.99" + ): s.describe(exclude=np.number) if PD_LTE_15: # datetime_is_numeric param added in 1.1.0 # https://pandas.pydata.org/docs/whatsnew/v1.1.0.html # Remove in 2.0.0 - with pytest.warns(DeprecationWarning, match="elementwise comparison failed"): + with pytest_warns_bounded( + DeprecationWarning, match="elementwise comparison failed", upper="1.5.99" + ): s.describe(datetime_is_numeric=True)