Skip to content

Commit 5ecb552

Browse files
committed
Test series pipe typing
1 parent 81a55f3 commit 5ecb552

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

tests/test_series.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,3 +2847,114 @@ def test_round() -> None:
28472847
def test_series_new_empty() -> None:
28482848
# GH 826
28492849
check(assert_type(pd.Series(), "pd.Series[Any]"), pd.Series)
2850+
2851+
2852+
def test_pipe() -> None:
2853+
ser = pd.Series(range(10))
2854+
2855+
def first_arg_series(
2856+
ser: pd.Series,
2857+
positional_only: int,
2858+
/,
2859+
argument_1: list[float],
2860+
argument_2: str,
2861+
*,
2862+
keyword_only: tuple[int, int],
2863+
) -> pd.Series:
2864+
return ser
2865+
2866+
check(
2867+
assert_type(
2868+
ser.pipe(
2869+
first_arg_series,
2870+
1,
2871+
[1.0, 2.0],
2872+
argument_2="hi",
2873+
keyword_only=(1, 2),
2874+
),
2875+
pd.Series,
2876+
),
2877+
pd.Series,
2878+
)
2879+
2880+
if TYPE_CHECKING_INVALID_USAGE:
2881+
ser.pipe(
2882+
first_arg_series, # type: ignore[arg-type]
2883+
"a", # pyright: ignore[reportGeneralTypeIssues]
2884+
[1.0, 2.0],
2885+
argument_2="hi",
2886+
keyword_only=(1, 2),
2887+
)
2888+
ser.pipe(
2889+
first_arg_series, # type: ignore[arg-type]
2890+
1,
2891+
[1.0, "b"], # pyright: ignore[reportGeneralTypeIssues]
2892+
argument_2="hi",
2893+
keyword_only=(1, 2),
2894+
)
2895+
ser.pipe(
2896+
first_arg_series, # type: ignore[arg-type]
2897+
1,
2898+
[1.0, 2.0],
2899+
argument_2=11, # pyright: ignore[reportGeneralTypeIssues]
2900+
keyword_only=(1, 2),
2901+
)
2902+
ser.pipe(
2903+
first_arg_series, # type: ignore[arg-type]
2904+
1,
2905+
[1.0, 2.0],
2906+
argument_2="hi",
2907+
keyword_only=(1,), # pyright: ignore[reportGeneralTypeIssues]
2908+
)
2909+
ser.pipe(
2910+
first_arg_series, # type: ignore[arg-type]
2911+
1,
2912+
[1.0, 2.0],
2913+
argument_3="hi", # pyright: ignore[reportGeneralTypeIssues]
2914+
keyword_only=(1, 2),
2915+
)
2916+
ser.pipe(
2917+
first_arg_series, # type: ignore[arg-type]
2918+
1,
2919+
[1.0, 2.0],
2920+
11,
2921+
(1, 2), # pyright: ignore[reportGeneralTypeIssues]
2922+
)
2923+
ser.pipe(
2924+
first_arg_series, # type: ignore[arg-type]
2925+
positional_only=1, # pyright: ignore[reportGeneralTypeIssues]
2926+
argument_1=[1.0, 2.0],
2927+
argument_2=11,
2928+
keyword_only=(1, 2),
2929+
)
2930+
2931+
def first_arg_not_series(argument_1: int, ser: pd.Series) -> pd.Series:
2932+
return ser
2933+
2934+
# pyright does not like that the paramspec is not specified
2935+
check(
2936+
assert_type(
2937+
ser.pipe(
2938+
(first_arg_not_series, "ser"),
2939+
1, # pyright: ignore[reportGeneralTypeIssues]
2940+
),
2941+
pd.Series,
2942+
),
2943+
pd.Series,
2944+
)
2945+
2946+
if TYPE_CHECKING_INVALID_USAGE:
2947+
ser.pipe(
2948+
(
2949+
first_arg_not_series, # type: ignore[arg-type]
2950+
1, # pyright: ignore[reportGeneralTypeIssues]
2951+
),
2952+
1, # pyright: ignore[reportGeneralTypeIssues]
2953+
)
2954+
ser.pipe(
2955+
(
2956+
1, # type: ignore[arg-type]
2957+
"df",
2958+
), # pyright: ignore[reportGeneralTypeIssues]
2959+
1, # pyright: ignore[reportGeneralTypeIssues]
2960+
)

0 commit comments

Comments
 (0)