Skip to content

DOC: update the pandas.Series.where docstring #20165

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 3 commits into from
Jul 8, 2018
Merged
Changes from 1 commit
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
50 changes: 29 additions & 21 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6596,9 +6596,10 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
return self._constructor(new_data).__finalize__(self)

_shared_docs['where'] = ("""
Return an object of same shape as self and whose corresponding
entries are from self where `cond` is %(cond)s and otherwise are from
`other`.
Replace values that don't respect a `cond` condition.
Copy link
Member

Choose a reason for hiding this comment

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

"don't respect" is too specific for where I think. Can you make this Replace values where the condition is %(cond)s .


Return an object of same shape as self with entries that
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we should try to avoid using "self", as not necessarily all our users know this concept. You can for example change it to "the calling object"

not satisfy a `cond` is %(cond)s are replaced by `other`.

Parameters
----------
Expand All @@ -6623,23 +6624,26 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
A callable can be used as other.

inplace : boolean, default False
Whether to perform the operation in place on the data
axis : alignment axis if needed, default None
level : alignment level if needed, default None
errors : str, {'raise', 'ignore'}, default 'raise'
- ``raise`` : allow exceptions to be raised
- ``ignore`` : suppress exceptions. On error return original object

Whether to perform the operation in place on the data.
axis : int, default None
Alignment axis if needed.
level : int, default None
Alignment level if needed.
errors : str, {'raise', 'ignore'}, default `raise`
Note that currently this parameter won't affect
the results and will always coerce to a suitable dtype.

- `raise` : allow exceptions to be raised.
- `ignore` : suppress exceptions. On error return original object.

try_cast : boolean, default False
try to cast the result back to the input type (if possible),
Try to cast the result back to the input type (if possible).
raise_on_error : boolean, default True
Whether to raise on invalid data types (e.g. trying to where on
strings)
strings).

.. deprecated:: 0.21.0
Use `error`.
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an extra indentation level to this line? (so sphinx knows it is part of the deprecated directive

and 'error' -> 'errors'


Returns
-------
Expand All @@ -6659,6 +6663,11 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
For further details and examples see the ``%(name)s`` documentation in
:ref:`indexing <indexing.where_mask>`.

See Also
--------
:func:`DataFrame.%(name_other)s` : Return an object of same shape as
self

Examples
--------
>>> s = pd.Series(range(5))
Expand All @@ -6668,20 +6677,23 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
2 2.0
3 3.0
4 4.0
dtype: float64

>>> s.mask(s > 0)
0 0.0
1 NaN
2 NaN
3 NaN
4 NaN
dtype: float64

>>> s.where(s > 1, 10)
0 10.0
1 10.0
2 2.0
3 3.0
4 4.0
0 10
1 10
2 2
3 3
4 4
dtype: int64

>>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B'])
>>> m = df %% 3 == 0
Expand All @@ -6706,10 +6718,6 @@ def _where(self, cond, other=np.nan, inplace=False, axis=None, level=None,
2 True True
3 True True
4 True True

See Also
--------
:func:`DataFrame.%(name_other)s`
""")

@Appender(_shared_docs['where'] % dict(_shared_doc_kwargs, cond="True",
Expand Down