Skip to content

Commit 27d126f

Browse files
committed
BUG: get_indexer_not_unique inconsistent return types vs get_indexer pandas-dev#16819
1 parent 565bf4c commit 27d126f

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

doc/source/whatsnew/v0.20.3.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Bug Fixes
3838
~~~~~~~~~
3939
- 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`)
4040
- Bug in reindexing on an empty CategoricalIndex (:issue:`16770`)
41-
41+
- Bug in get_indexer_non_unique inconsistent return type with get_indexer (:issue:`16819`)
4242

4343

4444
Conversion

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2704,7 +2704,7 @@ def get_indexer_non_unique(self, target):
27042704
tgt_values = target._values
27052705

27062706
indexer, missing = self._engine.get_indexer_non_unique(tgt_values)
2707-
return Index(indexer), missing
2707+
return indexer, missing
27082708

27092709
def get_indexer_for(self, target, **kwargs):
27102710
"""

pandas/tests/indexes/test_base.py

+10
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,16 @@ def test_get_indexer_strings(self):
11311131
with pytest.raises(TypeError):
11321132
idx.get_indexer(['a', 'b', 'c', 'd'], method='pad', tolerance=2)
11331133

1134+
def test_get_indexer_consistency(self):
1135+
# See GH 16819
1136+
for name, index in self.indices.items():
1137+
expected = index.get_indexer(index[0:2])
1138+
result, _ = index.get_indexer_non_unique(index[0:2])
1139+
assert isinstance(expected, np.ndarray)
1140+
assert expected.dtype == np.intp
1141+
assert isinstance(result, np.ndarray)
1142+
assert result.dtype == np.intp
1143+
11341144
def test_get_loc(self):
11351145
idx = pd.Index([0, 1, 2])
11361146
all_methods = [None, 'pad', 'backfill', 'nearest']

pandas/tests/indexes/test_category.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ def test_reindexing(self):
386386
expected = oidx.get_indexer_non_unique(finder)[0]
387387

388388
actual = ci.get_indexer(finder)
389-
tm.assert_numpy_array_equal(
390-
expected.values, actual, check_dtype=False)
389+
tm.assert_numpy_array_equal(expected, actual, check_dtype=True)
391390

392391
def test_reindex_dtype(self):
393392
c = CategoricalIndex(['a', 'b', 'c', 'a'])

0 commit comments

Comments
 (0)