Skip to content

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

Merged
merged 8 commits into from
Dec 7, 2018
26 changes: 23 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,15 +2019,35 @@ def __contains__(self, key):
return False

_index_shared_docs['contains'] = """
return a boolean if this key is IN the index
Return a boolean indicating whether 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`,
hence immutable-like and 1-dimensional if it is a tuple.

Returns
-------
boolean
bool
Result indicating whether the key search is in the index.

See Also
--------
Index.isin : Returns an ndarray of boolean dtype indicating whether the
list-like key is in the index.

Examples
--------
>>> idx = pd.Index([1, 2, (3, 4), 5])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer an example with a simple values like pd.Index(list('abcd')). This is a rather esoteric case.

>>> idx
Index([1, 2, (3, 4), 5], dtype='object')
>>> idx.contains(1)
True
>>> idx.contains(6)
False
>>> idx.contains((3, 4))
True
"""

@Appender(_index_shared_docs['contains'] % _index_doc_kwargs)
Expand Down