Skip to content

fix pyright and pytest --nightly #819

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

Merged
merged 3 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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: 23.10.0
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.1
rev: v0.1.6
hooks:
- id: ruff
args: [
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/multi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class MultiIndex(Index[Any]):
def equals(self, other) -> bool: ...
def equal_levels(self, other): ...
def union(self, other, sort=...): ...
def intersection(self, other, sort: bool = ...): ...
def intersection(self, other: list | Self, sort: bool = ...): ...
def difference(self, other, sort=...): ...
def astype(self, dtype: DtypeArg, copy: bool = ...) -> Self: ...
def insert(self, loc, item): ...
Expand Down
28 changes: 12 additions & 16 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,7 @@ 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(UserWarning, "'M' will be deprecated", lower="2.1.99"):
df.resample("M", on="date")
# origin and offset params added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
df.resample("M", on="date")
df.resample("20min", origin="epoch", offset=pd.Timedelta(2, "minutes"), on="date")


Expand Down Expand Up @@ -1352,18 +1350,17 @@ def test_pipe() -> None:
def foo(df: pd.DataFrame) -> pd.DataFrame:
return pd.DataFrame(df)

with pytest_warns_bounded(UserWarning, "'M' will be deprecated", lower="2.1.99"):
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("M", on="week_starting")
.pipe(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("M", on="week_starting")
.pipe(foo)
)

check(assert_type(val, pd.DataFrame), pd.DataFrame)

Expand Down Expand Up @@ -2491,8 +2488,7 @@ 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(UserWarning, "'M' will be deprecated", lower="2.1.99"):
resampler = frame.resample("M", group_keys=True)
resampler = frame.resample("M", group_keys=True)
assert_type(resampler, "Resampler[pd.DataFrame]")

def f(s: pd.DataFrame) -> pd.Series:
Expand Down
20 changes: 9 additions & 11 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from tests import (
TYPE_CHECKING_INVALID_USAGE,
check,
pytest_warns_bounded,
)


Expand Down Expand Up @@ -252,17 +251,16 @@ def test_interval_range():
pd.IntervalIndex,
pd.Interval,
)
with pytest_warns_bounded(UserWarning, "'M' will be deprecated", lower="2.1.99"):
check(
assert_type(
pd.interval_range(
pd.Timestamp(2000, 1, 1), pd.Timestamp(2010, 1, 1), freq="1M"
),
"pd.IntervalIndex[pd.Interval[pd.Timestamp]]",
check(
assert_type(
pd.interval_range(
pd.Timestamp(2000, 1, 1), pd.Timestamp(2010, 1, 1), freq="1M"
),
pd.IntervalIndex,
pd.Interval,
)
"pd.IntervalIndex[pd.Interval[pd.Timestamp]]",
),
pd.IntervalIndex,
pd.Interval,
)
check(
assert_type(
pd.interval_range(
Expand Down
71 changes: 35 additions & 36 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1958,52 +1958,51 @@ def g(x: pd.Series) -> int:
},
index=idx,
)
with pytest_warns_bounded(UserWarning, "'M' will be deprecated", lower="2.1.99"):
check(
assert_type(
pd.pivot_table(
df, index=pd.Index(idx.month), columns=Grouper(key="dt", freq="M")
),
pd.DataFrame,
check(
assert_type(
pd.pivot_table(
df, index=pd.Index(idx.month), columns=Grouper(key="dt", freq="M")
),
pd.DataFrame,
)
check(
assert_type(
pd.pivot_table(
df, index=np.array(idx.month), columns=Grouper(key="dt", freq="M")
),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.pivot_table(
df, index=np.array(idx.month), columns=Grouper(key="dt", freq="M")
),
pd.DataFrame,
)
check(
assert_type(
pd.pivot_table(
df, index=Grouper(key="dt", freq="M"), columns=pd.Index(idx.month)
),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.pivot_table(
df, index=Grouper(key="dt", freq="M"), columns=pd.Index(idx.month)
),
pd.DataFrame,
)
check(
assert_type(
pd.pivot_table(
df, index=Grouper(key="dt", freq="M"), columns=np.array(idx.month)
),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.pivot_table(
df, index=Grouper(key="dt", freq="M"), columns=np.array(idx.month)
),
pd.DataFrame,
)
check(
assert_type(
pd.pivot_table(
df, index=Grouper(freq="A"), columns=Grouper(key="dt", freq="M")
),
pd.DataFrame,
),
pd.DataFrame,
)
check(
assert_type(
pd.pivot_table(
df, index=Grouper(freq="A"), columns=Grouper(key="dt", freq="M")
),
pd.DataFrame,
)
),
pd.DataFrame,
)


def test_argmin_and_argmax_return() -> None:
Expand Down