@@ -1231,20 +1231,8 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
1231
1231
1232
1232
key_index = self .grouper .result_index if self .as_index else None
1233
1233
1234
- if isinstance (first_not_none , NDFrame ):
1235
-
1236
- # this is to silence a DeprecationWarning
1237
- # TODO: Remove when default dtype of empty Series is object
1238
- kwargs = first_not_none ._construct_axes_dict ()
1239
- if isinstance (first_not_none , Series ):
1240
- backup = create_series_with_explicit_dtype (
1241
- ** kwargs , dtype_if_empty = object
1242
- )
1243
- else :
1244
- backup = first_not_none ._constructor (** kwargs )
1234
+ if not isinstance (first_not_none , (Series , np .ndarray , Index )):
1245
1235
1246
- values = [x if (x is not None ) else backup for x in values ]
1247
- else :
1248
1236
# values are not series or array-like but scalars
1249
1237
# self._selection_name not passed through to Series as the
1250
1238
# result should not take the name of original selection
@@ -1256,24 +1244,31 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
1256
1244
self ._insert_inaxis_grouper_inplace (result )
1257
1245
return result
1258
1246
1259
- v = values [ 0 ]
1247
+ elif not isinstance ( first_not_none , Series ):
1260
1248
1261
- if not isinstance (v , ABCSeries ):
1262
1249
# GH1738: values is list of arrays of unequal lengths
1263
1250
# TODO: sure this is right? we used to do this
1264
1251
# after raising AttributeError above
1265
1252
return self .obj ._constructor_sliced (
1266
1253
values , index = key_index , name = self ._selection_name
1267
1254
)
1268
1255
1256
+ # this is to silence a DeprecationWarning
1257
+ # TODO: Replace when default dtype of empty Series is object
1258
+ # with backup = first_not_none._constructor(**kwargs)
1259
+ kwargs = first_not_none ._construct_axes_dict ()
1260
+ backup = create_series_with_explicit_dtype (** kwargs , dtype_if_empty = object )
1261
+ values = [x if (x is not None ) else backup for x in values ]
1262
+
1263
+ v = values [0 ]
1269
1264
all_indexed_same = all_indexes_same ((x .index for x in values ))
1270
1265
1271
1266
# GH3596 - provide a reduction (Frame -> Series) if groups are unique
1272
1267
if self .squeeze :
1273
1268
# assign the name to this series
1274
1269
applied_index = self ._selected_obj ._get_axis (self .axis )
1275
1270
if len (values ) == 1 and applied_index .nlevels == 1 :
1276
- values [ 0 ] .name = keys [0 ]
1271
+ v .name = keys [0 ]
1277
1272
1278
1273
# GH2893
1279
1274
# we have series in the values array, we want to
0 commit comments