Skip to content

Commit 46fb34c

Browse files
rhshadrachznicholls
authored andcommitted
CLN: Remove "how" return from agg (pandas-dev#39786)
1 parent 6646f7c commit 46fb34c

File tree

6 files changed

+19
-24
lines changed

6 files changed

+19
-24
lines changed

pandas/core/apply.py

+8-14
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,14 @@ def index(self) -> Index:
147147
def apply(self) -> FrameOrSeriesUnion:
148148
pass
149149

150-
def agg(self) -> Tuple[Optional[FrameOrSeriesUnion], Optional[bool]]:
150+
def agg(self) -> Optional[FrameOrSeriesUnion]:
151151
"""
152152
Provide an implementation for the aggregators.
153153
154154
Returns
155155
-------
156-
tuple of result, how.
157-
158-
Notes
159-
-----
160-
how can be a string describe the required post-processing, or
161-
None if not required.
156+
Result of aggregation, or None if agg cannot be performed by
157+
this method.
162158
"""
163159
obj = self.obj
164160
arg = self.f
@@ -171,23 +167,21 @@ def agg(self) -> Tuple[Optional[FrameOrSeriesUnion], Optional[bool]]:
171167

172168
result = self.maybe_apply_str()
173169
if result is not None:
174-
return result, None
170+
return result
175171

176172
if is_dict_like(arg):
177-
return self.agg_dict_like(_axis), True
173+
return self.agg_dict_like(_axis)
178174
elif is_list_like(arg):
179175
# we require a list, but not a 'str'
180-
return self.agg_list_like(_axis=_axis), None
181-
else:
182-
result = None
176+
return self.agg_list_like(_axis=_axis)
183177

184178
if callable(arg):
185179
f = obj._get_cython_func(arg)
186180
if f and not args and not kwargs:
187-
return getattr(obj, f)(), None
181+
return getattr(obj, f)()
188182

189183
# caller can react
190-
return result, True
184+
return None
191185

192186
def agg_list_like(self, _axis: int) -> FrameOrSeriesUnion:
193187
"""

pandas/core/frame.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7686,7 +7686,7 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs):
76867686

76877687
result = None
76887688
try:
7689-
result, how = self._aggregate(func, axis, *args, **kwargs)
7689+
result = self._aggregate(func, axis, *args, **kwargs)
76907690
except TypeError as err:
76917691
exc = TypeError(
76927692
"DataFrame constructor called with "
@@ -7720,14 +7720,14 @@ def _aggregate(self, arg, axis: Axis = 0, *args, **kwargs):
77207720
args=args,
77217721
kwargs=kwargs,
77227722
)
7723-
result, how = op.agg()
7723+
result = op.agg()
77247724

77257725
if axis == 1:
77267726
# NDFrame.aggregate returns a tuple, and we need to transpose
77277727
# only result
77287728
result = result.T if result is not None else result
77297729

7730-
return result, how
7730+
return result
77317731

77327732
agg = aggregate
77337733

pandas/core/groupby/generic.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
ensure_platform_int,
4747
is_bool,
4848
is_categorical_dtype,
49+
is_dict_like,
4950
is_integer_dtype,
5051
is_interval_dtype,
5152
is_numeric_dtype,
@@ -968,8 +969,8 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
968969
func = maybe_mangle_lambdas(func)
969970

970971
op = GroupByApply(self, func, args, kwargs)
971-
result, how = op.agg()
972-
if how is None:
972+
result = op.agg()
973+
if not is_dict_like(func) and result is not None:
973974
return result
974975

975976
if result is None:
@@ -988,7 +989,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
988989

989990
# try to treat as if we are passing a list
990991
try:
991-
result, _ = GroupByApply(
992+
result = GroupByApply(
992993
self, [func], args=(), kwargs={"_axis": self.axis}
993994
).agg()
994995

pandas/core/resample.py

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

302302
self._set_binner()
303-
result, how = ResamplerWindowApply(self, func, args=args, kwargs=kwargs).agg()
303+
result = ResamplerWindowApply(self, func, args=args, kwargs=kwargs).agg()
304304
if result is None:
305305
how = func
306306
grouper = None

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3973,7 +3973,7 @@ def aggregate(self, func=None, axis=0, *args, **kwargs):
39733973
func = dict(kwargs.items())
39743974

39753975
op = series_apply(self, func, args=args, kwargs=kwargs)
3976-
result, how = op.agg()
3976+
result = op.agg()
39773977
if result is None:
39783978

39793979
# we can be called from an inner function which

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, kwargs=kwargs).agg()
513+
result = 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, kwargs=kwargs).agg()
997+
result = ResamplerWindowApply(self, func, args=args, kwargs=kwargs).agg()
998998
if result is None:
999999

10001000
# these must apply directly

0 commit comments

Comments
 (0)