Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

dajcs
Copy link
Contributor

@dajcs dajcs commented Mar 10, 2018

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • PR title is "DOC: update the docstring"
  • The validation script passes: scripts/validate_docstrings.py <your-function-or-method>
  • The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • The html version looks good: python doc/make.py --single <your-function-or-method>
  • It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:


################################################################################
###################### Docstring (pandas.Index.contains)  ######################
################################################################################

Return a boolean if key is in the index.

This function returns True if key is in the index and
returns False if key is not in index.

Parameters
----------
key : immutable object
    Key to be searched.

Returns
-------
bool
    Result of the key search.

Notes
-----
    CategoricalIndex is a sub-class of Index.

Examples
--------
>>> pd.CategoricalIndex([2000, 2001, 2012]).contains(2001)
True
>>> pd.CategoricalIndex([2000, 2001, 2012]).contains(2222)
False

################################################################################
################################## Validation ##################################
################################################################################

Errors found:
        See Also section not found

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):

  • closes #xxxx
  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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)
Copy link
Contributor

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)

@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Mar 10, 2018
@jorisvandenbossche
Copy link
Member

@dajcs do you have time to update the PR based on the feedback?

@datapythonista datapythonista self-assigned this Aug 22, 2018
@TanyaaCJain
Copy link
Contributor

I am working to update this PR in accordance with the reviews made to it and match it to the Pandas docstring standards.

@datapythonista
Copy link
Member

datapythonista commented Oct 12, 2018

Superseded by #23100 and #23107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants