@@ -1206,7 +1206,6 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
1206
1206
key_index = self .grouper .result_index if self .as_index else None
1207
1207
1208
1208
if isinstance (first_not_none , Series ):
1209
-
1210
1209
# this is to silence a DeprecationWarning
1211
1210
# TODO: Remove when default dtype of empty Series is object
1212
1211
kwargs = first_not_none ._construct_axes_dict ()
@@ -1218,16 +1217,26 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
1218
1217
1219
1218
v = values [0 ]
1220
1219
1221
- if isinstance (v , (np .ndarray , Index , Series )) or not self .as_index :
1220
+ if not isinstance (v , (np .ndarray , Index , Series )) and self .as_index :
1221
+ # values are not series or array-like but scalars
1222
+ # self._selection_name not passed through to Series as the
1223
+ # result should not take the name of original selection
1224
+ # of columns
1225
+ return self .obj ._constructor_sliced (values , index = key_index )
1226
+
1227
+ else :
1222
1228
if isinstance (v , Series ):
1223
- applied_index = self ._selected_obj ._get_axis (self .axis )
1224
1229
all_indexed_same = all_indexes_same ((x .index for x in values ))
1225
- singular_series = len (values ) == 1 and applied_index .nlevels == 1
1226
1230
1227
1231
# GH3596
1228
1232
# provide a reduction (Frame -> Series) if groups are
1229
1233
# unique
1230
1234
if self .squeeze :
1235
+ applied_index = self ._selected_obj ._get_axis (self .axis )
1236
+ singular_series = (
1237
+ len (values ) == 1 and applied_index .nlevels == 1
1238
+ )
1239
+
1231
1240
# assign the name to this series
1232
1241
if singular_series :
1233
1242
values [0 ].name = keys [0 ]
@@ -1253,18 +1262,6 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
1253
1262
# GH 8467
1254
1263
return self ._concat_objects (keys , values , not_indexed_same = True )
1255
1264
1256
- # GH6124 if the list of Series have a consistent name,
1257
- # then propagate that name to the result.
1258
- index = v .index .copy ()
1259
- if index .name is None :
1260
- # Only propagate the series name to the result
1261
- # if all series have a consistent name. If the
1262
- # series do not have a consistent name, do
1263
- # nothing.
1264
- names = {v .name for v in values }
1265
- if len (names ) == 1 :
1266
- index .name = list (names )[0 ]
1267
-
1268
1265
# Combine values
1269
1266
# vstack+constructor is faster than concat and handles MI-columns
1270
1267
stacked_values = np .vstack ([np .asarray (v ) for v in values ])
@@ -1313,13 +1310,6 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
1313
1310
1314
1311
return self ._reindex_output (result )
1315
1312
1316
- # values are not series or array-like but scalars
1317
- else :
1318
- # self._selection_name not passed through to Series as the
1319
- # result should not take the name of original selection
1320
- # of columns
1321
- return self .obj ._constructor_sliced (values , index = key_index )
1322
-
1323
1313
def _transform_general (
1324
1314
self , func , * args , engine = "cython" , engine_kwargs = None , ** kwargs
1325
1315
):
0 commit comments