@@ -369,7 +369,6 @@ def _indexed_output_to_ndframe(
369
369
def _wrap_applied_output (
370
370
self ,
371
371
data : Series ,
372
- keys : Index ,
373
372
values : list [Any ] | None ,
374
373
not_indexed_same : bool = False ,
375
374
) -> DataFrame | Series :
@@ -380,8 +379,6 @@ def _wrap_applied_output(
380
379
----------
381
380
data : Series
382
381
Input data for groupby operation.
383
- keys : Index
384
- Keys of groups that Series was grouped by.
385
382
values : Optional[List[Any]]
386
383
Applied output for each group.
387
384
not_indexed_same : bool, default False
@@ -391,6 +388,8 @@ def _wrap_applied_output(
391
388
-------
392
389
DataFrame or Series
393
390
"""
391
+ keys = self .grouper .group_keys_seq
392
+
394
393
if len (keys ) == 0 :
395
394
# GH #6265
396
395
return self .obj ._constructor (
@@ -412,7 +411,7 @@ def _wrap_applied_output(
412
411
res_ser .name = self .obj .name
413
412
return res_ser
414
413
elif isinstance (values [0 ], (Series , DataFrame )):
415
- return self ._concat_objects (keys , values , not_indexed_same = not_indexed_same )
414
+ return self ._concat_objects (values , not_indexed_same = not_indexed_same )
416
415
else :
417
416
# GH #6265 #24880
418
417
result = self .obj ._constructor (
@@ -1100,7 +1099,9 @@ def _aggregate_item_by_item(self, func, *args, **kwargs) -> DataFrame:
1100
1099
res_df .columns = obj .columns
1101
1100
return res_df
1102
1101
1103
- def _wrap_applied_output (self , data , keys , values , not_indexed_same = False ):
1102
+ def _wrap_applied_output (self , data , values , not_indexed_same = False ):
1103
+ keys = self .grouper .group_keys_seq
1104
+
1104
1105
if len (keys ) == 0 :
1105
1106
result = self .obj ._constructor (
1106
1107
index = self .grouper .result_index , columns = data .columns
@@ -1115,7 +1116,7 @@ def _wrap_applied_output(self, data, keys, values, not_indexed_same=False):
1115
1116
# GH9684 - All values are None, return an empty frame.
1116
1117
return self .obj ._constructor ()
1117
1118
elif isinstance (first_not_none , DataFrame ):
1118
- return self ._concat_objects (keys , values , not_indexed_same = not_indexed_same )
1119
+ return self ._concat_objects (values , not_indexed_same = not_indexed_same )
1119
1120
1120
1121
key_index = self .grouper .result_index if self .as_index else None
1121
1122
@@ -1143,12 +1144,11 @@ def _wrap_applied_output(self, data, keys, values, not_indexed_same=False):
1143
1144
else :
1144
1145
# values are Series
1145
1146
return self ._wrap_applied_output_series (
1146
- keys , values , not_indexed_same , first_not_none , key_index
1147
+ values , not_indexed_same , first_not_none , key_index
1147
1148
)
1148
1149
1149
1150
def _wrap_applied_output_series (
1150
1151
self ,
1151
- keys ,
1152
1152
values : list [Series ],
1153
1153
not_indexed_same : bool ,
1154
1154
first_not_none ,
@@ -1171,6 +1171,7 @@ def _wrap_applied_output_series(
1171
1171
1172
1172
# assign the name to this series
1173
1173
if singular_series :
1174
+ keys = self .grouper .group_keys_seq
1174
1175
values [0 ].name = keys [0 ]
1175
1176
1176
1177
# GH2893
@@ -1179,9 +1180,7 @@ def _wrap_applied_output_series(
1179
1180
# if any of the sub-series are not indexed the same
1180
1181
# OR we don't have a multi-index and we have only a
1181
1182
# single values
1182
- return self ._concat_objects (
1183
- keys , values , not_indexed_same = not_indexed_same
1184
- )
1183
+ return self ._concat_objects (values , not_indexed_same = not_indexed_same )
1185
1184
1186
1185
# still a series
1187
1186
# path added as of GH 5545
@@ -1192,7 +1191,7 @@ def _wrap_applied_output_series(
1192
1191
1193
1192
if not all_indexed_same :
1194
1193
# GH 8467
1195
- return self ._concat_objects (keys , values , not_indexed_same = True )
1194
+ return self ._concat_objects (values , not_indexed_same = True )
1196
1195
1197
1196
# Combine values
1198
1197
# vstack+constructor is faster than concat and handles MI-columns
0 commit comments