Skip to content

Commit 8d89a72

Browse files
committed
fix a few more nightly tests
1 parent 82be814 commit 8d89a72

File tree

2 files changed

+88
-41
lines changed

2 files changed

+88
-41
lines changed

tests/test_frame.py

Lines changed: 49 additions & 33 deletions
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

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,25 @@ def df2scalar(val: DataFrame) -> float:
264264
raise RuntimeError("Should not happen")
265265

266266
if not PD_LTE_22:
267+
268+
def resample_interpolate(x: DataFrame) -> DataFrame:
269+
return x.resample("ME").interpolate()
270+
267271
check(
268272
assert_type(
269-
GB_DF.apply(
270-
lambda x: x.resample("ME").interpolate(), include_groups=False
271-
),
273+
GB_DF.apply(resample_interpolate, include_groups=False),
272274
DataFrame,
273275
),
274276
DataFrame,
275277
)
278+
279+
def resample_interpolate_linear(x: DataFrame) -> DataFrame:
280+
return x.resample("ME").interpolate(method="linear")
281+
276282
check(
277283
assert_type(
278284
GB_DF.apply(
279-
lambda x: x.resample("ME").interpolate(method="linear"),
285+
resample_interpolate_linear,
280286
include_groups=False,
281287
),
282288
DataFrame,
@@ -421,10 +427,35 @@ def f(val: Series) -> float:
421427
check(assert_type(GB_S.resample("ME").asfreq(-1.0), "Series[float]"), Series, float)
422428

423429
# interpolate
424-
check(
425-
assert_type(GB_S.resample("ME").interpolate(), "Series[float]"), Series, float
426-
)
427-
check(assert_type(GB_S.resample("ME").interpolate(inplace=True), None), type(None))
430+
try:
431+
check(
432+
assert_type(GB_S.resample("ME").interpolate(), "Series[float]"),
433+
Series,
434+
float,
435+
)
436+
check(
437+
assert_type(GB_S.resample("ME").interpolate(inplace=True), None), type(None)
438+
)
439+
except NotImplementedError:
440+
if PD_LTE_22:
441+
raise RuntimeError("should not happen")
442+
443+
if not PD_LTE_22:
444+
check(
445+
assert_type(
446+
GB_S.apply(lambda x: x.resample("ME").interpolate()), "Series[float]"
447+
),
448+
Series,
449+
float,
450+
)
451+
# This fails typing checks, and should work in 3.0, but is a bug in main
452+
# https://github.com/pandas-dev/pandas/issues/58690
453+
# check(
454+
# assert_type(
455+
# GB_S.apply(lambda x: x.resample("ME").interpolate(inplace=True)), None
456+
# ),
457+
# type(None),
458+
# )
428459

429460
# pipe
430461
def g(val: Resampler[Series]) -> float:

0 commit comments

Comments
 (0)