Skip to content

Commit

Permalink
Update pyright, pandas, mypy versions. Fix nightly tests (#920)
Browse files Browse the repository at this point in the history
* update pyright, mypy, pandas versions

* fix nightly tests

* fix a few more nightly tests

* replace try/except with if/else
  • Loading branch information
Dr-Irv committed May 13, 2024
1 parent 2a0d375 commit 6dfa03e
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 208 deletions.
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
216 changes: 134 additions & 82 deletions tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,44 @@ 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),
)
if PD_LTE_22:
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),
)
else:

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 +422,31 @@ 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))
if PD_LTE_22:
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)
)
else:
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 +904,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 +1015,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

0 comments on commit 6dfa03e

Please sign in to comment.