Skip to content

Commit f5323ab

Browse files
DOC: add examples to get_indexer_non_unique (pandas-dev#50152)
* DOC: add examples to get_indexer_non_unique * DOC: add examples to get_indexer_non_unique II * DOC: add examples to get_indexer_non_unique III * Update pandas/core/indexes/base.py * Update pandas/core/indexes/base.py Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent 5fad2e4 commit f5323ab

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pandas/core/indexes/base.py

+25
Original file line numberDiff line numberDiff line change
@@ -5557,6 +5557,31 @@ def _should_fallback_to_positional(self) -> bool:
55575557
missing : np.ndarray[np.intp]
55585558
An indexer into the target of the values not found.
55595559
These correspond to the -1 in the indexer array.
5560+
5561+
Examples
5562+
--------
5563+
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b'])
5564+
>>> index.get_indexer_non_unique(['b', 'b'])
5565+
(array([1, 3, 4, 1, 3, 4]), array([], dtype=int64))
5566+
5567+
In the example below there are no matched values.
5568+
5569+
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b'])
5570+
>>> index.get_indexer_non_unique(['q', 'r', 't'])
5571+
(array([-1, -1, -1]), array([0, 1, 2]))
5572+
5573+
For this reason, the returned ``indexer`` contains only integers equal to -1.
5574+
It demonstrates that there's no match between the index and the ``target``
5575+
values at these positions. The mask [0, 1, 2] in the return value shows that
5576+
the first, second, and third elements are missing.
5577+
5578+
Notice that the return value is a tuple contains two items. In the example
5579+
below the first item is an array of locations in ``index``. The second
5580+
item is a mask shows that the first and third elements are missing.
5581+
5582+
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b'])
5583+
>>> index.get_indexer_non_unique(['f', 'b', 's'])
5584+
(array([-1, 1, 3, 4, -1]), array([0, 2]))
55605585
"""
55615586

55625587
@Appender(_index_shared_docs["get_indexer_non_unique"] % _index_doc_kwargs)

0 commit comments

Comments
 (0)