Skip to content

Commit 545cbbf

Browse files
authored
CLN: Use kwargs instead of kwds in apply functions (#39625)
1 parent b15901e commit 545cbbf

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

pandas/core/apply.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def frame_apply(
6363
raw: bool = False,
6464
result_type: Optional[str] = None,
6565
args=None,
66-
kwds=None,
66+
kwargs=None,
6767
) -> FrameApply:
6868
""" construct and return a row or column based frame apply object """
6969
axis = obj._get_axis_number(axis)
@@ -79,7 +79,7 @@ def frame_apply(
7979
raw=raw,
8080
result_type=result_type,
8181
args=args,
82-
kwds=kwds,
82+
kwargs=kwargs,
8383
)
8484

8585

@@ -88,14 +88,14 @@ def series_apply(
8888
func: AggFuncType,
8989
convert_dtype: bool = True,
9090
args=None,
91-
kwds=None,
91+
kwargs=None,
9292
) -> SeriesApply:
9393
return SeriesApply(
9494
obj,
9595
func,
9696
convert_dtype,
9797
args,
98-
kwds,
98+
kwargs,
9999
)
100100

101101

@@ -109,12 +109,12 @@ def __init__(
109109
raw: bool,
110110
result_type: Optional[str],
111111
args,
112-
kwds,
112+
kwargs,
113113
):
114114
self.obj = obj
115115
self.raw = raw
116116
self.args = args or ()
117-
self.kwds = kwds or {}
117+
self.kwargs = kwargs or {}
118118

119119
if result_type not in [None, "reduce", "broadcast", "expand"]:
120120
raise ValueError(
@@ -126,13 +126,13 @@ def __init__(
126126

127127
# curry if needed
128128
if (
129-
(kwds or args)
129+
(kwargs or args)
130130
and not isinstance(func, (np.ufunc, str))
131131
and not is_list_like(func)
132132
):
133133

134134
def f(x):
135-
return func(x, *args, **kwds)
135+
return func(x, *args, **kwargs)
136136

137137
else:
138138
f = func
@@ -163,7 +163,7 @@ def agg(self) -> Tuple[Optional[FrameOrSeriesUnion], Optional[bool]]:
163163
obj = self.obj
164164
arg = self.f
165165
args = self.args
166-
kwargs = self.kwds
166+
kwargs = self.kwargs
167167

168168
_axis = kwargs.pop("_axis", None)
169169
if _axis is None:
@@ -413,10 +413,10 @@ def maybe_apply_str(self) -> Optional[FrameOrSeriesUnion]:
413413
if callable(func):
414414
sig = inspect.getfullargspec(func)
415415
if "axis" in sig.args:
416-
self.kwds["axis"] = self.axis
416+
self.kwargs["axis"] = self.axis
417417
elif self.axis != 0:
418418
raise ValueError(f"Operation {f} does not support axis=1")
419-
return self.obj._try_aggregate_string_function(f, *self.args, **self.kwds)
419+
return self.obj._try_aggregate_string_function(f, *self.args, **self.kwargs)
420420

421421
def maybe_apply_multiple(self) -> Optional[FrameOrSeriesUnion]:
422422
"""
@@ -430,7 +430,7 @@ def maybe_apply_multiple(self) -> Optional[FrameOrSeriesUnion]:
430430
# Note: dict-likes are list-like
431431
if not is_list_like(self.f):
432432
return None
433-
return self.obj.aggregate(self.f, self.axis, *self.args, **self.kwds)
433+
return self.obj.aggregate(self.f, self.axis, *self.args, **self.kwargs)
434434

435435

436436
class FrameApply(Apply):
@@ -806,7 +806,7 @@ def __init__(
806806
func: AggFuncType,
807807
convert_dtype: bool,
808808
args,
809-
kwds,
809+
kwargs,
810810
):
811811
self.convert_dtype = convert_dtype
812812

@@ -816,7 +816,7 @@ def __init__(
816816
raw=False,
817817
result_type=None,
818818
args=args,
819-
kwds=kwds,
819+
kwargs=kwargs,
820820
)
821821

822822
def apply(self) -> FrameOrSeriesUnion:
@@ -877,17 +877,17 @@ def __init__(
877877
obj: Union[SeriesGroupBy, DataFrameGroupBy],
878878
func: AggFuncType,
879879
args,
880-
kwds,
880+
kwargs,
881881
):
882-
kwds = kwds.copy()
883-
self.axis = obj.obj._get_axis_number(kwds.get("axis", 0))
882+
kwargs = kwargs.copy()
883+
self.axis = obj.obj._get_axis_number(kwargs.get("axis", 0))
884884
super().__init__(
885885
obj,
886886
func,
887887
raw=False,
888888
result_type=None,
889889
args=args,
890-
kwds=kwds,
890+
kwargs=kwargs,
891891
)
892892

893893
def apply(self):
@@ -903,15 +903,15 @@ def __init__(
903903
obj: Union[Resampler, BaseWindow],
904904
func: AggFuncType,
905905
args,
906-
kwds,
906+
kwargs,
907907
):
908908
super().__init__(
909909
obj,
910910
func,
911911
raw=False,
912912
result_type=None,
913913
args=args,
914-
kwds=kwds,
914+
kwargs=kwargs,
915915
)
916916

917917
def apply(self):

pandas/core/frame.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -7718,7 +7718,7 @@ def _aggregate(self, arg, axis: Axis = 0, *args, **kwargs):
77187718
func=arg,
77197719
axis=0,
77207720
args=args,
7721-
kwds=kwargs,
7721+
kwargs=kwargs,
77227722
)
77237723
result, how = op.agg()
77247724

@@ -7750,7 +7750,7 @@ def apply(
77507750
raw: bool = False,
77517751
result_type=None,
77527752
args=(),
7753-
**kwds,
7753+
**kwargs,
77547754
):
77557755
"""
77567756
Apply a function along an axis of the DataFrame.
@@ -7798,7 +7798,7 @@ def apply(
77987798
args : tuple
77997799
Positional arguments to pass to `func` in addition to the
78007800
array/series.
7801-
**kwds
7801+
**kwargs
78027802
Additional keyword arguments to pass as keywords arguments to
78037803
`func`.
78047804
@@ -7892,7 +7892,7 @@ def apply(
78927892
raw=raw,
78937893
result_type=result_type,
78947894
args=args,
7895-
kwds=kwds,
7895+
kwargs=kwargs,
78967896
)
78977897
return op.apply()
78987898

pandas/core/groupby/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
983983
# try to treat as if we are passing a list
984984
try:
985985
result, _ = GroupByApply(
986-
self, [func], args=(), kwds={"_axis": self.axis}
986+
self, [func], args=(), kwargs={"_axis": self.axis}
987987
).agg()
988988

989989
# select everything except for the last level, which is the one

pandas/core/resample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def pipe(
301301
def aggregate(self, func, *args, **kwargs):
302302

303303
self._set_binner()
304-
result, how = ResamplerWindowApply(self, func, args=args, kwds=kwargs).agg()
304+
result, how = ResamplerWindowApply(self, func, args=args, kwargs=kwargs).agg()
305305
if result is None:
306306
how = func
307307
grouper = None

pandas/core/series.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3967,7 +3967,7 @@ def aggregate(self, func=None, axis=0, *args, **kwargs):
39673967
if func is None:
39683968
func = dict(kwargs.items())
39693969

3970-
op = series_apply(self, func, args=args, kwds=kwargs)
3970+
op = series_apply(self, func, args=args, kwargs=kwargs)
39713971
result, how = op.agg()
39723972
if result is None:
39733973

@@ -4008,7 +4008,7 @@ def apply(
40084008
func: AggFuncType,
40094009
convert_dtype: bool = True,
40104010
args: Tuple[Any, ...] = (),
4011-
**kwds,
4011+
**kwargs,
40124012
) -> FrameOrSeriesUnion:
40134013
"""
40144014
Invoke function on values of Series.
@@ -4025,7 +4025,7 @@ def apply(
40254025
False, leave as dtype=object.
40264026
args : tuple
40274027
Positional arguments passed to func after the series value.
4028-
**kwds
4028+
**kwargs
40294029
Additional keyword arguments passed to func.
40304030
40314031
Returns
@@ -4106,7 +4106,7 @@ def apply(
41064106
Helsinki 2.484907
41074107
dtype: float64
41084108
"""
4109-
op = series_apply(self, func, convert_dtype, args, kwds)
4109+
op = series_apply(self, func, convert_dtype, args, kwargs)
41104110
return op.apply()
41114111

41124112
def _reduce(

pandas/core/window/rolling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def calc(x):
510510
return self._apply_tablewise(homogeneous_func, name)
511511

512512
def aggregate(self, func, *args, **kwargs):
513-
result, how = ResamplerWindowApply(self, func, args=args, kwds=kwargs).agg()
513+
result, how = ResamplerWindowApply(self, func, args=args, kwargs=kwargs).agg()
514514
if result is None:
515515
return self.apply(func, raw=False, args=args, kwargs=kwargs)
516516
return result
@@ -994,7 +994,7 @@ def calc(x):
994994
axis="",
995995
)
996996
def aggregate(self, func, *args, **kwargs):
997-
result, how = ResamplerWindowApply(self, func, args=args, kwds=kwargs).agg()
997+
result, how = ResamplerWindowApply(self, func, args=args, kwargs=kwargs).agg()
998998
if result is None:
999999

10001000
# these must apply directly

0 commit comments

Comments
 (0)