-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: add examples to get_indexer_non_unique #50152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
53b2f30
27b9ff0
ca39193
3d660b1
ef7c4e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5557,6 +5557,25 @@ def _should_fallback_to_positional(self) -> bool: | |
missing : np.ndarray[np.intp] | ||
An indexer into the target of the values not found. | ||
These correspond to the -1 in the indexer array. | ||
|
||
Examples | ||
-------- | ||
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) | ||
>>> index.get_indexer_non_unique(['f', 'b', 's']) | ||
(array([-1, 1, 3, 4, -1]), array([0, 2])) | ||
|
||
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) | ||
>>> index.get_indexer_non_unique(['b', 'b']) | ||
(array([1, 3, 4, 1, 3, 4]), array([], dtype=int64)) | ||
|
||
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b']) | ||
>>> index.get_indexer_non_unique(['q', 'r', 't']) | ||
(array([-1, -1, -1]), array([0, 1, 2])) | ||
|
||
Notice that the return value is a tuple contains two items. | ||
The first item is an array of locations in ``index`` and ``x`` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My mistake, there is no |
||
is marked by -1, as it is not in ``index``. The second item | ||
is a mask for new index given the current index. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure we need to repeat the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, there is no need to repeat |
||
""" | ||
|
||
@Appender(_index_shared_docs["get_indexer_non_unique"] % _index_doc_kwargs) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we give this example first?
and then have the examples with missing values
Apart from the first example, can we also have a sentence before the missing values one, describing what the example is demonstrating?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly. I will change the order of examples as you suggested.
Adding a sentence before the example with missing values sounds like a great idea.
To make this example more understandable I suggest the following explanation :
In the example below there are no matched values. For this reason, the returned indexer contains only integers equal to
-1
. It demonstrates no index at these positions that match the corresponding target values. The mask[0, 1, 2]
in the return value shows that the first, second, and third elements are missing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah looks fine