10
10
final ,
11
11
no_type_check ,
12
12
)
13
+ import warnings
13
14
14
15
import numpy as np
15
16
37
38
TimestampConvertibleTypes ,
38
39
npt ,
39
40
)
41
+ from pandas .compat .numpy import function as nv
40
42
from pandas .errors import (
41
43
AbstractMethodError ,
42
44
DataError ,
46
48
Substitution ,
47
49
doc ,
48
50
)
51
+ from pandas .util ._exceptions import find_stack_level
49
52
50
53
from pandas .core .dtypes .generic import (
51
54
ABCDataFrame ,
@@ -898,54 +901,82 @@ def sum(
898
901
self ,
899
902
numeric_only : bool = False ,
900
903
min_count : int = 0 ,
904
+ * args ,
905
+ ** kwargs ,
901
906
):
907
+ maybe_warn_args_and_kwargs (type (self ), "sum" , args , kwargs )
908
+ nv .validate_resampler_func ("sum" , args , kwargs )
902
909
return self ._downsample ("sum" , numeric_only = numeric_only , min_count = min_count )
903
910
904
911
@doc (GroupBy .prod )
905
912
def prod (
906
913
self ,
907
914
numeric_only : bool = False ,
908
915
min_count : int = 0 ,
916
+ * args ,
917
+ ** kwargs ,
909
918
):
919
+ maybe_warn_args_and_kwargs (type (self ), "prod" , args , kwargs )
920
+ nv .validate_resampler_func ("prod" , args , kwargs )
910
921
return self ._downsample ("prod" , numeric_only = numeric_only , min_count = min_count )
911
922
912
923
def min (
913
924
self ,
914
925
numeric_only : bool = False ,
915
926
min_count : int = 0 ,
927
+ * args ,
928
+ ** kwargs ,
916
929
):
930
+ maybe_warn_args_and_kwargs (type (self ), "min" , args , kwargs )
931
+ nv .validate_resampler_func ("min" , args , kwargs )
917
932
return self ._downsample ("min" , numeric_only = numeric_only , min_count = min_count )
918
933
919
934
def max (
920
935
self ,
921
936
numeric_only : bool = False ,
922
937
min_count : int = 0 ,
938
+ * args ,
939
+ ** kwargs ,
923
940
):
941
+ maybe_warn_args_and_kwargs (type (self ), "max" , args , kwargs )
942
+ nv .validate_resampler_func ("max" , args , kwargs )
924
943
return self ._downsample ("max" , numeric_only = numeric_only , min_count = min_count )
925
944
926
945
@doc (GroupBy .first )
927
946
def first (
928
947
self ,
929
948
numeric_only : bool = False ,
930
949
min_count : int = 0 ,
950
+ * args ,
951
+ ** kwargs ,
931
952
):
953
+ maybe_warn_args_and_kwargs (type (self ), "first" , args , kwargs )
954
+ nv .validate_resampler_func ("first" , args , kwargs )
932
955
return self ._downsample ("first" , numeric_only = numeric_only , min_count = min_count )
933
956
934
957
@doc (GroupBy .last )
935
958
def last (
936
959
self ,
937
960
numeric_only : bool = False ,
938
961
min_count : int = 0 ,
962
+ * args ,
963
+ ** kwargs ,
939
964
):
965
+ maybe_warn_args_and_kwargs (type (self ), "last" , args , kwargs )
966
+ nv .validate_resampler_func ("last" , args , kwargs )
940
967
return self ._downsample ("last" , numeric_only = numeric_only , min_count = min_count )
941
968
942
969
@doc (GroupBy .median )
943
- def median (self , numeric_only : bool = False ):
970
+ def median (self , numeric_only : bool = False , * args , ** kwargs ):
971
+ maybe_warn_args_and_kwargs (type (self ), "median" , args , kwargs )
972
+ nv .validate_resampler_func ("median" , args , kwargs )
944
973
return self ._downsample ("median" , numeric_only = numeric_only )
945
974
946
975
def mean (
947
976
self ,
948
977
numeric_only : bool = False ,
978
+ * args ,
979
+ ** kwargs ,
949
980
):
950
981
"""
951
982
Compute mean of groups, excluding missing values.
@@ -964,12 +995,16 @@ def mean(
964
995
DataFrame or Series
965
996
Mean of values within each group.
966
997
"""
998
+ maybe_warn_args_and_kwargs (type (self ), "mean" , args , kwargs )
999
+ nv .validate_resampler_func ("mean" , args , kwargs )
967
1000
return self ._downsample ("mean" , numeric_only = numeric_only )
968
1001
969
1002
def std (
970
1003
self ,
971
1004
ddof : int = 1 ,
972
1005
numeric_only : bool = False ,
1006
+ * args ,
1007
+ ** kwargs ,
973
1008
):
974
1009
"""
975
1010
Compute standard deviation of groups, excluding missing values.
@@ -992,12 +1027,16 @@ def std(
992
1027
DataFrame or Series
993
1028
Standard deviation of values within each group.
994
1029
"""
1030
+ maybe_warn_args_and_kwargs (type (self ), "std" , args , kwargs )
1031
+ nv .validate_resampler_func ("std" , args , kwargs )
995
1032
return self ._downsample ("std" , ddof = ddof , numeric_only = numeric_only )
996
1033
997
1034
def var (
998
1035
self ,
999
1036
ddof : int = 1 ,
1000
1037
numeric_only : bool = False ,
1038
+ * args ,
1039
+ ** kwargs ,
1001
1040
):
1002
1041
"""
1003
1042
Compute variance of groups, excluding missing values.
@@ -1021,26 +1060,40 @@ def var(
1021
1060
DataFrame or Series
1022
1061
Variance of values within each group.
1023
1062
"""
1063
+ maybe_warn_args_and_kwargs (type (self ), "var" , args , kwargs )
1064
+ nv .validate_resampler_func ("var" , args , kwargs )
1024
1065
return self ._downsample ("var" , ddof = ddof , numeric_only = numeric_only )
1025
1066
1026
1067
@doc (GroupBy .sem )
1027
1068
def sem (
1028
1069
self ,
1029
1070
ddof : int = 1 ,
1030
1071
numeric_only : bool = False ,
1072
+ * args ,
1073
+ ** kwargs ,
1031
1074
):
1075
+ maybe_warn_args_and_kwargs (type (self ), "sem" , args , kwargs )
1076
+ nv .validate_resampler_func ("sem" , args , kwargs )
1032
1077
return self ._downsample ("sem" , ddof = ddof , numeric_only = numeric_only )
1033
1078
1034
1079
@doc (GroupBy .ohlc )
1035
1080
def ohlc (
1036
1081
self ,
1082
+ * args ,
1083
+ ** kwargs ,
1037
1084
):
1085
+ maybe_warn_args_and_kwargs (type (self ), "ohlc" , args , kwargs )
1086
+ nv .validate_resampler_func ("ohlc" , args , kwargs )
1038
1087
return self ._downsample ("ohlc" )
1039
1088
1040
1089
@doc (SeriesGroupBy .nunique )
1041
1090
def nunique (
1042
1091
self ,
1092
+ * args ,
1093
+ ** kwargs ,
1043
1094
):
1095
+ maybe_warn_args_and_kwargs (type (self ), "nunique" , args , kwargs )
1096
+ nv .validate_resampler_func ("nunique" , args , kwargs )
1044
1097
return self ._downsample ("nunique" )
1045
1098
1046
1099
@doc (GroupBy .size )
@@ -2193,3 +2246,38 @@ def _asfreq_compat(index: DatetimeIndex | PeriodIndex | TimedeltaIndex, freq):
2193
2246
else : # pragma: no cover
2194
2247
raise TypeError (type (index ))
2195
2248
return new_index
2249
+
2250
+
2251
+ def maybe_warn_args_and_kwargs (cls , kernel : str , args , kwargs ) -> None :
2252
+ """
2253
+ Warn for deprecation of args and kwargs in resample functions.
2254
+
2255
+ Parameters
2256
+ ----------
2257
+ cls : type
2258
+ Class to warn about.
2259
+ kernel : str
2260
+ Operation name.
2261
+ args : tuple or None
2262
+ args passed by user. Will be None if and only if kernel does not have args.
2263
+ kwargs : dict or None
2264
+ kwargs passed by user. Will be None if and only if kernel does not have kwargs.
2265
+ """
2266
+ warn_args = args is not None and len (args ) > 0
2267
+ warn_kwargs = kwargs is not None and len (kwargs ) > 0
2268
+ if warn_args and warn_kwargs :
2269
+ msg = "args and kwargs"
2270
+ elif warn_args :
2271
+ msg = "args"
2272
+ elif warn_kwargs :
2273
+ msg = "kwargs"
2274
+ else :
2275
+ msg = ""
2276
+ if msg != "" :
2277
+ warnings .warn (
2278
+ f"Passing additional { msg } to { cls .__name__ } .{ kernel } has "
2279
+ "no impact on the result and is deprecated. This will "
2280
+ "raise a TypeError in a future version of pandas." ,
2281
+ category = FutureWarning ,
2282
+ stacklevel = find_stack_level (),
2283
+ )
0 commit comments