@@ -251,7 +251,13 @@ def aggregate(self, func=None, *args, **kwargs):
251
251
result = self ._aggregate_named (func , * args , ** kwargs )
252
252
253
253
index = Index (sorted (result ), name = self .grouper .names [0 ])
254
- ret = Series (result , index = index )
254
+
255
+ # TODO: if/else can be removed as soon as default dtype
256
+ # for empty series is changed object
257
+ if result :
258
+ ret = Series (result , index = index )
259
+ else :
260
+ ret = Series (result , index = index , dtype = object )
255
261
256
262
if not self .as_index : # pragma: no cover
257
263
print ("Warning, ignoring as_index=True" )
@@ -348,7 +354,7 @@ def _wrap_transformed_output(self, output, names=None):
348
354
def _wrap_applied_output (self , keys , values , not_indexed_same = False ):
349
355
if len (keys ) == 0 :
350
356
# GH #6265
351
- return Series ([], name = self ._selection_name , index = keys )
357
+ return Series ([], name = self ._selection_name , index = keys , dtype = np . float64 )
352
358
353
359
def _get_index () -> Index :
354
360
if self .grouper .nkeys > 1 :
@@ -430,7 +436,7 @@ def transform(self, func, *args, **kwargs):
430
436
431
437
result = concat (results ).sort_index ()
432
438
else :
433
- result = Series ()
439
+ result = Series (dtype = np . float64 )
434
440
435
441
# we will only try to coerce the result type if
436
442
# we have a numeric dtype, as these are *always* udfs
@@ -1164,9 +1170,17 @@ def first_not_none(values):
1164
1170
if v is None :
1165
1171
return DataFrame ()
1166
1172
elif isinstance (v , NDFrame ):
1173
+
1174
+ # this is to silence a FutureWarning
1175
+ # TODO: Remove when default dtype of empty Series is object
1176
+ kwargs = v ._construct_axes_dict ()
1177
+ if v ._constructor is Series :
1178
+ is_empty = "data" not in kwargs or not kwargs ["data" ]
1179
+ if "dtype" not in kwargs and is_empty :
1180
+ kwargs ["dtype" ] = object
1181
+
1167
1182
values = [
1168
- x if x is not None else v ._constructor (** v ._construct_axes_dict ())
1169
- for x in values
1183
+ x if (x is not None ) else v ._constructor (** kwargs ) for x in values
1170
1184
]
1171
1185
1172
1186
v = values [0 ]
0 commit comments