From 2bb43b857b488eba1658ee77bdb6d999f4856142 Mon Sep 17 00:00:00 2001 From: Antonio Linde Date: Sat, 10 Mar 2018 12:20:04 +0100 Subject: [PATCH 1/6] DOC: Improved the docstring of pandasIndex.all and pandasIndex.any. --- pandas/core/indexes/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 7e6ae88a26e7c..0bc388434a0a6 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4274,10 +4274,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 From 70695c28533784a9a17879afe61da4f58f0c5d7a Mon Sep 17 00:00:00 2001 From: Antonio Linde Date: Sat, 10 Mar 2018 15:51:30 +0100 Subject: [PATCH 2/6] DOC: Improved docstring of pandas.Index.all and pandas.Index.any --- pandas/core/indexes/base.py | 53 ++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 0bc388434a0a6..ff72c4d02aff3 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1156,7 +1156,7 @@ def to_frame(self, index=True): >>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') >>> idx.to_frame() animal - animal + animal Ant Ant Bear Bear Cow Cow @@ -4246,20 +4246,67 @@ 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 is 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([1,2,3]) + >>> index.all() + True + + >>> index = pd.Index([0,1,2]) + >>> index.all() + False + """ + + _index_shared_docs['index_any'] = """ + + See Also + -------- + pandas.Index.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) From 0adc9d3e683c000138f0da898f5865809c10a49f Mon Sep 17 00:00:00 2001 From: Antonio Linde Date: Sat, 10 Mar 2018 15:55:08 +0100 Subject: [PATCH 3/6] DOC: Improved docstring --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ff72c4d02aff3..12a57847ad122 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4306,7 +4306,7 @@ def _add_logical_methods(cls): def _make_logical_function(name, desc, f): @Substitution(outname=name, desc=desc) - @Appender(_index_shared_docs['index_'+name]) + @Appender(_index_shared_docs['index_' + name]) @Appender(_doc) def logical_func(self, *args, **kwargs): result = f(self.values) From 6eefa7bcef42f0205ebb70ecaf702d57c235f639 Mon Sep 17 00:00:00 2001 From: Antonio Linde Date: Sat, 10 Mar 2018 17:15:29 +0100 Subject: [PATCH 4/6] Added space after commas --- pandas/core/indexes/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 12a57847ad122..c2f0e8729af11 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4273,11 +4273,11 @@ def _add_logical_methods(cls): Examples -------- - >>> index = pd.Index([1,2,3]) + >>> index = pd.Index([1, 2, 3]) >>> index.all() True - >>> index = pd.Index([0,1,2]) + >>> index = pd.Index([0, 1, 2]) >>> index.all() False """ @@ -4295,11 +4295,11 @@ def _add_logical_methods(cls): Examples -------- - >>> index = pd.Index([0,1,2]) + >>> index = pd.Index([0, 1, 2]) >>> index.any() True - >>> index = pd.Index([0,0,0]) + >>> index = pd.Index([0, 0, 0]) >>> index.any() False """ From 231fdccb2aa7664884d3cd03eb9433ef4dd6c2e5 Mon Sep 17 00:00:00 2001 From: Antonio Linde Date: Sat, 10 Mar 2018 18:26:39 +0100 Subject: [PATCH 5/6] Added requested changes. --- pandas/core/indexes/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index f06e0f1d6a61d..1e704d64ddd0f 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4309,6 +4309,7 @@ def _add_logical_methods(cls): See Also -------- pandas.Index.any : Return whether any element is True. + pandas.Series.any : Return whether any element is True. Notes ----- @@ -4331,6 +4332,7 @@ def _add_logical_methods(cls): See Also -------- pandas.Index.all : Return whether all elements are True. + pandas.Series.all : Return whether all elements are True. Notes ----- From 23c2c3d7c4ff3dce7e62c83f65113c6890b319ca Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 13 Mar 2018 15:55:37 -0500 Subject: [PATCH 6/6] Fixup [ci skip] [ci skip] --- pandas/core/indexes/base.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 1e704d64ddd0f..f4066095ebd1e 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -4308,8 +4308,9 @@ def _add_logical_methods(cls): See Also -------- - pandas.Index.any : Return whether any element is True. - pandas.Series.any : Return whether any element is True. + 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 ----- @@ -4318,12 +4319,28 @@ def _add_logical_methods(cls): Examples -------- - >>> index = pd.Index([1, 2, 3]) - >>> index.all() + **all** + + True, because nonzero integers are considered True. + + >>> pd.Index([1, 2, 3]).all() True - >>> index = pd.Index([0, 1, 2]) - >>> index.all() + 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 """