Skip to content

REF: remove _wrap_frame_output #41461

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
May 13, 2021
Merged
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
22 changes: 9 additions & 13 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,22 +1101,28 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame:
if self.grouper.nkeys != 1:
raise AssertionError("Number of keys must be 1")

axis = self.axis
obj = self._obj_with_exclusions

result: dict[Hashable, NDFrame | np.ndarray] = {}
if axis != obj._info_axis_number:
if self.axis == 0:
# test_pass_args_kwargs_duplicate_columns gets here with non-unique columns
for name, data in self:
fres = func(data, *args, **kwargs)
result[name] = fres
else:
# we get here in a number of test_multilevel tests
for name in self.indices:
data = self.get_group(name, obj=obj)
fres = func(data, *args, **kwargs)
result[name] = fres

return self._wrap_frame_output(result, obj)
result_index = self.grouper.result_index
other_ax = obj.axes[1 - self.axis]
out = self.obj._constructor(result, index=other_ax, columns=result_index)
if self.axis == 0:
out = out.T

return out

def _aggregate_item_by_item(self, func, *args, **kwargs) -> DataFrame:
# only for axis==0
Expand Down Expand Up @@ -1568,16 +1574,6 @@ def _gotitem(self, key, ndim: int, subset=None):

raise AssertionError("invalid ndim for _gotitem")

def _wrap_frame_output(self, result: dict, obj: DataFrame) -> DataFrame:
result_index = self.grouper.levels[0]

if self.axis == 0:
return self.obj._constructor(
result, index=obj.columns, columns=result_index
).T
else:
return self.obj._constructor(result, index=obj.index, columns=result_index)

def _get_data_to_aggregate(self) -> Manager2D:
obj = self._obj_with_exclusions
if self.axis == 1:
Expand Down