Skip to content

Commit 90d4c57

Browse files
alinde1TomAugspurger
authored andcommitted
DOC: Docstring pandas index all any (#20168)
1 parent 74bf0d0 commit 90d4c57

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed

pandas/core/indexes/base.py

+70-4
Original file line numberDiff line numberDiff line change
@@ -4550,20 +4550,86 @@ def _add_logical_methods(cls):
45504550
""" add in logical methods """
45514551

45524552
_doc = """
4553-
45544553
%(desc)s
45554554
45564555
Parameters
45574556
----------
4558-
All arguments to numpy.%(outname)s are accepted.
4557+
*args
4558+
These parameters will be passed to numpy.%(outname)s.
4559+
**kwargs
4560+
These parameters will be passed to numpy.%(outname)s.
45594561
45604562
Returns
45614563
-------
45624564
%(outname)s : bool or array_like (if axis is specified)
45634565
A single element array_like may be converted to bool."""
45644566

4567+
_index_shared_docs['index_all'] = """
4568+
4569+
See Also
4570+
--------
4571+
pandas.Index.any : Return whether any element in an Index is True.
4572+
pandas.Series.any : Return whether any element in a Series is True.
4573+
pandas.Series.all : Return whether all elements in a Series are True.
4574+
4575+
Notes
4576+
-----
4577+
Not a Number (NaN), positive infinity and negative infinity
4578+
evaluate to True because these are not equal to zero.
4579+
4580+
Examples
4581+
--------
4582+
**all**
4583+
4584+
True, because nonzero integers are considered True.
4585+
4586+
>>> pd.Index([1, 2, 3]).all()
4587+
True
4588+
4589+
False, because ``0`` is considered False.
4590+
4591+
>>> pd.Index([0, 1, 2]).all()
4592+
False
4593+
4594+
**any**
4595+
4596+
True, because ``1`` is considered True.
4597+
4598+
>>> pd.Index([0, 0, 1]).any()
4599+
True
4600+
4601+
False, because ``0`` is considered False.
4602+
4603+
>>> pd.Index([0, 0, 0]).any()
4604+
False
4605+
"""
4606+
4607+
_index_shared_docs['index_any'] = """
4608+
4609+
See Also
4610+
--------
4611+
pandas.Index.all : Return whether all elements are True.
4612+
pandas.Series.all : Return whether all elements are True.
4613+
4614+
Notes
4615+
-----
4616+
Not a Number (NaN), positive infinity and negative infinity
4617+
evaluate to True because these are not equal to zero.
4618+
4619+
Examples
4620+
--------
4621+
>>> index = pd.Index([0, 1, 2])
4622+
>>> index.any()
4623+
True
4624+
4625+
>>> index = pd.Index([0, 0, 0])
4626+
>>> index.any()
4627+
False
4628+
"""
4629+
45654630
def _make_logical_function(name, desc, f):
45664631
@Substitution(outname=name, desc=desc)
4632+
@Appender(_index_shared_docs['index_' + name])
45674633
@Appender(_doc)
45684634
def logical_func(self, *args, **kwargs):
45694635
result = f(self.values)
@@ -4578,10 +4644,10 @@ def logical_func(self, *args, **kwargs):
45784644
return logical_func
45794645

45804646
cls.all = _make_logical_function('all', 'Return whether all elements '
4581-
'are True',
4647+
'are True.',
45824648
np.all)
45834649
cls.any = _make_logical_function('any',
4584-
'Return whether any element is True',
4650+
'Return whether any element is True.',
45854651
np.any)
45864652

45874653
@classmethod

0 commit comments

Comments
 (0)