Skip to content

Commit fb338ff

Browse files
committed
Test series pipe typing
1 parent 3b1d0fb commit fb338ff

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

tests/test_series.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,3 +2847,116 @@ 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+
# FIXME: Remove ignore when pyright releases fix:
2869+
# https://github.com/microsoft/pyright/pull/6797
2870+
ser.pipe( # pyright: ignore[reportGeneralTypeIssues]
2871+
first_arg_series,
2872+
1,
2873+
[1.0, 2.0],
2874+
argument_2="hi",
2875+
keyword_only=(1, 2),
2876+
),
2877+
pd.Series,
2878+
),
2879+
pd.Series,
2880+
)
2881+
2882+
if TYPE_CHECKING_INVALID_USAGE:
2883+
ser.pipe(
2884+
first_arg_series,
2885+
"a", # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
2886+
[1.0, 2.0],
2887+
argument_2="hi",
2888+
keyword_only=(1, 2),
2889+
)
2890+
ser.pipe(
2891+
first_arg_series,
2892+
1,
2893+
[1.0, "b"], # type: ignore[list-item] # pyright: ignore[reportGeneralTypeIssues]
2894+
argument_2="hi",
2895+
keyword_only=(1, 2),
2896+
)
2897+
ser.pipe(
2898+
first_arg_series,
2899+
1,
2900+
[1.0, 2.0],
2901+
argument_2=11, # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
2902+
keyword_only=(1, 2),
2903+
)
2904+
ser.pipe(
2905+
first_arg_series,
2906+
1,
2907+
[1.0, 2.0],
2908+
argument_2="hi",
2909+
keyword_only=(1,), # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
2910+
)
2911+
ser.pipe( # type: ignore[call-arg]
2912+
first_arg_series,
2913+
1,
2914+
[1.0, 2.0],
2915+
argument_3="hi", # pyright: ignore[reportGeneralTypeIssues]
2916+
keyword_only=(1, 2),
2917+
)
2918+
ser.pipe( # type: ignore[misc]
2919+
first_arg_series,
2920+
1,
2921+
[1.0, 2.0],
2922+
11, # type: ignore[arg-type]
2923+
(1, 2), # pyright: ignore[reportGeneralTypeIssues]
2924+
)
2925+
ser.pipe( # type: ignore[call-arg]
2926+
first_arg_series,
2927+
positional_only=1, # pyright: ignore[reportGeneralTypeIssues]
2928+
argument_1=[1.0, 2.0],
2929+
argument_2=11, # type: ignore[arg-type]
2930+
keyword_only=(1, 2),
2931+
)
2932+
2933+
def first_arg_not_series(argument_1: int, ser: pd.Series) -> pd.Series:
2934+
return ser
2935+
2936+
# pyright does not like that the paramspec is not specified
2937+
check(
2938+
assert_type(
2939+
ser.pipe(
2940+
(first_arg_not_series, "ser"),
2941+
1,
2942+
),
2943+
pd.Series,
2944+
),
2945+
pd.Series,
2946+
)
2947+
2948+
if TYPE_CHECKING_INVALID_USAGE:
2949+
ser.pipe(
2950+
(
2951+
first_arg_not_series, # type: ignore[arg-type]
2952+
1, # pyright: ignore[reportGeneralTypeIssues]
2953+
),
2954+
1,
2955+
)
2956+
ser.pipe(
2957+
(
2958+
1, # type: ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
2959+
"df",
2960+
),
2961+
1,
2962+
)

0 commit comments

Comments
 (0)