From ab05b877832c4da2b29f71757ec8c18c6baa856c Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sat, 3 Nov 2018 23:15:00 -0700 Subject: [PATCH 1/2] :TST: Empty Series.reindex with tz-aware dtype --- doc/source/whatsnew/v0.24.0.txt | 1 + pandas/tests/test_multilevel.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index b19003e1c1284..ea26a7882da13 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -1197,6 +1197,7 @@ Indexing - The traceback from a ``KeyError`` when asking ``.loc`` for a single missing label is now shorter and more clear (:issue:`21557`) - When ``.ix`` is asked for a missing integer label in a :class:`MultiIndex` with a first level of integer type, it now raises a ``KeyError``, consistently with the case of a flat :class:`Int64Index`, rather than falling back to positional indexing (:issue:`21593`) - Bug in :meth:`DatetimeIndex.reindex` when reindexing a tz-naive and tz-aware :class:`DatetimeIndex` (:issue:`8306`) +- Bug in :meth:`Series.reindex` when reindexing an empty series with a ``datetime64[ns, tz]`` dtype (:issue:`20869`) - Bug in :class:`DataFrame` when setting values with ``.loc`` and a timezone aware :class:`DatetimeIndex` (:issue:`11365`) - ``DataFrame.__getitem__`` now accepts dictionaries and dictionary keys as list-likes of labels, consistently with ``Series.__getitem__`` (:issue:`21294`) - Fixed ``DataFrame[np.nan]`` when columns are non-unique (:issue:`21428`) diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index 2022340926cca..e1ec3f65883c9 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -218,6 +218,12 @@ def test_reindex_preserve_levels(self): chunk = ymdT.loc[:, new_index] assert chunk.columns is new_index + def test_reindex_empty_series_tz_dtype(self): + # GH 20869 + result = Series(dtype='datetime64[ns, UTC]').reindex([0, 1]) + expected = Series([pd.NaT] * 2, dtype='datetime64[ns, UTC]') + tm.assert_equal(result, expected) + def test_repr_to_string(self): repr(self.frame) repr(self.ymd) From ac5cd2d677aa96142b15e72f80ece445cd6586e8 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sun, 4 Nov 2018 09:22:11 -0800 Subject: [PATCH 2/2] move test --- pandas/tests/series/indexing/test_alter_index.py | 7 +++++++ pandas/tests/test_multilevel.py | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pandas/tests/series/indexing/test_alter_index.py b/pandas/tests/series/indexing/test_alter_index.py index 25c930e8cade6..57a087221f411 100644 --- a/pandas/tests/series/indexing/test_alter_index.py +++ b/pandas/tests/series/indexing/test_alter_index.py @@ -459,6 +459,13 @@ def test_reindex_datetimeindexes_tz_naive_and_aware(): s.reindex(newidx, method='ffill') +def test_reindex_empty_series_tz_dtype(): + # GH 20869 + result = Series(dtype='datetime64[ns, UTC]').reindex([0, 1]) + expected = Series([pd.NaT] * 2, dtype='datetime64[ns, UTC]') + tm.assert_equal(result, expected) + + def test_rename(): # GH 17407 s = Series(range(1, 6), index=pd.Index(range(2, 7), name='IntIndex')) diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index e1ec3f65883c9..2022340926cca 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -218,12 +218,6 @@ def test_reindex_preserve_levels(self): chunk = ymdT.loc[:, new_index] assert chunk.columns is new_index - def test_reindex_empty_series_tz_dtype(self): - # GH 20869 - result = Series(dtype='datetime64[ns, UTC]').reindex([0, 1]) - expected = Series([pd.NaT] * 2, dtype='datetime64[ns, UTC]') - tm.assert_equal(result, expected) - def test_repr_to_string(self): repr(self.frame) repr(self.ymd)