-
-
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
DOC: add examples to get_indexer_non_unique #50152
Conversation
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.
thanks for working on this
pandas/core/indexes/base.py
Outdated
(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 comment
The reason will be displayed to describe this comment to others. Learn more.
what's x
?
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.
My mistake, there is no x
in my examples ;) In this example, it should be q
, r
, and t
.
>>> 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)) |
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.
can we give this example first?
and then have the examples with missing values
Certainly. I will change the order of examples as you suggested.
Apart from the first example, can we also have a sentence before the missing values one, describing what the example is demonstrating?
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
pandas/core/indexes/base.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
not sure we need to repeat the return
description here - perhaps, describe the mask given the example? e.g. given that the first and third elements are missing, the mask shows [0, 2]
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.
agreed, there is no need to repeat return
sentence. I will add an explanation of what the mask shows.
Thank you @MarcoGorelli for reviewing my PR. |
Some tests in CI failed, I am not sure if it’s related to my changes. Locally (on Linux) test |
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 CI failures are unrelated, and due to #50124
I've just left a couple of minor comments, but overall this looks good
pandas/core/indexes/base.py
Outdated
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.
Just suggesting a slight rewording
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. | |
It demonstrates that there's no match between the index and the ``target`` | |
values at these positions. The mask [0, 1, 2] in the return value shows that | |
the first, second, and third elements are missing. |
pandas/core/indexes/base.py
Outdated
Notice that the return value is a tuple contains two items. In the example | ||
above the first item is an array of locations in ``index``. The second | ||
item is a mask shows that the first 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.
shouldn't this come first?
So, overall, I'd suggest:
- the example with
>>> index.get_indexer_non_unique(['f', 'b', 's'])
... - this text "Notice that the return value is a tuple", then the example with
>>> index.get_indexer_non_unique(['f', 'b', 's'])
- The text "In the example below there are no matched values."and then the example with
['q', 'r', 't']
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.
Thank you, MarcoGorelli, for your suggestions. I updated my PR accordingly.
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.
thanks @natmokval !
Updated docstring for
Index.get_indexer_non_unique
. Added examples to clarifyIndex.get_indexer_non_unique
behavior.