-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: Improve the docstring of pd.Index.contains and closes PR #20211 #23100
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 3 commits
05fe477
f0f875d
e176a5d
a65f51d
c54ac4f
b9ba90a
dedb267
93dcd9d
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 |
---|---|---|
|
@@ -2005,15 +2005,35 @@ def __contains__(self, key): | |
return False | ||
|
||
_index_shared_docs['contains'] = """ | ||
return a boolean if this key is IN the index | ||
Return a boolean if this key is in the index. | ||
|
||
Parameters | ||
---------- | ||
key : object | ||
key : label | ||
The key can be of the same type as the label of :class: `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. I think the space after 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. Thanks, it renders correctly after removing the space after |
||
hence immutable-like and 1-dimensional if it is a tuple. | ||
|
||
Returns | ||
------- | ||
boolean | ||
bool | ||
Result of the key search. | ||
|
||
See Also | ||
-------- | ||
Index.isin : Returns ndarray of boolean dtype if list-like key is in | ||
index. | ||
|
||
Examples | ||
-------- | ||
>>> idx = pd.Index([1, 2, (3, 4), 5]) | ||
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. I would prefer an example with a simple values like |
||
>>> idx | ||
Index([1, 2, (3, 4), 5], dtype='object') | ||
>>> idx.contains((3,4)) | ||
True | ||
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. Small thing, but do you mind moving this example after the other two? I think it helps if we show the simple/easy cases first, and the more complex later. Also, you there is a missing space after the comma. When you're done with the changes, it may be helpful to run And also 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. I have made the said changes. Validation tests passed with a warning of absence of an extended description which has been suggested to avoid in the review of the original PR. Tested via command No doctests problem were reported for lines 2008-2036 by testing via command |
||
>>> idx.contains(1) | ||
True | ||
>>> idx.contains(6) | ||
False | ||
""" | ||
|
||
@Appender(_index_shared_docs['contains'] % _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.
Minor thing, and I know this is the original description and not yours, but this sounds like it a boolean is returned only if the key is in the index. Not that a boolean is always returned, on whether the key is in the index. Do you mind rephrasing it to be more correct please?
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.
Sure, I'll rephrase it in the next commit as a boolean indicator. Apparently, there are few more docstrings with similar phrasing like
Series.is_unique
,Series.is_monotonic
,Series.is_monotonic_increasing
,Series.is_monotonic_decreasing
. These too can be corrected in future if seems appropriate.