Skip to content

DOC: Improve documentation for Index.where #32009

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 6 commits into from
Feb 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3936,18 +3936,35 @@ def memory_usage(self, deep: bool = False) -> int:

def where(self, cond, other=None):
"""
Return an Index of same shape as self and whose corresponding
entries are from self where cond is True and otherwise are from
other.
Replace values where the condition is False.

The replacement is taken from other.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this whole description is very clear. May be you can simply mention in the short summary this is a conditional. And explain what exactly does in the extended summary.

Copy link
Contributor Author

@laymonage laymonage Feb 23, 2020

Choose a reason for hiding this comment

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

Okay, I've copied the short summary from Series.where and DataFrame.where.


Parameters
----------
cond : bool array-like with the same length as self
other : scalar, or array-like
Condition to select the values on.
other : scalar, or array-like, default None
Replacement if the condition is False.

Returns
-------
Index
pandas.Index
A copy of self with values replaced from other
where the condition is False.

See Also
--------
Series.where : Same method for Series.
DataFrame.where : Same method for DataFrame.

Examples
--------
>>> idx = pd.Index(['car', 'bike', 'train', 'tractor'])
>>> idx
Index(['car', 'bike', 'train', 'tractor'], dtype='object')
>>> idx.where(idx.isin(['car', 'train']), 'other')
Index(['car', 'other', 'train', 'other'], dtype='object')
"""
if other is None:
other = self._na_value
Expand Down