From afa6c42da9e19a3f8927df2793ccac44776d7ba6 Mon Sep 17 00:00:00 2001 From: Marc Date: Sun, 11 Mar 2018 10:42:35 -0400 Subject: [PATCH] DOC: update the pandas.DataFrame.all docstring (#20216) --- pandas/core/generic.py | 73 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d9bc4804b061b..fc8aaa23d2f79 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7584,11 +7584,10 @@ 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) + nanops.nanany, '', '') cls.all = _make_logical_function( - cls, 'all', name, name2, axis_descr, - 'Return whether all elements are True over requested axis', - nanops.nanall) + cls, 'all', name, name2, axis_descr, _all_doc, + nanops.nanall, _all_examples, _all_see_also) @Substitution(outname='mad', desc="Return the mean absolute deviation of the values " @@ -7845,7 +7844,6 @@ def _doc_parms(cls): %(outname)s : %(name1)s or %(name2)s (if level specified)\n""" _bool_doc = """ - %(desc)s Parameters @@ -7853,17 +7851,71 @@ def _doc_parms(cls): axis : %(axis_descr)s skipna : boolean, default True Exclude NA/null values. If an entire row/column is NA, the result - will be NA + will be NA. level : int or level name, default None If the axis is a MultiIndex (hierarchical), count along a - particular level, collapsing into a %(name1)s + particular level, collapsing into a %(name1)s. bool_only : boolean, default None Include only boolean columns. If None, will attempt to use everything, then use only boolean data. Not implemented for Series. +**kwargs : any, default None + Additional keywords have no affect but might be accepted for + compatibility with numpy. Returns ------- -%(outname)s : %(name1)s or %(name2)s (if level specified)\n""" +%(outname)s : %(name1)s or %(name2)s (if level specified) + +%(examples)s +%(see_also)s""" + +_all_doc = """\ +Return whether all elements are True over series or dataframe axis. + +Returns True if all elements within a series or along a dataframe +axis are non-zero, not-empty or not-False.""" + +_all_examples = """\ +Examples +-------- +Series + +>>> pd.Series([True, True]).all() +True +>>> pd.Series([True, False]).all() +False + +Dataframes + +Create a dataframe from a dictionary. + +>>> df = pd.DataFrame({'col1': [True, True], 'col2': [True, False]}) +>>> df + col1 col2 +0 True True +1 True False + +Default behaviour checks if column-wise values all return True. + +>>> df.all() +col1 True +col2 False +dtype: bool + +Adding axis=1 argument will check if row-wise values all return True. + +>>> df.all(axis=1) +0 True +1 False +dtype: bool +""" + +_all_see_also = """\ +See also +-------- +pandas.Series.all : Return True if all elements are True +pandas.DataFrame.any : Return True if one (or more) elements are True +""" _cnum_doc = """ @@ -8046,9 +8098,10 @@ def cum_func(self, axis=None, skipna=True, *args, **kwargs): return set_function_name(cum_func, name, cls) -def _make_logical_function(cls, name, name1, name2, axis_descr, desc, f): +def _make_logical_function(cls, name, name1, name2, axis_descr, desc, f, + examples, see_also): @Substitution(outname=name, desc=desc, name1=name1, name2=name2, - axis_descr=axis_descr) + axis_descr=axis_descr, examples=examples, see_also=see_also) @Appender(_bool_doc) def logical_func(self, axis=None, bool_only=None, skipna=None, level=None, **kwargs):