Skip to content

REF: remove aggregate_item_by_item #51222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,22 +1378,6 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame:

return out

def _aggregate_item_by_item(self, func, *args, **kwargs) -> DataFrame:
# only for axis==0
# tests that get here with non-unique cols:
# test_resample_with_timedelta_yields_no_empty_groups,
# test_resample_apply_product

obj = self._obj_with_exclusions
result: dict[int, NDFrame] = {}

for i, (item, sgb) in enumerate(self._iterate_column_groupbys(obj)):
result[i] = sgb.aggregate(func, *args, **kwargs)

res_df = self.obj._constructor(result)
res_df.columns = obj.columns
return res_df

def _wrap_applied_output(
self,
data: DataFrame,
Expand Down
17 changes: 6 additions & 11 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
npt,
)
from pandas.compat.numpy import function as nv
from pandas.errors import (
AbstractMethodError,
DataError,
)
from pandas.errors import AbstractMethodError
from pandas.util._decorators import (
Appender,
Substitution,
Expand Down Expand Up @@ -423,15 +420,13 @@ def _groupby_and_aggregate(self, how, *args, **kwargs):
)

try:
if isinstance(obj, ABCDataFrame) and callable(how):
# Check if the function is reducing or not.
# e.g. test_resample_apply_with_additional_args
result = grouped._aggregate_item_by_item(how, *args, **kwargs)
if callable(how):
# TODO: test_resample_apply_with_additional_args fails if we go
# through the non-lambda path, not clear that it should.
func = lambda x: how(x, *args, **kwargs)
result = grouped.aggregate(func)
else:
result = grouped.aggregate(how, *args, **kwargs)
except DataError:
# got TypeErrors on aggregation
result = grouped.apply(how, *args, **kwargs)
except (AttributeError, KeyError):
# we have a non-reducing function; try to evaluate
# alternatively we want to evaluate only a column of the input
Expand Down