Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nightly #904

Merged
merged 7 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
rev: v0.3.5
hooks:
- id: ruff
args: [
Expand Down
10 changes: 0 additions & 10 deletions pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Comment on lines -51 to -56
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove "t", "u", "l" and "n" as well

"W",
"w",
"D",
Expand All @@ -68,7 +62,6 @@ TimeDeltaUnitChoices: TypeAlias = Literal[
"minute",
"min",
"minutes",
"t",
"s",
"seconds",
"sec",
Expand All @@ -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 = (
Expand Down
5 changes: 2 additions & 3 deletions pandas-stubs/core/algorithms.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections.abc import Sequence
from typing import (
Literal,
overload,
Expand Down Expand Up @@ -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 = ...,
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/indexes/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = ...,
Dr-Irv marked this conversation as resolved.
Show resolved Hide resolved
freq: str | BaseOffset = ...,
closed: object = ...,
dtype: Literal["<m8[ns]"] = ...,
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/reshape/merge.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def merge(
suffixes: (
list[str | None] | tuple[str, str] | tuple[None, str] | tuple[str, None]
) = ...,
copy: bool = ...,
indicator: bool | str = ...,
validate: ValidationOptions = ...,
) -> DataFrame: ...
Expand Down
50 changes: 26 additions & 24 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,12 +983,15 @@ def test_types_groupby() -> None:
with pytest_warns_bounded(
FutureWarning,
"(The provided callable <built-in function sum> 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")
Expand Down Expand Up @@ -1033,7 +1036,7 @@ def wrapped_min(x: Any) -> Any:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <built-in function (min|max)> 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(
Expand Down Expand Up @@ -1182,7 +1185,7 @@ def test_types_window() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <built-in function (min|max)> is currently using",
lower="2.0.99",
upper="2.2.99",
):
check(
assert_type(df.rolling(2).agg(max), pd.DataFrame),
Expand Down Expand Up @@ -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)
Expand All @@ -1309,7 +1312,7 @@ def test_types_aggregate() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <built-in function (min|max)> 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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -2916,7 +2918,7 @@ def test_getattr_and_dataframe_groupby() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <built-in function (min|max)> 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(
Expand Down
26 changes: 13 additions & 13 deletions tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_frame_groupby_resample() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> is currently using ",
lower="2.0.99",
upper="2.2.99",
):
check(
assert_type(GB_DF.resample("ME").aggregate(np.sum), DataFrame),
Expand Down Expand Up @@ -193,7 +193,7 @@ def df2scalar(val: DataFrame) -> float:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -344,7 +344,7 @@ def test_series_groupby_resample() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> is currently using ",
lower="2.0.99",
upper="2.2.99",
):
check(
assert_type(
Expand Down Expand Up @@ -421,7 +421,7 @@ def s2scalar(val: Series) -> float:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -468,7 +468,7 @@ def test_frame_groupby_rolling() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -512,7 +512,7 @@ def df2scalar(val: DataFrame) -> float:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -590,7 +590,7 @@ def test_series_groupby_rolling() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -663,7 +663,7 @@ def test_frame_groupby_expanding() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -709,7 +709,7 @@ def df2scalar(val: DataFrame) -> float:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -789,7 +789,7 @@ def test_series_groupby_expanding() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -857,7 +857,7 @@ def test_frame_groupby_ewm() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -888,7 +888,7 @@ def test_frame_groupby_ewm() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down Expand Up @@ -961,7 +961,7 @@ def test_series_groupby_ewm() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> 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)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 8 additions & 18 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down