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