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 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
48 changes: 27 additions & 21 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7778,9 +7778,7 @@ 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 where the condition is %(cond_rev)s.

Parameters
----------
Expand All @@ -7805,24 +7803,28 @@ 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 `errors`.

Returns
-------
wh : same type as caller
Expand All @@ -7841,6 +7843,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 @@ -7850,20 +7857,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 @@ -7888,10 +7898,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