|
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,7 @@ 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(result, index=index) |
263 | 264 |
|
264 | 265 | if not self.as_index: # pragma: no cover
|
265 | 266 | print("Warning, ignoring as_index=True")
|
@@ -407,7 +408,7 @@ def _wrap_transformed_output(
|
407 | 408 | def _wrap_applied_output(self, keys, values, not_indexed_same=False):
|
408 | 409 | if len(keys) == 0:
|
409 | 410 | # GH #6265
|
410 |
| - return Series([], name=self._selection_name, index=keys) |
| 411 | + return Series([], name=self._selection_name, index=keys, dtype=np.float64) |
411 | 412 |
|
412 | 413 | def _get_index() -> Index:
|
413 | 414 | if self.grouper.nkeys > 1:
|
@@ -493,7 +494,7 @@ def _transform_general(self, func, *args, **kwargs):
|
493 | 494 |
|
494 | 495 | result = concat(results).sort_index()
|
495 | 496 | else:
|
496 |
| - result = Series() |
| 497 | + result = Series(dtype=np.float64) |
497 | 498 |
|
498 | 499 | # we will only try to coerce the result type if
|
499 | 500 | # we have a numeric dtype, as these are *always* user-defined funcs
|
@@ -1205,9 +1206,17 @@ def first_not_none(values):
|
1205 | 1206 | if v is None:
|
1206 | 1207 | return DataFrame()
|
1207 | 1208 | elif isinstance(v, NDFrame):
|
| 1209 | + |
| 1210 | + # this is to silence a FutureWarning |
| 1211 | + # TODO: Remove when default dtype of empty Series is object |
| 1212 | + kwargs = v._construct_axes_dict() |
| 1213 | + if v._constructor is Series: |
| 1214 | + is_empty = "data" not in kwargs or not kwargs["data"] |
| 1215 | + if "dtype" not in kwargs and is_empty: |
| 1216 | + kwargs["dtype"] = object |
| 1217 | + |
1208 | 1218 | values = [
|
1209 |
| - x if x is not None else v._constructor(**v._construct_axes_dict()) |
1210 |
| - for x in values |
| 1219 | + x if (x is not None) else v._constructor(**kwargs) for x in values |
1211 | 1220 | ]
|
1212 | 1221 |
|
1213 | 1222 | v = values[0]
|
|
0 commit comments