diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7cd5ce04..7b6ae84d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ ci: autofix_prs: false repos: - repo: https://github.com/python/black - rev: 24.2.0 + rev: 24.3.0 hooks: - id: black - repo: https://github.com/PyCQA/isort @@ -11,7 +11,7 @@ repos: hooks: - id: isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.0 + rev: v0.3.5 hooks: - id: ruff args: [ diff --git a/pandas-stubs/_libs/tslibs/timedeltas.pyi b/pandas-stubs/_libs/tslibs/timedeltas.pyi index 13fc53b8..29c602a0 100644 --- a/pandas-stubs/_libs/tslibs/timedeltas.pyi +++ b/pandas-stubs/_libs/tslibs/timedeltas.pyi @@ -48,12 +48,6 @@ class Components(NamedTuple): # This should be kept consistent with the keys in the dict timedelta_abbrevs # in pandas/_libs/tslibs/timedeltas.pyx TimeDeltaUnitChoices: TypeAlias = Literal[ - "H", - "T", - "S", - "L", - "U", - "N", "W", "w", "D", @@ -68,7 +62,6 @@ TimeDeltaUnitChoices: TypeAlias = Literal[ "minute", "min", "minutes", - "t", "s", "seconds", "sec", @@ -78,20 +71,17 @@ TimeDeltaUnitChoices: TypeAlias = Literal[ "millisecond", "milli", "millis", - "l", "us", "microseconds", "microsecond", "µs", "micro", "micros", - "u", "ns", "nanoseconds", "nano", "nanos", "nanosecond", - "n", ] UnitChoices: TypeAlias = ( diff --git a/pandas-stubs/core/algorithms.pyi b/pandas-stubs/core/algorithms.pyi index f80e2f9c..2fbcfab4 100644 --- a/pandas-stubs/core/algorithms.pyi +++ b/pandas-stubs/core/algorithms.pyi @@ -1,4 +1,3 @@ -from collections.abc import Sequence from typing import ( Literal, overload, @@ -37,12 +36,12 @@ def unique(values: Categorical) -> Categorical: ... @overload def unique(values: Series) -> np.ndarray | ExtensionArray: ... @overload -def unique(values: np.ndarray | list) -> np.ndarray: ... +def unique(values: np.ndarray) -> np.ndarray: ... @overload def unique(values: ExtensionArray) -> ExtensionArray: ... @overload def factorize( - values: Sequence | np.recarray, + values: np.ndarray, sort: bool = ..., use_na_sentinel: bool = ..., size_hint: int | None = ..., diff --git a/pandas-stubs/core/indexes/timedeltas.pyi b/pandas-stubs/core/indexes/timedeltas.pyi index 0099ee09..3e771a33 100644 --- a/pandas-stubs/core/indexes/timedeltas.pyi +++ b/pandas-stubs/core/indexes/timedeltas.pyi @@ -40,7 +40,6 @@ class TimedeltaIndex(DatetimeTimedeltaMixin[Timedelta], TimedeltaIndexProperties | list[str] | Sequence[dt.timedelta | Timedelta | np.timedelta64 | float] ) = ..., - unit: Literal["D", "h", "m", "s", "ms", "us", "ns"] = ..., freq: str | BaseOffset = ..., closed: object = ..., dtype: Literal[" DataFrame: ... diff --git a/tests/test_frame.py b/tests/test_frame.py index 0eb9b8bb..a6658dcc 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -983,12 +983,15 @@ def test_types_groupby() -> None: with pytest_warns_bounded( FutureWarning, "(The provided callable is currently using|The behavior of DataFrame.sum with)", + upper="2.2.99", ): with pytest_warns_bounded( DeprecationWarning, "DataFrameGroupBy.apply operated on the grouping columns", + upper="2.2.99", ): - df7: pd.DataFrame = df.groupby(by="col1").apply(sum) + if PD_LTE_22: + df7: pd.DataFrame = df.groupby(by="col1").apply(sum) df8: pd.DataFrame = df.groupby("col1").transform("sum") s1: pd.Series = df.set_index("col1")["col2"] s2: pd.Series = s1.groupby("col1").transform("sum") @@ -1033,7 +1036,7 @@ def wrapped_min(x: Any) -> Any: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(df.groupby("col1")["col3"].agg(min), pd.Series), pd.Series) check( @@ -1182,7 +1185,7 @@ def test_types_window() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check( assert_type(df.rolling(2).agg(max), pd.DataFrame), @@ -1282,7 +1285,7 @@ def test_types_agg() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable <(built-in function (min|max|mean)|function mean at 0x\w+)> is currently using", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(df.agg(min), pd.Series), pd.Series) check(assert_type(df.agg([min, max]), pd.DataFrame), pd.DataFrame) @@ -1309,7 +1312,7 @@ def test_types_aggregate() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(df.aggregate(min), pd.Series), pd.Series) check(assert_type(df.aggregate([min, max]), pd.DataFrame), pd.DataFrame) @@ -2222,7 +2225,7 @@ def test_frame_stack() -> None: with pytest_warns_bounded( FutureWarning, "The previous implementation of stack is deprecated", - lower="2.1.99", + upper="2.2.99", ): check( assert_type( @@ -2593,23 +2596,22 @@ def test_resample() -> None: # GH 181 N = 10 x = [x for x in range(N)] - with pytest_warns_bounded(FutureWarning, "'T' is deprecated", lower="2.1.99"): - index = pd.date_range("1/1/2000", periods=N, freq="T") - x = [x for x in range(N)] - df = pd.DataFrame({"a": x, "b": x, "c": x}, index=index) - check(assert_type(df.resample("2T").std(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").var(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").quantile(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").sum(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").prod(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").min(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").max(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").first(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").last(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").mean(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").sem(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").median(), pd.DataFrame), pd.DataFrame) - check(assert_type(df.resample("2T").ohlc(), pd.DataFrame), pd.DataFrame) + index = pd.date_range("1/1/2000", periods=N, freq="min") + x = [x for x in range(N)] + df = pd.DataFrame({"a": x, "b": x, "c": x}, index=index) + check(assert_type(df.resample("2min").std(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").var(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").quantile(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").sum(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").prod(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").min(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").max(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").first(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").last(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").mean(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").sem(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").median(), pd.DataFrame), pd.DataFrame) + check(assert_type(df.resample("2min").ohlc(), pd.DataFrame), pd.DataFrame) def test_loc_set() -> None: @@ -2916,7 +2918,7 @@ def test_getattr_and_dataframe_groupby() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(df.groupby("col1").col3.agg(min), pd.Series), pd.Series) check( diff --git a/tests/test_groupby.py b/tests/test_groupby.py index 9e356a4c..dc191b88 100644 --- a/tests/test_groupby.py +++ b/tests/test_groupby.py @@ -130,7 +130,7 @@ def test_frame_groupby_resample() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check( assert_type(GB_DF.resample("ME").aggregate(np.sum), DataFrame), @@ -193,7 +193,7 @@ def df2scalar(val: DataFrame) -> float: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(GB_DF.resample("ME").aggregate(np.sum), DataFrame) check(GB_DF.resample("ME").aggregate([np.mean]), DataFrame) @@ -344,7 +344,7 @@ def test_series_groupby_resample() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check( assert_type( @@ -421,7 +421,7 @@ def s2scalar(val: Series) -> float: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(GB_S.resample("ME").aggregate(np.sum), Series) check(GB_S.resample("ME").aggregate([np.mean]), DataFrame) @@ -468,7 +468,7 @@ def test_frame_groupby_rolling() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(GB_DF.rolling(1).aggregate(np.sum), DataFrame), DataFrame) check(assert_type(GB_DF.rolling(1).agg(np.sum), DataFrame), DataFrame) @@ -512,7 +512,7 @@ def df2scalar(val: DataFrame) -> float: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(GB_DF.rolling(1).aggregate(np.sum), DataFrame) check(GB_DF.rolling(1).aggregate([np.mean]), DataFrame) @@ -590,7 +590,7 @@ def test_series_groupby_rolling() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(GB_S.rolling(1).aggregate("sum"), Series), Series) check(assert_type(GB_S.rolling(1).aggregate(np.sum), Series), Series) @@ -663,7 +663,7 @@ def test_frame_groupby_expanding() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(GB_DF.expanding(1).aggregate(np.sum), DataFrame), DataFrame) check(assert_type(GB_DF.expanding(1).agg(np.sum), DataFrame), DataFrame) @@ -709,7 +709,7 @@ def df2scalar(val: DataFrame) -> float: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(GB_DF.expanding(1).aggregate(np.sum), DataFrame) check(GB_DF.expanding(1).aggregate([np.mean]), DataFrame) @@ -789,7 +789,7 @@ def test_series_groupby_expanding() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(GB_S.expanding(1).aggregate("sum"), Series), Series) check(assert_type(GB_S.expanding(1).aggregate(np.sum), Series), Series) @@ -857,7 +857,7 @@ def test_frame_groupby_ewm() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(GB_DF.ewm(1).aggregate(np.sum), DataFrame), DataFrame) check(assert_type(GB_DF.ewm(1).agg(np.sum), DataFrame), DataFrame) @@ -888,7 +888,7 @@ def test_frame_groupby_ewm() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(GB_DF.ewm(1).aggregate(np.sum), DataFrame) check(GB_DF.ewm(1).aggregate([np.mean]), DataFrame) @@ -961,7 +961,7 @@ def test_series_groupby_ewm() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(GB_S.ewm(1).aggregate("sum"), Series), Series) check(assert_type(GB_S.ewm(1).aggregate(np.sum), Series), Series) diff --git a/tests/test_indexes.py b/tests/test_indexes.py index c3203217..84c3c491 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -14,6 +14,7 @@ from pandas._typing import Dtype # noqa: F401 from tests import ( + PD_LTE_22, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, @@ -866,7 +867,11 @@ def test_getitem() -> None: iri = pd.RangeIndex(0, 10) check(assert_type(iri, pd.RangeIndex), pd.RangeIndex, int) check(assert_type(iri[0], int), int) - check(assert_type(iri[[0, 2, 4]], pd.Index), pd.Index, np.integer) + check( + assert_type(iri[[0, 2, 4]], pd.Index), + pd.Index, + np.integer if PD_LTE_22 else int, + ) mi = pd.MultiIndex.from_product([["a", "b"], ["c", "d"]], names=["ab", "cd"]) check(assert_type(mi, pd.MultiIndex), pd.MultiIndex) diff --git a/tests/test_io.py b/tests/test_io.py index 6bc53c25..df2b8480 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -49,11 +49,9 @@ from typing_extensions import assert_type from tests import ( - PD_LTE_22, TYPE_CHECKING_INVALID_USAGE, WINDOWS, check, - pytest_warns_bounded, ) from pandas.io.api import to_pickle @@ -428,23 +426,15 @@ def test_hdf_series(): def test_spss(): - if PD_LTE_22: - warning_class = FutureWarning - message = "Placeholder" - else: - warning_class = pd.errors.ChainedAssignmentError # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue] - message = "A value is trying to be set on a copy of a DataFrame" - path = Path(CWD, "data", "labelled-num.sav") - with pytest_warns_bounded(warning_class, message, "2.3.0"): - check( - assert_type(read_spss(path, convert_categoricals=True), DataFrame), - DataFrame, - ) - check( - assert_type(read_spss(str(path), usecols=["VAR00002"]), DataFrame), - DataFrame, - ) + check( + assert_type(read_spss(path, convert_categoricals=True), DataFrame), + DataFrame, + ) + check( + assert_type(read_spss(str(path), usecols=["VAR00002"]), DataFrame), + DataFrame, + ) def test_json(): diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 8bb10849..c7d777be 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -27,6 +27,7 @@ from pandas._typing import Scalar from tests import ( + PD_LTE_22, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, @@ -243,7 +244,12 @@ def test_concat_args() -> None: pd.DataFrame, ) check(assert_type(pd.concat([df, df2], sort=True), pd.DataFrame), pd.DataFrame) - check(assert_type(pd.concat([df, df2], copy=True), pd.DataFrame), pd.DataFrame) + with pytest_warns_bounded( + DeprecationWarning, + "The copy keyword is deprecated and will be removed in a future version.", + lower="2.2.99", + ): + check(assert_type(pd.concat([df, df2], copy=True), pd.DataFrame), pd.DataFrame) check(assert_type(pd.concat([df, df2], join="inner"), pd.DataFrame), pd.DataFrame) check(assert_type(pd.concat([df, df2], join="outer"), pd.DataFrame), pd.DataFrame) check(assert_type(pd.concat([df, df2], axis=0), pd.DataFrame), pd.DataFrame) @@ -483,13 +489,7 @@ def test_unique() -> None: pd.DatetimeIndex, ) - with pytest_warns_bounded( - FutureWarning, - "unique with argument that is not not a Series, Index, ExtensionArray, " - "or np.ndarray is deprecated", - lower="2.0.99", - ): - check(assert_type(pd.unique(list("baabc")), np.ndarray), np.ndarray) + check(assert_type(pd.unique(np.array(list("baabc"))), np.ndarray), np.ndarray) check( assert_type( @@ -516,25 +516,13 @@ def test_unique() -> None: ), pd.Categorical, ) - with pytest_warns_bounded( - FutureWarning, - "unique with argument that is not not a Series, Index, ExtensionArray, " - "or np.ndarray is deprecated", - lower="2.0.99", - ): - check( - assert_type( - pd.unique([("a", "b"), ("b", "a"), ("a", "c"), ("b", "a")]), np.ndarray - ), - np.ndarray, - ) check( assert_type(pd.unique(pd.Index(["a", "b", "c", "a"])), np.ndarray), - np.ndarray, + np.ndarray if PD_LTE_22 else pd.Index, ) check( assert_type(pd.unique(pd.RangeIndex(0, 10)), np.ndarray), - np.ndarray, + np.ndarray if PD_LTE_22 else pd.Index, ) check( assert_type(pd.unique(pd.Categorical(["a", "b", "c", "a"])), pd.Categorical), @@ -552,7 +540,7 @@ def test_unique() -> None: pd.unique(pd.timedelta_range(start="1 day", periods=4)), np.ndarray, ), - np.ndarray, + np.ndarray if PD_LTE_22 else pd.Index, ) @@ -824,15 +812,9 @@ def test_lreshape() -> None: def test_factorize() -> None: - with pytest_warns_bounded( - FutureWarning, - "factorize with argument that is not not a Series, Index, ExtensionArray, " - "or np.ndarray is deprecated", - lower="2.0.99", - ): - codes, uniques = pd.factorize(["b", "b", "a", "c", "b"]) - check(assert_type(codes, np.ndarray), np.ndarray) - check(assert_type(uniques, np.ndarray), np.ndarray) + codes, uniques = pd.factorize(np.array(["b", "b", "a", "c", "b"])) + check(assert_type(codes, np.ndarray), np.ndarray) + check(assert_type(uniques, np.ndarray), np.ndarray) codes, uniques = pd.factorize(np.recarray((1,), dtype=[("x", int)])) check(assert_type(codes, np.ndarray), np.ndarray) @@ -850,21 +832,15 @@ def test_factorize() -> None: check(assert_type(codes, np.ndarray), np.ndarray) check(assert_type(idx_uniques, pd.Index), pd.Index) - with pytest_warns_bounded( - FutureWarning, - "factorize with argument that is not not a Series, Index, ExtensionArray, " - "or np.ndarray is deprecated", - lower="2.0.99", - ): - codes, uniques = pd.factorize("bbacb") - check(assert_type(codes, np.ndarray), np.ndarray) - check(assert_type(uniques, np.ndarray), np.ndarray) + codes, uniques = pd.factorize(np.array(list("bbacb"))) + check(assert_type(codes, np.ndarray), np.ndarray) + check(assert_type(uniques, np.ndarray), np.ndarray) - codes, uniques = pd.factorize( - ["b", "b", "a", "c", "b"], use_na_sentinel=True, size_hint=10 - ) - check(assert_type(codes, np.ndarray), np.ndarray) - check(assert_type(uniques, np.ndarray), np.ndarray) + codes, uniques = pd.factorize( + np.array(["b", "b", "a", "c", "b"]), use_na_sentinel=True, size_hint=10 + ) + check(assert_type(codes, np.ndarray), np.ndarray) + check(assert_type(uniques, np.ndarray), np.ndarray) def test_index_unqiue() -> None: @@ -881,12 +857,16 @@ def test_index_unqiue() -> None: interval_i = pd.interval_range(1, 10, periods=10) check(assert_type(pd.unique(ci), pd.CategoricalIndex), pd.CategoricalIndex) - check(assert_type(pd.unique(dti), np.ndarray), np.ndarray) - check(assert_type(pd.unique(i), np.ndarray), np.ndarray) + check( + assert_type(pd.unique(dti), np.ndarray), np.ndarray if PD_LTE_22 else pd.Index + ) + check(assert_type(pd.unique(i), np.ndarray), np.ndarray if PD_LTE_22 else pd.Index) check(assert_type(pd.unique(pi), pd.PeriodIndex), pd.PeriodIndex) - check(assert_type(pd.unique(ri), np.ndarray), np.ndarray) - check(assert_type(pd.unique(tdi), np.ndarray), np.ndarray) - check(assert_type(pd.unique(mi), np.ndarray), np.ndarray) + check(assert_type(pd.unique(ri), np.ndarray), np.ndarray if PD_LTE_22 else pd.Index) + check( + assert_type(pd.unique(tdi), np.ndarray), np.ndarray if PD_LTE_22 else pd.Index + ) + check(assert_type(pd.unique(mi), np.ndarray), np.ndarray if PD_LTE_22 else pd.Index) check( assert_type(pd.unique(interval_i), "pd.IntervalIndex[pd.Interval[int]]"), pd.IntervalIndex, @@ -1105,7 +1085,6 @@ def test_merge() -> None: left_index=True, right_index=True, sort=True, - copy=True, ), pd.DataFrame, ), @@ -1567,7 +1546,7 @@ def test_crosstab_args() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check( assert_type(pd.crosstab(a, b, values=values, aggfunc=np.sum), pd.DataFrame), @@ -1795,7 +1774,7 @@ def test_pivot_table() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check( assert_type( @@ -1831,7 +1810,7 @@ def test_pivot_table() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check( assert_type( @@ -1899,7 +1878,7 @@ def g(x: pd.Series) -> int: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check( assert_type( @@ -1926,7 +1905,7 @@ def g(x: pd.Series) -> int: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check( assert_type( @@ -2064,7 +2043,7 @@ def g(x: pd.Series) -> int: check( assert_type( pd.pivot_table( - df, index=Grouper(freq="A"), columns=Grouper(key="dt", freq="M") + df, index=Grouper(freq="YE"), columns=Grouper(key="dt", freq="M") ), pd.DataFrame, ), diff --git a/tests/test_resampler.py b/tests/test_resampler.py index be7108b8..27828406 100644 --- a/tests/test_resampler.py +++ b/tests/test_resampler.py @@ -95,7 +95,7 @@ def test_aggregate() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(DF.resample("ME").aggregate(np.sum), DataFrame), DataFrame) check(assert_type(DF.resample("ME").agg(np.sum), DataFrame), DataFrame) @@ -323,7 +323,7 @@ def test_aggregate_series() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(S.resample("ME").aggregate(np.sum), _AggRetType), Series) check(assert_type(S.resample("ME").agg(np.sum), _AggRetType), Series) @@ -400,7 +400,7 @@ def s2scalar(val: Series) -> float: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(S.resample("ME").aggregate(np.sum), Series) check(S.resample("ME").aggregate([np.mean]), DataFrame) @@ -425,7 +425,7 @@ def df2scalar(val: DataFrame) -> float: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(DF.resample("ME").aggregate(np.sum), DataFrame) check(DF.resample("ME").aggregate([np.mean]), DataFrame) diff --git a/tests/test_scalars.py b/tests/test_scalars.py index dc6e0e5e..70479da7 100644 --- a/tests/test_scalars.py +++ b/tests/test_scalars.py @@ -385,18 +385,6 @@ def test_interval_cmp(): def test_timedelta_construction() -> None: - with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "H"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'T' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "T"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'S' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "S"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'L' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "L"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'U' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "U"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'N' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "N"), 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) check(assert_type(pd.Timedelta(1, "D"), pd.Timedelta), pd.Timedelta) @@ -411,8 +399,6 @@ def test_timedelta_construction() -> None: check(assert_type(pd.Timedelta(1, "minute"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "min"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "minutes"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'t' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "t"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "s"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "seconds"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "sec"), pd.Timedelta), pd.Timedelta) @@ -422,23 +408,17 @@ def test_timedelta_construction() -> None: check(assert_type(pd.Timedelta(1, "millisecond"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "milli"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "millis"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'l' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "l"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "us"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "microseconds"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "microsecond"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "µs"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "micro"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "micros"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'u' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "u"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "ns"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "nanoseconds"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "nano"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "nanos"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "nanosecond"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'n' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta(1, "n"), 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) @@ -454,8 +434,6 @@ def test_timedelta_construction() -> None: check(assert_type(pd.Timedelta("1 minute"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 min"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 minutes"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'t' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta("1 t"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 s"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 seconds"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 sec"), pd.Timedelta), pd.Timedelta) @@ -465,23 +443,17 @@ def test_timedelta_construction() -> None: check(assert_type(pd.Timedelta("1 millisecond"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 milli"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 millis"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'l' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta("1 l"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 us"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 microseconds"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 microsecond"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 µs"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 micro"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 micros"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'u' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta("1 u"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 ns"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 nanoseconds"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 nano"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 nanos"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 nanosecond"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded(FutureWarning, "'n' is deprecated", lower="2.1.99"): - check(assert_type(pd.Timedelta("1 n"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(days=1), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(seconds=1), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(microseconds=1), pd.Timedelta), pd.Timedelta) @@ -851,10 +823,7 @@ def test_timedelta_cmp() -> None: c_dt_timedelta = dt.timedelta(days=1) c_timedelta64 = np.timedelta64(1, "D") c_ndarray_td64 = ndarray_td64 - with pytest_warns_bounded( - FutureWarning, "The 'unit' keyword in TimedeltaIndex", lower="2.1.99" - ): - c_timedelta_index = pd.TimedeltaIndex([1, 2, 3], unit="D") + c_timedelta_index = pd.to_timedelta([1, 2, 3], unit="D") c_timedelta_series = pd.Series(pd.TimedeltaIndex([1, 2, 3])) check(assert_type(td < c_timedelta, bool), bool) @@ -1057,10 +1026,7 @@ def test_timedelta_cmp_rhs() -> None: c_dt_timedelta = dt.timedelta(days=1) c_timedelta64 = np.timedelta64(1, "D") c_ndarray_td64 = ndarray_td64 - with pytest_warns_bounded( - FutureWarning, "The 'unit' keyword in TimedeltaIndex", lower="2.1.99" - ): - c_timedelta_index = pd.TimedeltaIndex([1, 2, 3], unit="D") + c_timedelta_index = pd.to_timedelta([1, 2, 3], unit="D") c_timedelta_series = pd.Series(pd.TimedeltaIndex([1, 2, 3])) eq = check(assert_type(c_dt_timedelta == td, bool), bool) @@ -1207,10 +1173,7 @@ def test_timestamp_add_sub() -> None: as_dt_timedelta = dt.timedelta(days=1) as_offset = 3 * Day() - with pytest_warns_bounded( - FutureWarning, "The 'unit' keyword in TimedeltaIndex", lower="2.1.99" - ): - as_timedelta_index = pd.TimedeltaIndex([1, 2, 3], "D") + as_timedelta_index = pd.to_timedelta([1, 2, 3], unit="D") as_timedelta_series = pd.Series(as_timedelta_index) check(assert_type(as_timedelta_series, TimedeltaSeries), pd.Series, pd.Timedelta) as_np_ndarray_td64 = np_td64_arr @@ -1573,7 +1536,7 @@ def test_timestamp_misc_methods() -> None: ) check( assert_type( - ts2.round("2H", nonexistent=pd.Timedelta(24, "H")), pd.Timestamp + ts2.round("2H", nonexistent=pd.Timedelta(24, "h")), pd.Timestamp ), pd.Timestamp, ) @@ -1607,7 +1570,7 @@ def test_timestamp_misc_methods() -> None: ) check( assert_type( - ts2.ceil("2H", nonexistent=pd.Timedelta(24, "H")), pd.Timestamp + ts2.ceil("2H", nonexistent=pd.Timedelta(24, "h")), pd.Timestamp ), pd.Timestamp, ) @@ -1642,7 +1605,7 @@ def test_timestamp_misc_methods() -> None: ) check( assert_type( - ts2.floor("2H", nonexistent=pd.Timedelta(24, "H")), pd.Timestamp + ts2.floor("2H", nonexistent=pd.Timedelta(24, "h")), pd.Timestamp ), pd.Timestamp, ) diff --git a/tests/test_series.py b/tests/test_series.py index d34cc3c4..bc5bd575 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -818,7 +818,7 @@ def test_types_groupby_agg() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(s.groupby(level=0).agg(sum), pd.Series), pd.Series) check( @@ -836,7 +836,7 @@ def test_types_groupby_aggregate() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(s.groupby(level=0).aggregate(sum), pd.Series), pd.Series) check( @@ -892,7 +892,7 @@ def test_types_window() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): check( assert_type(s.rolling(2).agg(sum), pd.Series), @@ -962,9 +962,9 @@ def test_types_agg() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable <(built-in function (min|max|mean)|function mean at 0x\w+)> is currently using", - lower="2.0.99", + upper="2.2.99", ): - check(assert_type(s.agg(min), int), np.integer) + check(assert_type(s.agg(min), int), np.integer if PD_LTE_22 else int) check(assert_type(s.agg([min, max]), pd.Series), pd.Series, np.integer) check(assert_type(s.agg({0: min}), pd.Series), pd.Series, np.integer) check( @@ -986,9 +986,9 @@ def test_types_aggregate() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using", - lower="2.0.99", + upper="2.2.99", ): - check(assert_type(s.aggregate(min), int), np.integer) + check(assert_type(s.aggregate(min), int), np.integer if PD_LTE_22 else int) check( assert_type(s.aggregate([min, max]), pd.Series), pd.Series, diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 13176f3d..173a4a41 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -28,6 +28,7 @@ from pandas._typing import TimeUnit from tests import ( + PD_LTE_22, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, @@ -356,9 +357,13 @@ def test_series_dt_accessors() -> None: with pytest_warns_bounded( FutureWarning, "The behavior of DatetimeProperties.to_pydatetime is deprecated", - lower="2.0.99", + upper="2.2.99", ): - check(assert_type(s0.dt.to_pydatetime(), np.ndarray), np.ndarray, dt.datetime) + check( + assert_type(s0.dt.to_pydatetime(), np.ndarray), + np.ndarray if PD_LTE_22 else pd.Series, + dt.datetime, + ) s0_local = s0.dt.tz_localize("UTC") check( assert_type(s0_local, "TimestampSeries"), @@ -757,13 +762,6 @@ def test_to_timdelta_units() -> None: check(assert_type(pd.to_timedelta(1, "minute"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "min"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "minutes"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded( - FutureWarning, - r"'[tl]' is deprecated", - lower="2.0.99", - ): - check(assert_type(pd.to_timedelta(1, "t"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.to_timedelta(1, "l"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "s"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "seconds"), pd.Timedelta), pd.Timedelta) @@ -780,23 +778,11 @@ def test_to_timdelta_units() -> None: check(assert_type(pd.to_timedelta(1, "µs"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "micro"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "micros"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded( - FutureWarning, - r"'u' is deprecated", - lower="2.1.99", - ): - check(assert_type(pd.to_timedelta(1, "u"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "ns"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "nanoseconds"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "nano"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "nanos"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "nanosecond"), pd.Timedelta), pd.Timedelta) - with pytest_warns_bounded( - FutureWarning, - r"'n' is deprecated", - lower="2.1.99", - ): - check(assert_type(pd.to_timedelta(1, "n"), pd.Timedelta), pd.Timedelta) def test_to_timedelta_scalar() -> None: diff --git a/tests/test_windowing.py b/tests/test_windowing.py index 2fe3ba58..db935c31 100644 --- a/tests/test_windowing.py +++ b/tests/test_windowing.py @@ -100,7 +100,7 @@ def test_rolling_aggregate() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(DF.rolling(10).aggregate(np.mean), DataFrame), DataFrame) check( @@ -125,7 +125,7 @@ def _mean(df: DataFrame) -> Series: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(DF.rolling(10).aggregate([np.mean]), DataFrame), DataFrame) check( @@ -195,7 +195,7 @@ def _mean(s: Series) -> float: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(S.rolling(10).aggregate(np.mean), Series), Series) @@ -259,7 +259,7 @@ def test_expanding_aggregate() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(DF.expanding(10).aggregate(np.mean), DataFrame), DataFrame) check( @@ -313,7 +313,7 @@ def test_expanding_aggregate_series() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(S.expanding(10).aggregate(np.mean), Series), Series) check( @@ -342,7 +342,7 @@ def test_ewm_aggregate() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(DF.ewm(span=10).aggregate(np.mean), DataFrame), DataFrame) check( @@ -371,7 +371,7 @@ def test_ewm_aggregate_series() -> None: with pytest_warns_bounded( FutureWarning, r"The provided callable is currently using ", - lower="2.0.99", + upper="2.2.99", ): check(assert_type(S.ewm(span=10).aggregate(np.mean), Series), Series) check(