Skip to content

Commit

Permalink
BUG: get_indexer_not_unique inconsistent return types vs get_indexer p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ri938 committed Jul 4, 2017
1 parent 565bf4c commit 27d126f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Bug Fixes
~~~~~~~~~
- Fixed issue with dataframe scatter plot for categorical data that reports incorrect column key not found when categorical data is used for plotting (:issue:`16199`)
- Bug in reindexing on an empty CategoricalIndex (:issue:`16770`)

- Bug in get_indexer_non_unique inconsistent return type with get_indexer (:issue:`16819`)


Conversion
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@ def get_indexer_non_unique(self, target):
tgt_values = target._values

indexer, missing = self._engine.get_indexer_non_unique(tgt_values)
return Index(indexer), missing
return indexer, missing

def get_indexer_for(self, target, **kwargs):
"""
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,16 @@ def test_get_indexer_strings(self):
with pytest.raises(TypeError):
idx.get_indexer(['a', 'b', 'c', 'd'], method='pad', tolerance=2)

def test_get_indexer_consistency(self):
# See GH 16819
for name, index in self.indices.items():
expected = index.get_indexer(index[0:2])
result, _ = index.get_indexer_non_unique(index[0:2])
assert isinstance(expected, np.ndarray)
assert expected.dtype == np.intp
assert isinstance(result, np.ndarray)
assert result.dtype == np.intp

def test_get_loc(self):
idx = pd.Index([0, 1, 2])
all_methods = [None, 'pad', 'backfill', 'nearest']
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ def test_reindexing(self):
expected = oidx.get_indexer_non_unique(finder)[0]

actual = ci.get_indexer(finder)
tm.assert_numpy_array_equal(
expected.values, actual, check_dtype=False)
tm.assert_numpy_array_equal(expected, actual, check_dtype=True)

def test_reindex_dtype(self):
c = CategoricalIndex(['a', 'b', 'c', 'a'])
Expand Down

0 comments on commit 27d126f

Please sign in to comment.