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

Update pyright, pandas, mypy versions. Fix nightly tests #920

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ types-pytz = ">= 2022.1.1"
numpy = { version = ">=1.26.0", python = "<3.13" }

[tool.poetry.group.dev.dependencies]
mypy = "1.9.0"
pandas = "2.2.1"
mypy = "1.10.0"
pandas = "2.2.2"
pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = ">=1.1.354"
pyright = ">=1.1.362"
poethepoet = ">=0.16.5"
loguru = ">=0.6.0"
typing-extensions = ">=4.4.0"
Expand Down
82 changes: 49 additions & 33 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1953,44 +1953,60 @@ class ReadCsvKwargs(TypedDict):
),
pd.DataFrame,
)
parse_dates_2 = {"combined_date": ["Year", "Month", "Day"]}
with pytest_warns_bounded(
FutureWarning, "Support for nested sequences", lower="2.1.99"
):
check(
assert_type(pd.read_csv(path, parse_dates=parse_dates_2), pd.DataFrame),
pd.DataFrame,
)
parse_dates_3 = {"combined_date": [1, 2, 3]}
with pytest_warns_bounded(
FutureWarning, "Support for nested sequences", lower="2.1.99"
):
check(
assert_type(pd.read_csv(path, parse_dates=parse_dates_3), pd.DataFrame),
pd.DataFrame,
)
# MyPy calls this Dict[str, object] by default which necessitates the explicit annotation (Pyright does not)
parse_dates_4: dict[str, list[str | int]] = {"combined_date": [1, "Month", 3]}
with pytest_warns_bounded(
FutureWarning, "Support for nested sequences", lower="2.1.99"
):
check(
assert_type(pd.read_csv(path, parse_dates=parse_dates_4), pd.DataFrame),
pd.DataFrame,
)
if PD_LTE_22:
parse_dates_2 = {"combined_date": ["Year", "Month", "Day"]}
with pytest_warns_bounded(
FutureWarning,
"Support for nested sequences",
lower="2.1.99",
):
check(
assert_type(
pd.read_csv(path, parse_dates=parse_dates_2), pd.DataFrame
),
pd.DataFrame,
)
parse_dates_3 = {"combined_date": [1, 2, 3]}
with pytest_warns_bounded(
FutureWarning, "Support for nested sequences", lower="2.1.99"
):
check(
assert_type(
pd.read_csv(path, parse_dates=parse_dates_3), pd.DataFrame
),
pd.DataFrame,
)
# MyPy calls this Dict[str, object] by default which necessitates the explicit annotation (Pyright does not)
parse_dates_4: dict[str, list[str | int]] = {
"combined_date": [1, "Month", 3]
}
with pytest_warns_bounded(
FutureWarning, "Support for nested sequences", lower="2.1.99"
):
check(
assert_type(
pd.read_csv(path, parse_dates=parse_dates_4), pd.DataFrame
),
pd.DataFrame,
)

parse_dates_6 = [[1, 2, 3]]
with pytest_warns_bounded(
FutureWarning,
"Support for nested sequences",
lower="2.1.99",
):
check(
assert_type(
pd.read_csv(path, parse_dates=parse_dates_6), pd.DataFrame
),
pd.DataFrame,
)
parse_dates_5 = [0]
check(
assert_type(pd.read_csv(path, parse_dates=parse_dates_5), pd.DataFrame),
pd.DataFrame,
)
parse_dates_6 = [[1, 2, 3]]
with pytest_warns_bounded(
FutureWarning, "Support for nested sequences", lower="2.1.99"
):
check(
assert_type(pd.read_csv(path, parse_dates=parse_dates_6), pd.DataFrame),
pd.DataFrame,
)


def test_groupby_series_methods() -> None:
Expand Down
225 changes: 143 additions & 82 deletions tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,49 @@ def df2scalar(val: DataFrame) -> float:
)

# interpolate
check(assert_type(GB_DF.resample("ME").interpolate(), DataFrame), DataFrame)
check(
assert_type(GB_DF.resample("ME").interpolate(method="linear"), DataFrame),
DataFrame,
)
check(
assert_type(GB_DF.resample("ME").interpolate(inplace=True), None),
type(None),
)
try:
Copy link
Member

Choose a reason for hiding this comment

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

should this be if PD_LTE_22:?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Not sure why I went that direction. Fixed in 47aac27

check(assert_type(GB_DF.resample("ME").interpolate(), DataFrame), DataFrame)
check(
assert_type(
GB_DF.resample("ME").interpolate(method="linear"), DataFrame
),
DataFrame,
)
check(
assert_type(GB_DF.resample("ME").interpolate(inplace=True), None),
type(None),
)
except NotImplementedError:
# In version 3.0, this is not allowed
if PD_LTE_22:
raise RuntimeError("Should not happen")

if not PD_LTE_22:

def resample_interpolate(x: DataFrame) -> DataFrame:
return x.resample("ME").interpolate()

check(
assert_type(
GB_DF.apply(resample_interpolate, include_groups=False),
DataFrame,
),
DataFrame,
)

def resample_interpolate_linear(x: DataFrame) -> DataFrame:
return x.resample("ME").interpolate(method="linear")

check(
assert_type(
GB_DF.apply(
resample_interpolate_linear,
include_groups=False,
),
DataFrame,
),
DataFrame,
)

# pipe
def g(val: Resampler[DataFrame]) -> DataFrame:
Expand Down Expand Up @@ -393,10 +427,35 @@ def f(val: Series) -> float:
check(assert_type(GB_S.resample("ME").asfreq(-1.0), "Series[float]"), Series, float)

# interpolate
check(
assert_type(GB_S.resample("ME").interpolate(), "Series[float]"), Series, float
)
check(assert_type(GB_S.resample("ME").interpolate(inplace=True), None), type(None))
try:
check(
assert_type(GB_S.resample("ME").interpolate(), "Series[float]"),
Series,
float,
)
check(
assert_type(GB_S.resample("ME").interpolate(inplace=True), None), type(None)
)
except NotImplementedError:
if PD_LTE_22:
raise RuntimeError("should not happen")

if not PD_LTE_22:
check(
assert_type(
GB_S.apply(lambda x: x.resample("ME").interpolate()), "Series[float]"
),
Series,
float,
)
# This fails typing checks, and should work in 3.0, but is a bug in main
# https://github.com/pandas-dev/pandas/issues/58690
# check(
# assert_type(
# GB_S.apply(lambda x: x.resample("ME").interpolate(inplace=True)), None
# ),
# type(None),
# )

# pipe
def g(val: Resampler[Series]) -> float:
Expand Down Expand Up @@ -854,62 +913,63 @@ def test_frame_groupby_ewm() -> None:
check(assert_type(GB_DF.ewm(1).var(), DataFrame), DataFrame)

# aggregate
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> is currently using ",
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)
check(
assert_type(GB_DF.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
DataFrame,
)
check(
assert_type(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame),
DataFrame,
)
check(
assert_type(
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": np.mean}),
if PD_LTE_22:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> is currently using ",
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)
check(
assert_type(GB_DF.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
DataFrame,
),
DataFrame,
)
check(
assert_type(
GB_DF.ewm(1).aggregate({"col1": ["sum", np.mean], "col2": np.mean}),
)
check(
assert_type(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame),
DataFrame,
),
DataFrame,
)
)
check(
assert_type(
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": np.mean}),
DataFrame,
),
DataFrame,
)
check(
assert_type(
GB_DF.ewm(1).aggregate({"col1": ["sum", np.mean], "col2": np.mean}),
DataFrame,
),
DataFrame,
)

# aggregate combinations
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> is currently using ",
upper="2.2.99",
):
check(GB_DF.ewm(1).aggregate(np.sum), DataFrame)
check(GB_DF.ewm(1).aggregate([np.mean]), DataFrame)
check(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame)
check(GB_DF.ewm(1).aggregate({"col1": np.sum}), DataFrame)
check(
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": np.mean}),
DataFrame,
)
check(
GB_DF.ewm(1).aggregate({"col1": [np.sum], "col2": ["sum", np.mean]}),
DataFrame,
)
check(
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": ["sum", np.mean]}),
DataFrame,
)
check(
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": [np.mean]}),
DataFrame,
)
# aggregate combinations
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <function (sum|mean) .*> is currently using ",
upper="2.2.99",
):
check(GB_DF.ewm(1).aggregate(np.sum), DataFrame)
check(GB_DF.ewm(1).aggregate([np.mean]), DataFrame)
check(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame)
check(GB_DF.ewm(1).aggregate({"col1": np.sum}), DataFrame)
check(
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": np.mean}),
DataFrame,
)
check(
GB_DF.ewm(1).aggregate({"col1": [np.sum], "col2": ["sum", np.mean]}),
DataFrame,
)
check(
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": ["sum", np.mean]}),
DataFrame,
)
check(
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": [np.mean]}),
DataFrame,
)
check(GB_DF.ewm(1).aggregate("sum"), DataFrame)

# getattr
Expand Down Expand Up @@ -964,22 +1024,23 @@ def test_series_groupby_ewm() -> None:
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)
check(assert_type(GB_S.ewm(1).agg(np.sum), Series), Series)
check(
assert_type(GB_S.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
DataFrame,
)
check(
assert_type(GB_S.ewm(1).aggregate(["sum", np.mean]), DataFrame),
DataFrame,
)
check(
assert_type(
GB_S.ewm(1).aggregate({"col1": "sum", "col2": np.mean}), DataFrame
),
DataFrame,
)
if PD_LTE_22:
check(assert_type(GB_S.ewm(1).aggregate(np.sum), Series), Series)
check(assert_type(GB_S.ewm(1).agg(np.sum), Series), Series)
check(
assert_type(GB_S.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
DataFrame,
)
check(
assert_type(GB_S.ewm(1).aggregate(["sum", np.mean]), DataFrame),
DataFrame,
)
check(
assert_type(
GB_S.ewm(1).aggregate({"col1": "sum", "col2": np.mean}), DataFrame
),
DataFrame,
)

# iter
iterator = iter(GB_S.ewm(1))
Expand Down
11 changes: 9 additions & 2 deletions tests/test_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing_extensions import assert_type

from tests import (
PD_LTE_22,
TYPE_CHECKING_INVALID_USAGE,
check,
pytest_warns_bounded,
Expand Down Expand Up @@ -148,7 +149,11 @@ def test_interpolate() -> None:


def test_interpolate_inplace() -> None:
check(assert_type(DF.resample("ME").interpolate(inplace=True), None), type(None))
if PD_LTE_22:
# Bug in main see https://github.com/pandas-dev/pandas/issues/58690
check(
assert_type(DF.resample("ME").interpolate(inplace=True), None), type(None)
)


def test_pipe() -> None:
Expand Down Expand Up @@ -360,7 +365,9 @@ def test_interpolate_series() -> None:


def test_interpolate_inplace_series() -> None:
check(assert_type(S.resample("ME").interpolate(inplace=True), None), type(None))
if PD_LTE_22:
# Bug in main see https://github.com/pandas-dev/pandas/issues/58690
check(assert_type(S.resample("ME").interpolate(inplace=True), None), type(None))


def test_pipe_series() -> None:
Expand Down
Loading
Loading