@@ -246,15 +246,44 @@ def df2scalar(val: DataFrame) -> float:
246
246
)
247
247
248
248
# 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
+ if PD_LTE_22 :
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
+ else :
262
+
263
+ def resample_interpolate (x : DataFrame ) -> DataFrame :
264
+ return x .resample ("ME" ).interpolate ()
265
+
266
+ check (
267
+ assert_type (
268
+ GB_DF .apply (resample_interpolate , include_groups = False ),
269
+ DataFrame ,
270
+ ),
271
+ DataFrame ,
272
+ )
273
+
274
+ def resample_interpolate_linear (x : DataFrame ) -> DataFrame :
275
+ return x .resample ("ME" ).interpolate (method = "linear" )
276
+
277
+ check (
278
+ assert_type (
279
+ GB_DF .apply (
280
+ resample_interpolate_linear ,
281
+ include_groups = False ,
282
+ ),
283
+ DataFrame ,
284
+ ),
285
+ DataFrame ,
286
+ )
258
287
259
288
# pipe
260
289
def g (val : Resampler [DataFrame ]) -> DataFrame :
@@ -393,10 +422,31 @@ def f(val: Series) -> float:
393
422
check (assert_type (GB_S .resample ("ME" ).asfreq (- 1.0 ), "Series[float]" ), Series , float )
394
423
395
424
# interpolate
396
- check (
397
- assert_type (GB_S .resample ("ME" ).interpolate (), "Series[float]" ), Series , float
398
- )
399
- check (assert_type (GB_S .resample ("ME" ).interpolate (inplace = True ), None ), type (None ))
425
+ if PD_LTE_22 :
426
+ check (
427
+ assert_type (GB_S .resample ("ME" ).interpolate (), "Series[float]" ),
428
+ Series ,
429
+ float ,
430
+ )
431
+ check (
432
+ assert_type (GB_S .resample ("ME" ).interpolate (inplace = True ), None ), type (None )
433
+ )
434
+ else :
435
+ check (
436
+ assert_type (
437
+ GB_S .apply (lambda x : x .resample ("ME" ).interpolate ()), "Series[float]"
438
+ ),
439
+ Series ,
440
+ float ,
441
+ )
442
+ # This fails typing checks, and should work in 3.0, but is a bug in main
443
+ # https://github.com/pandas-dev/pandas/issues/58690
444
+ # check(
445
+ # assert_type(
446
+ # GB_S.apply(lambda x: x.resample("ME").interpolate(inplace=True)), None
447
+ # ),
448
+ # type(None),
449
+ # )
400
450
401
451
# pipe
402
452
def g (val : Resampler [Series ]) -> float :
@@ -854,62 +904,63 @@ def test_frame_groupby_ewm() -> None:
854
904
check (assert_type (GB_DF .ewm (1 ).var (), DataFrame ), DataFrame )
855
905
856
906
# 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 }),
907
+ if PD_LTE_22 :
908
+ with pytest_warns_bounded (
909
+ FutureWarning ,
910
+ r"The provided callable <function (sum|mean) .*> is currently using " ,
911
+ upper = "2.2.99" ,
912
+ ):
913
+ check (assert_type (GB_DF .ewm (1 ).aggregate (np .sum ), DataFrame ), DataFrame )
914
+ check (assert_type (GB_DF .ewm (1 ).agg (np .sum ), DataFrame ), DataFrame )
915
+ check (
916
+ assert_type (GB_DF .ewm (1 ).aggregate ([np .sum , np .mean ]), DataFrame ),
875
917
DataFrame ,
876
- ),
877
- DataFrame ,
878
- )
879
- check (
880
- assert_type (
881
- GB_DF .ewm (1 ).aggregate ({"col1" : ["sum" , np .mean ], "col2" : np .mean }),
918
+ )
919
+ check (
920
+ assert_type (GB_DF .ewm (1 ).aggregate (["sum" , np .mean ]), DataFrame ),
882
921
DataFrame ,
883
- ),
884
- DataFrame ,
885
- )
922
+ )
923
+ check (
924
+ assert_type (
925
+ GB_DF .ewm (1 ).aggregate ({"col1" : "sum" , "col2" : np .mean }),
926
+ DataFrame ,
927
+ ),
928
+ DataFrame ,
929
+ )
930
+ check (
931
+ assert_type (
932
+ GB_DF .ewm (1 ).aggregate ({"col1" : ["sum" , np .mean ], "col2" : np .mean }),
933
+ DataFrame ,
934
+ ),
935
+ DataFrame ,
936
+ )
886
937
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
- )
938
+ # aggregate combinations
939
+ with pytest_warns_bounded (
940
+ FutureWarning ,
941
+ r"The provided callable <function (sum|mean) .*> is currently using " ,
942
+ upper = "2.2.99" ,
943
+ ):
944
+ check (GB_DF .ewm (1 ).aggregate (np .sum ), DataFrame )
945
+ check (GB_DF .ewm (1 ).aggregate ([np .mean ]), DataFrame )
946
+ check (GB_DF .ewm (1 ).aggregate (["sum" , np .mean ]), DataFrame )
947
+ check (GB_DF .ewm (1 ).aggregate ({"col1" : np .sum }), DataFrame )
948
+ check (
949
+ GB_DF .ewm (1 ).aggregate ({"col1" : np .sum , "col2" : np .mean }),
950
+ DataFrame ,
951
+ )
952
+ check (
953
+ GB_DF .ewm (1 ).aggregate ({"col1" : [np .sum ], "col2" : ["sum" , np .mean ]}),
954
+ DataFrame ,
955
+ )
956
+ check (
957
+ GB_DF .ewm (1 ).aggregate ({"col1" : np .sum , "col2" : ["sum" , np .mean ]}),
958
+ DataFrame ,
959
+ )
960
+ check (
961
+ GB_DF .ewm (1 ).aggregate ({"col1" : "sum" , "col2" : [np .mean ]}),
962
+ DataFrame ,
963
+ )
913
964
check (GB_DF .ewm (1 ).aggregate ("sum" ), DataFrame )
914
965
915
966
# getattr
@@ -964,22 +1015,23 @@ def test_series_groupby_ewm() -> None:
964
1015
upper = "2.2.99" ,
965
1016
):
966
1017
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
- )
1018
+ if PD_LTE_22 :
1019
+ check (assert_type (GB_S .ewm (1 ).aggregate (np .sum ), Series ), Series )
1020
+ check (assert_type (GB_S .ewm (1 ).agg (np .sum ), Series ), Series )
1021
+ check (
1022
+ assert_type (GB_S .ewm (1 ).aggregate ([np .sum , np .mean ]), DataFrame ),
1023
+ DataFrame ,
1024
+ )
1025
+ check (
1026
+ assert_type (GB_S .ewm (1 ).aggregate (["sum" , np .mean ]), DataFrame ),
1027
+ DataFrame ,
1028
+ )
1029
+ check (
1030
+ assert_type (
1031
+ GB_S .ewm (1 ).aggregate ({"col1" : "sum" , "col2" : np .mean }), DataFrame
1032
+ ),
1033
+ DataFrame ,
1034
+ )
983
1035
984
1036
# iter
985
1037
iterator = iter (GB_S .ewm (1 ))
0 commit comments