@@ -1101,22 +1101,28 @@ def _aggregate_frame(self, func, *args, **kwargs) -> DataFrame:
1101
1101
if self .grouper .nkeys != 1 :
1102
1102
raise AssertionError ("Number of keys must be 1" )
1103
1103
1104
- axis = self .axis
1105
1104
obj = self ._obj_with_exclusions
1106
1105
1107
1106
result : dict [Hashable , NDFrame | np .ndarray ] = {}
1108
- if axis != obj . _info_axis_number :
1107
+ if self . axis == 0 :
1109
1108
# test_pass_args_kwargs_duplicate_columns gets here with non-unique columns
1110
1109
for name , data in self :
1111
1110
fres = func (data , * args , ** kwargs )
1112
1111
result [name ] = fres
1113
1112
else :
1113
+ # we get here in a number of test_multilevel tests
1114
1114
for name in self .indices :
1115
1115
data = self .get_group (name , obj = obj )
1116
1116
fres = func (data , * args , ** kwargs )
1117
1117
result [name ] = fres
1118
1118
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
1120
1126
1121
1127
def _aggregate_item_by_item (self , func , * args , ** kwargs ) -> DataFrame :
1122
1128
# only for axis==0
@@ -1568,16 +1574,6 @@ def _gotitem(self, key, ndim: int, subset=None):
1568
1574
1569
1575
raise AssertionError ("invalid ndim for _gotitem" )
1570
1576
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
-
1581
1577
def _get_data_to_aggregate (self ) -> Manager2D :
1582
1578
obj = self ._obj_with_exclusions
1583
1579
if self .axis == 1 :
0 commit comments