Skip to content

DOC: Docstring pandas index all any #20168

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 7 commits into from
Mar 13, 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
74 changes: 70 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4290,20 +4290,86 @@ def _add_logical_methods(cls):
""" add in logical methods """

_doc = """

%(desc)s

Parameters
----------
All arguments to numpy.%(outname)s are accepted.
*args
These parameters will be passed to numpy.%(outname)s.
**kwargs
These parameters will be passed to numpy.%(outname)s.

Returns
-------
%(outname)s : bool or array_like (if axis is specified)
A single element array_like may be converted to bool."""

_index_shared_docs['index_all'] = """

See Also
--------
pandas.Index.any : Return whether any element in an Index is True.
pandas.Series.any : Return whether any element in a Series is True.
pandas.Series.all : Return whether all elements in a Series are True.

Notes
-----
Not a Number (NaN), positive infinity and negative infinity
evaluate to True because these are not equal to zero.

Examples
--------
**all**

True, because nonzero integers are considered True.

>>> pd.Index([1, 2, 3]).all()
True

False, because ``0`` is considered False.

>>> pd.Index([0, 1, 2]).all()
False

**any**

True, because ``1`` is considered True.

>>> pd.Index([0, 0, 1]).any()
True

False, because ``0`` is considered False.

>>> pd.Index([0, 0, 0]).any()
False
"""

_index_shared_docs['index_any'] = """

See Also
--------
pandas.Index.all : Return whether all elements are True.
Copy link
Contributor

Choose a reason for hiding this comment

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

pandas.Series.all

pandas.Series.all : Return whether all elements are True.

Notes
-----
Not a Number (NaN), positive infinity and negative infinity
evaluate to True because these are not equal to zero.

Examples
--------
>>> index = pd.Index([0, 1, 2])
>>> index.any()
True

>>> index = pd.Index([0, 0, 0])
>>> index.any()
False
"""

def _make_logical_function(name, desc, f):
@Substitution(outname=name, desc=desc)
@Appender(_index_shared_docs['index_' + name])
@Appender(_doc)
def logical_func(self, *args, **kwargs):
result = f(self.values)
Expand All @@ -4318,10 +4384,10 @@ def logical_func(self, *args, **kwargs):
return logical_func

cls.all = _make_logical_function('all', 'Return whether all elements '
'are True',
'are True.',
np.all)
cls.any = _make_logical_function('any',
'Return whether any element is True',
'Return whether any element is True.',
np.any)

@classmethod
Expand Down