Skip to content

Commit 82be814

Browse files
committed
fix nightly tests
1 parent 9455de9 commit 82be814

File tree

5 files changed

+219
-168
lines changed

5 files changed

+219
-168
lines changed

tests/test_groupby.py

Lines changed: 108 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,43 @@ 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+
try:
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+
except NotImplementedError:
262+
# In version 3.0, this is not allowed
263+
if PD_LTE_22:
264+
raise RuntimeError("Should not happen")
265+
266+
if not PD_LTE_22:
267+
check(
268+
assert_type(
269+
GB_DF.apply(
270+
lambda x: x.resample("ME").interpolate(), include_groups=False
271+
),
272+
DataFrame,
273+
),
274+
DataFrame,
275+
)
276+
check(
277+
assert_type(
278+
GB_DF.apply(
279+
lambda x: x.resample("ME").interpolate(method="linear"),
280+
include_groups=False,
281+
),
282+
DataFrame,
283+
),
284+
DataFrame,
285+
)
258286

259287
# pipe
260288
def g(val: Resampler[DataFrame]) -> DataFrame:
@@ -854,62 +882,63 @@ def test_frame_groupby_ewm() -> None:
854882
check(assert_type(GB_DF.ewm(1).var(), DataFrame), DataFrame)
855883

856884
# 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}),
885+
if PD_LTE_22:
886+
with pytest_warns_bounded(
887+
FutureWarning,
888+
r"The provided callable <function (sum|mean) .*> is currently using ",
889+
upper="2.2.99",
890+
):
891+
check(assert_type(GB_DF.ewm(1).aggregate(np.sum), DataFrame), DataFrame)
892+
check(assert_type(GB_DF.ewm(1).agg(np.sum), DataFrame), DataFrame)
893+
check(
894+
assert_type(GB_DF.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
875895
DataFrame,
876-
),
877-
DataFrame,
878-
)
879-
check(
880-
assert_type(
881-
GB_DF.ewm(1).aggregate({"col1": ["sum", np.mean], "col2": np.mean}),
896+
)
897+
check(
898+
assert_type(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame),
882899
DataFrame,
883-
),
884-
DataFrame,
885-
)
900+
)
901+
check(
902+
assert_type(
903+
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": np.mean}),
904+
DataFrame,
905+
),
906+
DataFrame,
907+
)
908+
check(
909+
assert_type(
910+
GB_DF.ewm(1).aggregate({"col1": ["sum", np.mean], "col2": np.mean}),
911+
DataFrame,
912+
),
913+
DataFrame,
914+
)
886915

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-
)
916+
# aggregate combinations
917+
with pytest_warns_bounded(
918+
FutureWarning,
919+
r"The provided callable <function (sum|mean) .*> is currently using ",
920+
upper="2.2.99",
921+
):
922+
check(GB_DF.ewm(1).aggregate(np.sum), DataFrame)
923+
check(GB_DF.ewm(1).aggregate([np.mean]), DataFrame)
924+
check(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame)
925+
check(GB_DF.ewm(1).aggregate({"col1": np.sum}), DataFrame)
926+
check(
927+
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": np.mean}),
928+
DataFrame,
929+
)
930+
check(
931+
GB_DF.ewm(1).aggregate({"col1": [np.sum], "col2": ["sum", np.mean]}),
932+
DataFrame,
933+
)
934+
check(
935+
GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": ["sum", np.mean]}),
936+
DataFrame,
937+
)
938+
check(
939+
GB_DF.ewm(1).aggregate({"col1": "sum", "col2": [np.mean]}),
940+
DataFrame,
941+
)
913942
check(GB_DF.ewm(1).aggregate("sum"), DataFrame)
914943

915944
# getattr
@@ -964,22 +993,23 @@ def test_series_groupby_ewm() -> None:
964993
upper="2.2.99",
965994
):
966995
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-
)
996+
if PD_LTE_22:
997+
check(assert_type(GB_S.ewm(1).aggregate(np.sum), Series), Series)
998+
check(assert_type(GB_S.ewm(1).agg(np.sum), Series), Series)
999+
check(
1000+
assert_type(GB_S.ewm(1).aggregate([np.sum, np.mean]), DataFrame),
1001+
DataFrame,
1002+
)
1003+
check(
1004+
assert_type(GB_S.ewm(1).aggregate(["sum", np.mean]), DataFrame),
1005+
DataFrame,
1006+
)
1007+
check(
1008+
assert_type(
1009+
GB_S.ewm(1).aggregate({"col1": "sum", "col2": np.mean}), DataFrame
1010+
),
1011+
DataFrame,
1012+
)
9831013

9841014
# iter
9851015
iterator = iter(GB_S.ewm(1))

tests/test_resampler.py

Lines changed: 9 additions & 2 deletions
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:

tests/test_series.py

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ def test_types_copy() -> None:
145145

146146
def test_types_select() -> None:
147147
s = pd.Series(data={"row1": 1, "row2": 2})
148-
with pytest_warns_bounded(
149-
FutureWarning,
150-
"Series.__getitem__ treating keys as positions is deprecated",
151-
lower="2.0.99",
152-
):
153-
s[0]
154-
s[1:]
148+
if PD_LTE_22:
149+
# Not valid in 3.0
150+
with pytest_warns_bounded(
151+
FutureWarning,
152+
"Series.__getitem__ treating keys as positions is deprecated",
153+
lower="2.0.99",
154+
):
155+
s[0]
156+
s[1:]
155157

156158

157159
def test_types_iloc_iat() -> None:
@@ -1710,20 +1712,21 @@ def test_bitwise_operators() -> None:
17101712
check(assert_type(s ^ s2, "pd.Series[int]"), pd.Series, np.integer)
17111713
check(assert_type(s2 ^ s, "pd.Series[int]"), pd.Series, np.integer)
17121714

1713-
with pytest_warns_bounded(
1714-
FutureWarning,
1715-
r"Logical ops \(and, or, xor\) between Pandas objects and dtype-less sequences "
1716-
r"\(e.g. list, tuple\) are deprecated",
1717-
lower="2.0.99",
1718-
):
1719-
check(assert_type(s & [1, 2, 3, 4], "pd.Series[bool]"), pd.Series, np.bool_)
1720-
check(assert_type([1, 2, 3, 4] & s, "pd.Series[bool]"), pd.Series, np.bool_)
1715+
if PD_LTE_22:
1716+
with pytest_warns_bounded(
1717+
FutureWarning,
1718+
r"Logical ops \(and, or, xor\) between Pandas objects and dtype-less sequences "
1719+
r"\(e.g. list, tuple\) are deprecated",
1720+
lower="2.0.99",
1721+
):
1722+
check(assert_type(s & [1, 2, 3, 4], "pd.Series[bool]"), pd.Series, np.bool_)
1723+
check(assert_type([1, 2, 3, 4] & s, "pd.Series[bool]"), pd.Series, np.bool_)
17211724

1722-
check(assert_type(s | [1, 2, 3, 4], "pd.Series[bool]"), pd.Series, np.bool_)
1723-
check(assert_type([1, 2, 3, 4] | s, "pd.Series[bool]"), pd.Series, np.bool_)
1725+
check(assert_type(s | [1, 2, 3, 4], "pd.Series[bool]"), pd.Series, np.bool_)
1726+
check(assert_type([1, 2, 3, 4] | s, "pd.Series[bool]"), pd.Series, np.bool_)
17241727

1725-
check(assert_type(s ^ [1, 2, 3, 4], "pd.Series[bool]"), pd.Series, np.bool_)
1726-
check(assert_type([1, 2, 3, 4] ^ s, "pd.Series[bool]"), pd.Series, np.bool_)
1728+
check(assert_type(s ^ [1, 2, 3, 4], "pd.Series[bool]"), pd.Series, np.bool_)
1729+
check(assert_type([1, 2, 3, 4] ^ s, "pd.Series[bool]"), pd.Series, np.bool_)
17271730

17281731

17291732
def test_logical_operators() -> None:
@@ -1757,42 +1760,43 @@ def test_logical_operators() -> None:
17571760

17581761
check(assert_type(True ^ (df["a"] >= 2), "pd.Series[bool]"), pd.Series, np.bool_)
17591762

1760-
with pytest_warns_bounded(
1761-
FutureWarning,
1762-
r"Logical ops \(and, or, xor\) between Pandas objects and dtype-less sequences "
1763-
r"\(e.g. list, tuple\) are deprecated",
1764-
lower="2.0.99",
1765-
):
1766-
check(
1767-
assert_type((df["a"] >= 2) ^ [True, False, True], "pd.Series[bool]"),
1768-
pd.Series,
1769-
np.bool_,
1770-
)
1771-
check(
1772-
assert_type((df["a"] >= 2) & [True, False, True], "pd.Series[bool]"),
1773-
pd.Series,
1774-
np.bool_,
1775-
)
1776-
check(
1777-
assert_type((df["a"] >= 2) | [True, False, True], "pd.Series[bool]"),
1778-
pd.Series,
1779-
np.bool_,
1780-
)
1781-
check(
1782-
assert_type([True, False, True] & (df["a"] >= 2), "pd.Series[bool]"),
1783-
pd.Series,
1784-
np.bool_,
1785-
)
1786-
check(
1787-
assert_type([True, False, True] | (df["a"] >= 2), "pd.Series[bool]"),
1788-
pd.Series,
1789-
np.bool_,
1790-
)
1791-
check(
1792-
assert_type([True, False, True] ^ (df["a"] >= 2), "pd.Series[bool]"),
1793-
pd.Series,
1794-
np.bool_,
1795-
)
1763+
if PD_LTE_22:
1764+
with pytest_warns_bounded(
1765+
FutureWarning,
1766+
r"Logical ops \(and, or, xor\) between Pandas objects and dtype-less sequences "
1767+
r"\(e.g. list, tuple\) are deprecated",
1768+
lower="2.0.99",
1769+
):
1770+
check(
1771+
assert_type((df["a"] >= 2) ^ [True, False, True], "pd.Series[bool]"),
1772+
pd.Series,
1773+
np.bool_,
1774+
)
1775+
check(
1776+
assert_type((df["a"] >= 2) & [True, False, True], "pd.Series[bool]"),
1777+
pd.Series,
1778+
np.bool_,
1779+
)
1780+
check(
1781+
assert_type((df["a"] >= 2) | [True, False, True], "pd.Series[bool]"),
1782+
pd.Series,
1783+
np.bool_,
1784+
)
1785+
check(
1786+
assert_type([True, False, True] & (df["a"] >= 2), "pd.Series[bool]"),
1787+
pd.Series,
1788+
np.bool_,
1789+
)
1790+
check(
1791+
assert_type([True, False, True] | (df["a"] >= 2), "pd.Series[bool]"),
1792+
pd.Series,
1793+
np.bool_,
1794+
)
1795+
check(
1796+
assert_type([True, False, True] ^ (df["a"] >= 2), "pd.Series[bool]"),
1797+
pd.Series,
1798+
np.bool_,
1799+
)
17961800

17971801

17981802
def test_AnyArrayLike_and_clip() -> None:

tests/test_timefuncs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,12 @@ def test_series_dt_accessors() -> None:
459459
check(assert_type(s2.dt.microseconds, "pd.Series[int]"), pd.Series, np.integer)
460460
check(assert_type(s2.dt.nanoseconds, "pd.Series[int]"), pd.Series, np.integer)
461461
check(assert_type(s2.dt.components, pd.DataFrame), pd.DataFrame)
462-
check(assert_type(s2.dt.to_pytimedelta(), np.ndarray), np.ndarray)
462+
with pytest_warns_bounded(
463+
FutureWarning,
464+
"The behavior of TimedeltaProperties.to_pytimedelta is deprecated",
465+
lower="2.2.99",
466+
):
467+
check(assert_type(s2.dt.to_pytimedelta(), np.ndarray), np.ndarray)
463468
check(assert_type(s2.dt.total_seconds(), "pd.Series[float]"), pd.Series, float)
464469
check(assert_type(s2.dt.unit, TimeUnit), str)
465470
check(assert_type(s2.dt.as_unit("s"), "TimedeltaSeries"), pd.Series, pd.Timedelta)

0 commit comments

Comments
 (0)