Skip to content

Commit 6dfa03e

Browse files
authored
Update pyright, pandas, mypy versions. Fix nightly tests (#920)
* update pyright, mypy, pandas versions * fix nightly tests * fix a few more nightly tests * replace try/except with if/else
1 parent 2a0d375 commit 6dfa03e

7 files changed

+297
-208
lines changed

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ types-pytz = ">= 2022.1.1"
3535
numpy = { version = ">=1.26.0", python = "<3.13" }
3636

3737
[tool.poetry.group.dev.dependencies]
38-
mypy = "1.9.0"
39-
pandas = "2.2.1"
38+
mypy = "1.10.0"
39+
pandas = "2.2.2"
4040
pyarrow = ">=10.0.1"
4141
pytest = ">=7.1.2"
42-
pyright = ">=1.1.354"
42+
pyright = ">=1.1.362"
4343
poethepoet = ">=0.16.5"
4444
loguru = ">=0.6.0"
4545
typing-extensions = ">=4.4.0"

tests/test_frame.py

+49-33
Original file line numberDiff line numberDiff line change
@@ -1953,44 +1953,60 @@ class ReadCsvKwargs(TypedDict):
19531953
),
19541954
pd.DataFrame,
19551955
)
1956-
parse_dates_2 = {"combined_date": ["Year", "Month", "Day"]}
1957-
with pytest_warns_bounded(
1958-
FutureWarning, "Support for nested sequences", lower="2.1.99"
1959-
):
1960-
check(
1961-
assert_type(pd.read_csv(path, parse_dates=parse_dates_2), pd.DataFrame),
1962-
pd.DataFrame,
1963-
)
1964-
parse_dates_3 = {"combined_date": [1, 2, 3]}
1965-
with pytest_warns_bounded(
1966-
FutureWarning, "Support for nested sequences", lower="2.1.99"
1967-
):
1968-
check(
1969-
assert_type(pd.read_csv(path, parse_dates=parse_dates_3), pd.DataFrame),
1970-
pd.DataFrame,
1971-
)
1972-
# MyPy calls this Dict[str, object] by default which necessitates the explicit annotation (Pyright does not)
1973-
parse_dates_4: dict[str, list[str | int]] = {"combined_date": [1, "Month", 3]}
1974-
with pytest_warns_bounded(
1975-
FutureWarning, "Support for nested sequences", lower="2.1.99"
1976-
):
1977-
check(
1978-
assert_type(pd.read_csv(path, parse_dates=parse_dates_4), pd.DataFrame),
1979-
pd.DataFrame,
1980-
)
1956+
if PD_LTE_22:
1957+
parse_dates_2 = {"combined_date": ["Year", "Month", "Day"]}
1958+
with pytest_warns_bounded(
1959+
FutureWarning,
1960+
"Support for nested sequences",
1961+
lower="2.1.99",
1962+
):
1963+
check(
1964+
assert_type(
1965+
pd.read_csv(path, parse_dates=parse_dates_2), pd.DataFrame
1966+
),
1967+
pd.DataFrame,
1968+
)
1969+
parse_dates_3 = {"combined_date": [1, 2, 3]}
1970+
with pytest_warns_bounded(
1971+
FutureWarning, "Support for nested sequences", lower="2.1.99"
1972+
):
1973+
check(
1974+
assert_type(
1975+
pd.read_csv(path, parse_dates=parse_dates_3), pd.DataFrame
1976+
),
1977+
pd.DataFrame,
1978+
)
1979+
# MyPy calls this Dict[str, object] by default which necessitates the explicit annotation (Pyright does not)
1980+
parse_dates_4: dict[str, list[str | int]] = {
1981+
"combined_date": [1, "Month", 3]
1982+
}
1983+
with pytest_warns_bounded(
1984+
FutureWarning, "Support for nested sequences", lower="2.1.99"
1985+
):
1986+
check(
1987+
assert_type(
1988+
pd.read_csv(path, parse_dates=parse_dates_4), pd.DataFrame
1989+
),
1990+
pd.DataFrame,
1991+
)
1992+
1993+
parse_dates_6 = [[1, 2, 3]]
1994+
with pytest_warns_bounded(
1995+
FutureWarning,
1996+
"Support for nested sequences",
1997+
lower="2.1.99",
1998+
):
1999+
check(
2000+
assert_type(
2001+
pd.read_csv(path, parse_dates=parse_dates_6), pd.DataFrame
2002+
),
2003+
pd.DataFrame,
2004+
)
19812005
parse_dates_5 = [0]
19822006
check(
19832007
assert_type(pd.read_csv(path, parse_dates=parse_dates_5), pd.DataFrame),
19842008
pd.DataFrame,
19852009
)
1986-
parse_dates_6 = [[1, 2, 3]]
1987-
with pytest_warns_bounded(
1988-
FutureWarning, "Support for nested sequences", lower="2.1.99"
1989-
):
1990-
check(
1991-
assert_type(pd.read_csv(path, parse_dates=parse_dates_6), pd.DataFrame),
1992-
pd.DataFrame,
1993-
)
19942010

19952011

19962012
def test_groupby_series_methods() -> None:

tests/test_groupby.py

+134-82
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,44 @@ def df2scalar(val: DataFrame) -> float:
246246
)
247247

248248
# interpolate
249-
check(assert_type(GB_DF.resample("ME").interpolate(), DataFrame), DataFrame)
250-
check(
251-
assert_type(GB_DF.resample("ME").interpolate(method="linear"), DataFrame),
252-
DataFrame,
253-
)
254-
check(
255-
assert_type(GB_DF.resample("ME").interpolate(inplace=True), None),
256-
type(None),
257-
)
249+
if PD_LTE_22:
250+
check(assert_type(GB_DF.resample("ME").interpolate(), DataFrame), DataFrame)
251+
check(
252+
assert_type(
253+
GB_DF.resample("ME").interpolate(method="linear"), DataFrame
254+
),
255+
DataFrame,
256+
)
257+
check(
258+
assert_type(GB_DF.resample("ME").interpolate(inplace=True), None),
259+
type(None),
260+
)
261+
else:
262+
263+
def resample_interpolate(x: DataFrame) -> DataFrame:
264+
return x.resample("ME").interpolate()
265+
266+
check(
267+
assert_type(
268+
GB_DF.apply(resample_interpolate, include_groups=False),
269+
DataFrame,
270+
),
271+
DataFrame,
272+
)
273+
274+
def resample_interpolate_linear(x: DataFrame) -> DataFrame:
275+
return x.resample("ME").interpolate(method="linear")
276+
277+
check(
278+
assert_type(
279+
GB_DF.apply(
280+
resample_interpolate_linear,
281+
include_groups=False,
282+
),
283+
DataFrame,
284+
),
285+
DataFrame,
286+
)
258287

259288
# pipe
260289
def g(val: Resampler[DataFrame]) -> DataFrame:
@@ -393,10 +422,31 @@ def f(val: Series) -> float:
393422
check(assert_type(GB_S.resample("ME").asfreq(-1.0), "Series[float]"), Series, float)
394423

395424
# interpolate
396-
check(
397-
assert_type(GB_S.resample("ME").interpolate(), "Series[float]"), Series, float
398-
)
399-
check(assert_type(GB_S.resample("ME").interpolate(inplace=True), None), type(None))
425+
if PD_LTE_22:
426+
check(
427+
assert_type(GB_S.resample("ME").interpolate(), "Series[float]"),
428+
Series,
429+
float,
430+
)
431+
check(
432+
assert_type(GB_S.resample("ME").interpolate(inplace=True), None), type(None)
433+
)
434+
else:
435+
check(
436+
assert_type(
437+
GB_S.apply(lambda x: x.resample("ME").interpolate()), "Series[float]"
438+
),
439+
Series,
440+
float,
441+
)
442+
# This fails typing checks, and should work in 3.0, but is a bug in main
443+
# https://github.com/pandas-dev/pandas/issues/58690
444+
# check(
445+
# assert_type(
446+
# GB_S.apply(lambda x: x.resample("ME").interpolate(inplace=True)), None
447+
# ),
448+
# type(None),
449+
# )
400450

401451
# pipe
402452
def g(val: Resampler[Series]) -> float:
@@ -854,62 +904,63 @@ def test_frame_groupby_ewm() -> None:
854904
check(assert_type(GB_DF.ewm(1).var(), DataFrame), DataFrame)
855905

856906
# aggregate
857-
with pytest_warns_bounded(
858-
FutureWarning,
859-
r"The provided callable <function (sum|mean) .*> is currently using ",
860-
upper="2.2.99",
861-
):
862-
check(assert_type(GB_DF.ewm(1).aggregate(np.sum), DataFrame), DataFrame)
863-
check(assert_type(GB_DF.ewm(1).agg(np.sum), DataFrame), DataFrame)
864-
check(
865-
assert_type(GB_DF.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
866-
DataFrame,
867-
)
868-
check(
869-
assert_type(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame),
870-
DataFrame,
871-
)
872-
check(
873-
assert_type(
874-
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": np.mean}),
907+
if PD_LTE_22:
908+
with pytest_warns_bounded(
909+
FutureWarning,
910+
r"The provided callable <function (sum|mean) .*> is currently using ",
911+
upper="2.2.99",
912+
):
913+
check(assert_type(GB_DF.ewm(1).aggregate(np.sum), DataFrame), DataFrame)
914+
check(assert_type(GB_DF.ewm(1).agg(np.sum), DataFrame), DataFrame)
915+
check(
916+
assert_type(GB_DF.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
875917
DataFrame,
876-
),
877-
DataFrame,
878-
)
879-
check(
880-
assert_type(
881-
GB_DF.ewm(1).aggregate({"col1": ["sum", np.mean], "col2": np.mean}),
918+
)
919+
check(
920+
assert_type(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame),
882921
DataFrame,
883-
),
884-
DataFrame,
885-
)
922+
)
923+
check(
924+
assert_type(
925+
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": np.mean}),
926+
DataFrame,
927+
),
928+
DataFrame,
929+
)
930+
check(
931+
assert_type(
932+
GB_DF.ewm(1).aggregate({"col1": ["sum", np.mean], "col2": np.mean}),
933+
DataFrame,
934+
),
935+
DataFrame,
936+
)
886937

887-
# aggregate combinations
888-
with pytest_warns_bounded(
889-
FutureWarning,
890-
r"The provided callable <function (sum|mean) .*> is currently using ",
891-
upper="2.2.99",
892-
):
893-
check(GB_DF.ewm(1).aggregate(np.sum), DataFrame)
894-
check(GB_DF.ewm(1).aggregate([np.mean]), DataFrame)
895-
check(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame)
896-
check(GB_DF.ewm(1).aggregate({"col1": np.sum}), DataFrame)
897-
check(
898-
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": np.mean}),
899-
DataFrame,
900-
)
901-
check(
902-
GB_DF.ewm(1).aggregate({"col1": [np.sum], "col2": ["sum", np.mean]}),
903-
DataFrame,
904-
)
905-
check(
906-
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": ["sum", np.mean]}),
907-
DataFrame,
908-
)
909-
check(
910-
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": [np.mean]}),
911-
DataFrame,
912-
)
938+
# aggregate combinations
939+
with pytest_warns_bounded(
940+
FutureWarning,
941+
r"The provided callable <function (sum|mean) .*> is currently using ",
942+
upper="2.2.99",
943+
):
944+
check(GB_DF.ewm(1).aggregate(np.sum), DataFrame)
945+
check(GB_DF.ewm(1).aggregate([np.mean]), DataFrame)
946+
check(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame)
947+
check(GB_DF.ewm(1).aggregate({"col1": np.sum}), DataFrame)
948+
check(
949+
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": np.mean}),
950+
DataFrame,
951+
)
952+
check(
953+
GB_DF.ewm(1).aggregate({"col1": [np.sum], "col2": ["sum", np.mean]}),
954+
DataFrame,
955+
)
956+
check(
957+
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": ["sum", np.mean]}),
958+
DataFrame,
959+
)
960+
check(
961+
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": [np.mean]}),
962+
DataFrame,
963+
)
913964
check(GB_DF.ewm(1).aggregate("sum"), DataFrame)
914965

915966
# getattr
@@ -964,22 +1015,23 @@ def test_series_groupby_ewm() -> None:
9641015
upper="2.2.99",
9651016
):
9661017
check(assert_type(GB_S.ewm(1).aggregate("sum"), Series), Series)
967-
check(assert_type(GB_S.ewm(1).aggregate(np.sum), Series), Series)
968-
check(assert_type(GB_S.ewm(1).agg(np.sum), Series), Series)
969-
check(
970-
assert_type(GB_S.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
971-
DataFrame,
972-
)
973-
check(
974-
assert_type(GB_S.ewm(1).aggregate(["sum", np.mean]), DataFrame),
975-
DataFrame,
976-
)
977-
check(
978-
assert_type(
979-
GB_S.ewm(1).aggregate({"col1": "sum", "col2": np.mean}), DataFrame
980-
),
981-
DataFrame,
982-
)
1018+
if PD_LTE_22:
1019+
check(assert_type(GB_S.ewm(1).aggregate(np.sum), Series), Series)
1020+
check(assert_type(GB_S.ewm(1).agg(np.sum), Series), Series)
1021+
check(
1022+
assert_type(GB_S.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
1023+
DataFrame,
1024+
)
1025+
check(
1026+
assert_type(GB_S.ewm(1).aggregate(["sum", np.mean]), DataFrame),
1027+
DataFrame,
1028+
)
1029+
check(
1030+
assert_type(
1031+
GB_S.ewm(1).aggregate({"col1": "sum", "col2": np.mean}), DataFrame
1032+
),
1033+
DataFrame,
1034+
)
9831035

9841036
# iter
9851037
iterator = iter(GB_S.ewm(1))

tests/test_resampler.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from typing_extensions import assert_type
2222

2323
from tests import (
24+
PD_LTE_22,
2425
TYPE_CHECKING_INVALID_USAGE,
2526
check,
2627
pytest_warns_bounded,
@@ -148,7 +149,11 @@ def test_interpolate() -> None:
148149

149150

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

153158

154159
def test_pipe() -> None:
@@ -360,7 +365,9 @@ def test_interpolate_series() -> None:
360365

361366

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

365372

366373
def test_pipe_series() -> None:

0 commit comments

Comments
 (0)