|
18 | 18 | from pandas.util.decorators import cache_readonly, Appender
|
19 | 19 | import pandas.core.algorithms as algos
|
20 | 20 | import pandas.core.common as com
|
21 |
| -from pandas.core.common import _possibly_downcast_to_dtype, isnull, notnull |
| 21 | +from pandas.core.common import(_possibly_downcast_to_dtype, isnull, |
| 22 | + notnull, _DATELIKE_DTYPES) |
22 | 23 |
|
23 | 24 | import pandas.lib as lib
|
24 | 25 | import pandas.algos as _algos
|
@@ -2169,11 +2170,12 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
|
2169 | 2170 | break
|
2170 | 2171 | if v is None:
|
2171 | 2172 | return DataFrame()
|
2172 |
| - values = [ |
2173 |
| - x if x is not None else |
2174 |
| - v._constructor(**v._construct_axes_dict()) |
2175 |
| - for x in values |
2176 |
| - ] |
| 2173 | + elif isinstance(v, NDFrame): |
| 2174 | + values = [ |
| 2175 | + x if x is not None else |
| 2176 | + v._constructor(**v._construct_axes_dict()) |
| 2177 | + for x in values |
| 2178 | + ] |
2177 | 2179 |
|
2178 | 2180 | v = values[0]
|
2179 | 2181 |
|
@@ -2235,11 +2237,17 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False):
|
2235 | 2237 | # through to the outer else caluse
|
2236 | 2238 | return Series(values, index=key_index)
|
2237 | 2239 |
|
| 2240 | + # if we have date/time like in the original, then coerce dates |
| 2241 | + # as we are stacking can easily have object dtypes here |
| 2242 | + cd = True |
| 2243 | + if self.obj.ndim == 2 and self.obj.dtypes.isin(_DATELIKE_DTYPES).any(): |
| 2244 | + cd = 'coerce' |
2238 | 2245 | return DataFrame(stacked_values, index=index,
|
2239 |
| - columns=columns).convert_objects() |
| 2246 | + columns=columns).convert_objects(convert_dates=cd, convert_numeric=True) |
2240 | 2247 |
|
2241 | 2248 | else:
|
2242 |
| - return Series(values, index=key_index) |
| 2249 | + return Series(values, index=key_index).convert_objects( |
| 2250 | + convert_dates='coerce',convert_numeric=True) |
2243 | 2251 | else:
|
2244 | 2252 | # Handle cases like BinGrouper
|
2245 | 2253 | return self._concat_objects(keys, values,
|
|
0 commit comments