Skip to content

Commit e4ee3d3

Browse files
authored
CLN: remove unnecessary return from agg_series (#41330)
1 parent 19b0e7a commit e4ee3d3

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

pandas/core/groupby/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ def _python_agg_general(self, func, *args, **kwargs):
12691269

12701270
try:
12711271
# if this function is invalid for this dtype, we will ignore it.
1272-
result, counts = self.grouper.agg_series(obj, f)
1272+
result = self.grouper.agg_series(obj, f)
12731273
except TypeError:
12741274
continue
12751275

@@ -1339,7 +1339,7 @@ def _agg_py_fallback(
13391339
# For SeriesGroupBy we could just use self instead of sgb
13401340

13411341
if self.ngroups > 0:
1342-
res_values, _ = self.grouper.agg_series(ser, alt)
1342+
res_values = self.grouper.agg_series(ser, alt)
13431343
else:
13441344
# equiv: res_values = self._python_agg_general(alt)
13451345
res_values = sgb._python_apply_general(alt, ser)._values

pandas/core/groupby/ops.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -968,28 +968,28 @@ def _cython_operation(
968968
)
969969

970970
@final
971-
def agg_series(self, obj: Series, func: F) -> tuple[ArrayLike, np.ndarray]:
971+
def agg_series(self, obj: Series, func: F) -> ArrayLike:
972972
# Caller is responsible for checking ngroups != 0
973973
assert self.ngroups != 0
974974

975975
cast_back = True
976976
if len(obj) == 0:
977977
# SeriesGrouper would raise if we were to call _aggregate_series_fast
978-
result, counts = self._aggregate_series_pure_python(obj, func)
978+
result = self._aggregate_series_pure_python(obj, func)
979979

980980
elif not isinstance(obj._values, np.ndarray):
981981
# _aggregate_series_fast would raise TypeError when
982982
# calling libreduction.Slider
983983
# In the datetime64tz case it would incorrectly cast to tz-naive
984984
# TODO: can we get a performant workaround for EAs backed by ndarray?
985-
result, counts = self._aggregate_series_pure_python(obj, func)
985+
result = self._aggregate_series_pure_python(obj, func)
986986

987987
elif obj.index._has_complex_internals:
988988
# Preempt TypeError in _aggregate_series_fast
989-
result, counts = self._aggregate_series_pure_python(obj, func)
989+
result = self._aggregate_series_pure_python(obj, func)
990990

991991
else:
992-
result, counts = self._aggregate_series_fast(obj, func)
992+
result = self._aggregate_series_fast(obj, func)
993993
cast_back = False
994994

995995
npvalues = lib.maybe_convert_objects(result, try_float=False)
@@ -998,11 +998,11 @@ def agg_series(self, obj: Series, func: F) -> tuple[ArrayLike, np.ndarray]:
998998
out = maybe_cast_pointwise_result(npvalues, obj.dtype, numeric_only=True)
999999
else:
10001000
out = npvalues
1001-
return out, counts
1001+
return out
1002+
1003+
def _aggregate_series_fast(self, obj: Series, func: F) -> np.ndarray:
1004+
# -> np.ndarray[object]
10021005

1003-
def _aggregate_series_fast(
1004-
self, obj: Series, func: F
1005-
) -> tuple[ArrayLike, np.ndarray]:
10061006
# At this point we have already checked that
10071007
# - obj.index is not a MultiIndex
10081008
# - obj is backed by an ndarray, not ExtensionArray
@@ -1017,11 +1017,12 @@ def _aggregate_series_fast(
10171017
obj = obj.take(indexer)
10181018
ids = ids.take(indexer)
10191019
sgrouper = libreduction.SeriesGrouper(obj, func, ids, ngroups)
1020-
result, counts = sgrouper.get_result()
1021-
return result, counts
1020+
result, _ = sgrouper.get_result()
1021+
return result
10221022

10231023
@final
1024-
def _aggregate_series_pure_python(self, obj: Series, func: F):
1024+
def _aggregate_series_pure_python(self, obj: Series, func: F) -> np.ndarray:
1025+
# -> np.ndarray[object]
10251026
ids, _, ngroups = self.group_info
10261027

10271028
counts = np.zeros(ngroups, dtype=int)
@@ -1046,7 +1047,7 @@ def _aggregate_series_pure_python(self, obj: Series, func: F):
10461047
counts[i] = group.shape[0]
10471048
result[i] = res
10481049

1049-
return result, counts
1050+
return result
10501051

10511052

10521053
class BinGrouper(BaseGrouper):
@@ -1204,16 +1205,17 @@ def groupings(self) -> list[grouper.Grouping]:
12041205
ping = grouper.Grouping(lev, lev, in_axis=False, level=None, name=lev.name)
12051206
return [ping]
12061207

1207-
def _aggregate_series_fast(
1208-
self, obj: Series, func: F
1209-
) -> tuple[ArrayLike, np.ndarray]:
1208+
def _aggregate_series_fast(self, obj: Series, func: F) -> np.ndarray:
1209+
# -> np.ndarray[object]
1210+
12101211
# At this point we have already checked that
12111212
# - obj.index is not a MultiIndex
12121213
# - obj is backed by an ndarray, not ExtensionArray
12131214
# - ngroups != 0
12141215
# - len(self.bins) > 0
12151216
sbg = libreduction.SeriesBinGrouper(obj, func, self.bins)
1216-
return sbg.get_result()
1217+
result, _ = sbg.get_result()
1218+
return result
12171219

12181220

12191221
def _is_indexed_like(obj, axes, axis: int) -> bool:

0 commit comments

Comments
 (0)