Skip to content

Commit 35ce30a

Browse files
authored
REF: remove _wrap_frame_output (#41461)
1 parent 3849fdb commit 35ce30a

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

pandas/core/groupby/generic.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -1101,22 +1101,28 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame:
11011101
if self.grouper.nkeys != 1:
11021102
raise AssertionError("Number of keys must be 1")
11031103

1104-
axis = self.axis
11051104
obj = self._obj_with_exclusions
11061105

11071106
result: dict[Hashable, NDFrame | np.ndarray] = {}
1108-
if axis != obj._info_axis_number:
1107+
if self.axis == 0:
11091108
# test_pass_args_kwargs_duplicate_columns gets here with non-unique columns
11101109
for name, data in self:
11111110
fres = func(data, *args, **kwargs)
11121111
result[name] = fres
11131112
else:
1113+
# we get here in a number of test_multilevel tests
11141114
for name in self.indices:
11151115
data = self.get_group(name, obj=obj)
11161116
fres = func(data, *args, **kwargs)
11171117
result[name] = fres
11181118

1119-
return self._wrap_frame_output(result, obj)
1119+
result_index = self.grouper.result_index
1120+
other_ax = obj.axes[1 - self.axis]
1121+
out = self.obj._constructor(result, index=other_ax, columns=result_index)
1122+
if self.axis == 0:
1123+
out = out.T
1124+
1125+
return out
11201126

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

15691575
raise AssertionError("invalid ndim for _gotitem")
15701576

1571-
def _wrap_frame_output(self, result: dict, obj: DataFrame) -> DataFrame:
1572-
result_index = self.grouper.levels[0]
1573-
1574-
if self.axis == 0:
1575-
return self.obj._constructor(
1576-
result, index=obj.columns, columns=result_index
1577-
).T
1578-
else:
1579-
return self.obj._constructor(result, index=obj.index, columns=result_index)
1580-
15811577
def _get_data_to_aggregate(self) -> Manager2D:
15821578
obj = self._obj_with_exclusions
15831579
if self.axis == 1:

0 commit comments

Comments
 (0)