diff --git a/doc/source/whatsnew/v0.20.3.txt b/doc/source/whatsnew/v0.20.3.txt index 3d82b2bd452bb..e555a24a853aa 100644 --- a/doc/source/whatsnew/v0.20.3.txt +++ b/doc/source/whatsnew/v0.20.3.txt @@ -42,7 +42,7 @@ Bug Fixes - Fixed compat with loading a ``DataFrame`` with a ``PeriodIndex``, from a ``format='fixed'`` HDFStore, in Python 3, that was written in Python 2 (:issue:`16781`) - Fixed a bug in failing to compute rolling computations of a column-MultiIndexed ``DataFrame`` (:issue:`16789`, :issue:`16825`) - Bug in a DataFrame/Series with a ``TimedeltaIndex`` when slice indexing (:issue:`16637`) -- Handle reindexing an empty categorical index rather than throwing (:issue:`16770`) +- Bug in reindexing on an empty ``CategoricalIndex`` (:issue:`16770`) Conversion diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index 7d3d96311f05a..b7ae053461cb5 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -420,7 +420,7 @@ def reindex(self, target, method=None, level=None, limit=None, indexer, missing = self.get_indexer_non_unique(np.array(target)) - if len(self.codes): + if len(indexer): new_target = self.take(indexer) else: new_target = target @@ -434,8 +434,6 @@ def reindex(self, target, method=None, level=None, limit=None, result = Index(np.array(self), name=self.name) new_target, indexer, _ = result._reindex_non_unique( np.array(target)) - # see GH 16819, indexer needs to be converted to correct type - indexer = np.array(indexer, dtype=np.int64) else: codes = new_target.codes.copy() diff --git a/pandas/tests/indexes/test_category.py b/pandas/tests/indexes/test_category.py index e1ac811b90bbc..1382b6bce0248 100644 --- a/pandas/tests/indexes/test_category.py +++ b/pandas/tests/indexes/test_category.py @@ -425,7 +425,7 @@ def test_reindex_empty_index(self): res, indexer = c.reindex(['a', 'b']) tm.assert_index_equal(res, Index(['a', 'b']), exact=True) tm.assert_numpy_array_equal(indexer, - np.array([-1, -1], dtype=np.int64)) + np.array([-1, -1], dtype=np.intp)) def test_duplicates(self):