Skip to content

Commit df99a21

Browse files
authored
REF: remove aggregate_item_by_item (#51222)
1 parent bd508de commit df99a21

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

pandas/core/groupby/generic.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,22 +1378,6 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame:
13781378

13791379
return out
13801380

1381-
def _aggregate_item_by_item(self, func, *args, **kwargs) -> DataFrame:
1382-
# only for axis==0
1383-
# tests that get here with non-unique cols:
1384-
# test_resample_with_timedelta_yields_no_empty_groups,
1385-
# test_resample_apply_product
1386-
1387-
obj = self._obj_with_exclusions
1388-
result: dict[int, NDFrame] = {}
1389-
1390-
for i, (item, sgb) in enumerate(self._iterate_column_groupbys(obj)):
1391-
result[i] = sgb.aggregate(func, *args, **kwargs)
1392-
1393-
res_df = self.obj._constructor(result)
1394-
res_df.columns = obj.columns
1395-
return res_df
1396-
13971381
def _wrap_applied_output(
13981382
self,
13991383
data: DataFrame,

pandas/core/resample.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@
4040
npt,
4141
)
4242
from pandas.compat.numpy import function as nv
43-
from pandas.errors import (
44-
AbstractMethodError,
45-
DataError,
46-
)
43+
from pandas.errors import AbstractMethodError
4744
from pandas.util._decorators import (
4845
Appender,
4946
Substitution,
@@ -423,15 +420,13 @@ def _groupby_and_aggregate(self, how, *args, **kwargs):
423420
)
424421

425422
try:
426-
if isinstance(obj, ABCDataFrame) and callable(how):
427-
# Check if the function is reducing or not.
428-
# e.g. test_resample_apply_with_additional_args
429-
result = grouped._aggregate_item_by_item(how, *args, **kwargs)
423+
if callable(how):
424+
# TODO: test_resample_apply_with_additional_args fails if we go
425+
# through the non-lambda path, not clear that it should.
426+
func = lambda x: how(x, *args, **kwargs)
427+
result = grouped.aggregate(func)
430428
else:
431429
result = grouped.aggregate(how, *args, **kwargs)
432-
except DataError:
433-
# got TypeErrors on aggregation
434-
result = grouped.apply(how, *args, **kwargs)
435430
except (AttributeError, KeyError):
436431
# we have a non-reducing function; try to evaluate
437432
# alternatively we want to evaluate only a column of the input

0 commit comments

Comments
 (0)