|
51 | 51 | import pandas.core.algorithms as algorithms
|
52 | 52 | from pandas.core.base import DataError, SpecificationError
|
53 | 53 | import pandas.core.common as com
|
| 54 | +from pandas.core.construction import create_series_with_explicit_dtype |
54 | 55 | from pandas.core.frame import DataFrame
|
55 | 56 | from pandas.core.generic import ABCDataFrame, ABCSeries, NDFrame, _shared_docs
|
56 | 57 | from pandas.core.groupby import base
|
@@ -259,7 +260,9 @@ def aggregate(self, func=None, *args, **kwargs):
|
259 | 260 | result = self._aggregate_named(func, *args, **kwargs)
|
260 | 261 |
|
261 | 262 | index = Index(sorted(result), name=self.grouper.names[0])
|
262 |
| - ret = Series(result, index=index) |
| 263 | + ret = create_series_with_explicit_dtype( |
| 264 | + result, index=index, dtype_if_empty=object |
| 265 | + ) |
263 | 266 |
|
264 | 267 | if not self.as_index: # pragma: no cover
|
265 | 268 | print("Warning, ignoring as_index=True")
|
@@ -407,7 +410,7 @@ def _wrap_transformed_output(
|
407 | 410 | def _wrap_applied_output(self, keys, values, not_indexed_same=False):
|
408 | 411 | if len(keys) == 0:
|
409 | 412 | # GH #6265
|
410 |
| - return Series([], name=self._selection_name, index=keys) |
| 413 | + return Series([], name=self._selection_name, index=keys, dtype=np.float64) |
411 | 414 |
|
412 | 415 | def _get_index() -> Index:
|
413 | 416 | if self.grouper.nkeys > 1:
|
@@ -493,7 +496,7 @@ def _transform_general(self, func, *args, **kwargs):
|
493 | 496 |
|
494 | 497 | result = concat(results).sort_index()
|
495 | 498 | else:
|
496 |
| - result = Series() |
| 499 | + result = Series(dtype=np.float64) |
497 | 500 |
|
498 | 501 | # we will only try to coerce the result type if
|
499 | 502 | # we have a numeric dtype, as these are *always* user-defined funcs
|
@@ -1205,10 +1208,18 @@ def first_not_none(values):
|
1205 | 1208 | if v is None:
|
1206 | 1209 | return DataFrame()
|
1207 | 1210 | elif isinstance(v, NDFrame):
|
1208 |
| - values = [ |
1209 |
| - x if x is not None else v._constructor(**v._construct_axes_dict()) |
1210 |
| - for x in values |
1211 |
| - ] |
| 1211 | + |
| 1212 | + # this is to silence a DeprecationWarning |
| 1213 | + # TODO: Remove when default dtype of empty Series is object |
| 1214 | + kwargs = v._construct_axes_dict() |
| 1215 | + if v._constructor is Series: |
| 1216 | + backup = create_series_with_explicit_dtype( |
| 1217 | + **kwargs, dtype_if_empty=object |
| 1218 | + ) |
| 1219 | + else: |
| 1220 | + backup = v._constructor(**kwargs) |
| 1221 | + |
| 1222 | + values = [x if (x is not None) else backup for x in values] |
1212 | 1223 |
|
1213 | 1224 | v = values[0]
|
1214 | 1225 |
|
|
0 commit comments