From 5e663c873575757b6a0d85a7e47b350367b8f664 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Thu, 25 Oct 2018 20:31:01 -0500 Subject: [PATCH] BUG: Handle Period in combine --- pandas/core/dtypes/cast.py | 8 +++++++- pandas/tests/frame/test_combine_concat.py | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 56bf394729773..46c8126f65fec 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -6,7 +6,7 @@ import warnings from pandas._libs import tslib, lib, tslibs -from pandas._libs.tslibs import iNaT, OutOfBoundsDatetime +from pandas._libs.tslibs import iNaT, OutOfBoundsDatetime, Period from pandas.compat import string_types, text_type, PY3 from .common import (ensure_object, is_bool, is_integer, is_float, is_complex, is_datetimetz, is_categorical_dtype, @@ -164,6 +164,12 @@ def trans(x): # noqa result = to_datetime(result).tz_localize('utc') result = result.tz_convert(dtype.tz) + elif dtype.type == Period: + # TODO(DatetimeArray): merge with previous elif + from pandas.core.arrays import PeriodArray + + return PeriodArray(result, freq=dtype.freq) + except Exception: pass diff --git a/pandas/tests/frame/test_combine_concat.py b/pandas/tests/frame/test_combine_concat.py index 2803db4f496a5..3b8d6e6c55ed1 100644 --- a/pandas/tests/frame/test_combine_concat.py +++ b/pandas/tests/frame/test_combine_concat.py @@ -759,7 +759,6 @@ def test_combine_first_timedelta(self): tm.assert_frame_equal(res, exp) assert res['TD'].dtype == 'timedelta64[ns]' - @pytest.mark.xfail(reason="GH-23079", strict=True) def test_combine_first_period(self): data1 = pd.PeriodIndex(['2011-01', 'NaT', '2011-03', '2011-04'], freq='M')