-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update the pd.Index.contains docstring #20211
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
Conversation
return a boolean if this key is IN the index | ||
Return a boolean if key is in the index. | ||
|
||
This function returns True if key is in the index and |
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.
I think this extended summary can be removed.
|
||
Parameters | ||
---------- | ||
key : object | ||
key : immutable object |
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 remove immutable
, it could be anything.
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't be anything:
pd.CategoricalIndex([2000, 2001, 2012]).contains([1,2])
TypeError: unhashable type: 'list'
|
||
Notes | ||
----- | ||
CategoricalIndex is a sub-class of 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.
Don't think you need this Notes section.
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.
Could you add a See Also with Index.isin
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.
this note is because of shared documentation between Index and CategoricalIndex
|
||
Examples | ||
-------- | ||
>>> pd.CategoricalIndex([2000, 2001, 2012]).contains(2001) |
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.
Best to just use a regular Index here, not a CategoricalIndex.
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.
pd.Index.contains and pd.CategoricalIndex.contains have shared documentation
and a CategoricalIndex example is valid for Index but not the other way around since CategoricalIndex is a sub-class of 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.
yeah for this particular case I would separate the doc-strings, IOW 1 more Index and a separate one for CategoricalIndex. Can use a shared doc if that works (with templates)
|
||
Examples | ||
-------- | ||
>>> pd.CategoricalIndex([2000, 2001, 2012]).contains(2001) |
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 for this particular case I would separate the doc-strings, IOW 1 more Index and a separate one for CategoricalIndex. Can use a shared doc if that works (with templates)
@dajcs do you have time to update the PR based on the feedback? |
I am working to update this PR in accordance with the reviews made to it and match it to the Pandas docstring standards. |
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks:
If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.
See Also missing because we haven't found similar functions
Checklist for other PRs (remove this part if you are doing a PR for the pandas documentation sprint):
git diff upstream/master -u -- "*.py" | flake8 --diff