Skip to content

DOC: update the pandas.DataFrame.any docstring #20217

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 13 commits into from Mar 12, 2018
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ doc/tmp.sv
doc/source/styled.xlsx
doc/source/templates/
env/
doc/source/savefig/
78 changes: 73 additions & 5 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7583,8 +7583,7 @@ def _add_numeric_operations(cls):

cls.any = _make_logical_function(
cls, 'any', name, name2, axis_descr,
'Return whether any element is True over requested axis',
nanops.nanany, '', '')
_any_desc, nanops.nanany, _any_examples, _any_see_also)
cls.all = _make_logical_function(
cls, 'all', name, name2, axis_descr, _all_doc,
nanops.nanall, _all_examples, _all_see_also)
Expand Down Expand Up @@ -7848,7 +7847,8 @@ def _doc_parms(cls):

Parameters
----------
axis : %(axis_descr)s
axis : int, default 0
Select the axis which can be 0 for indices and 1 for columns.
skipna : boolean, default True
Exclude NA/null values. If an entire row/column is NA, the result
will be NA.
Expand All @@ -7866,8 +7866,8 @@ def _doc_parms(cls):
-------
%(outname)s : %(name1)s or %(name2)s (if level specified)

%(examples)s
%(see_also)s"""
%(see_also)s
%(examples)s"""

_all_doc = """\
Return whether all elements are True over series or dataframe axis.
Expand Down Expand Up @@ -7938,6 +7938,74 @@ def _doc_parms(cls):

"""

_any_see_also = """\
See Also
--------
pandas.DataFrame.all : Return whether all elements are True.
"""

_any_desc = """\
Return whether any element is True over requested axis.

Unlike :meth:`DataFrame.all`, this performs an *or* operation. If any of the
values along the specified axis is True, this will return True."""

_any_examples = """\
Examples
--------
**Series**

For Series input, the output is a scalar indicating whether any element
is True.

>>> pd.Series([True, False]).any()
True

**DataFrame**

Whether each column contains at least one True element (the default).

>>> df = pd.DataFrame({"A": [1, 2], "B": [0, 2], "C": [0, 0]})
>>> df
A B C
0 1 0 0
1 2 2 0

>>> df.any()
A True
B True
C False
dtype: bool

Aggregating over the columns.

>>> df = pd.DataFrame({"A": [True, False], "B": [1, 2]})
>>> df
A B
0 True 1
1 False 2

>>> df.any(axis='columns')
0 True
1 True
dtype: bool

>>> df = pd.DataFrame({"A": [True, False], "B": [1, 0]})
>>> df
A B
0 True 1
1 False 0

>>> df.any(axis='columns')
0 True
1 False
dtype: bool

`any` for an empty DataFrame is an empty Series.

>>> pd.DataFrame([]).any()
Series([], dtype: bool)
"""

_sum_examples = """\
Examples
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,8 @@ def result_to_bool(result):
@Substitution(name='groupby')
@Appender(_doc_template)
def any(self, skipna=True):
"""Returns True if any value in the group is truthful, else False
"""
Returns True if any value in the group is truthful, else False

Parameters
----------
Expand Down