Skip to content

Commit f95cef4

Browse files
committed
DOC: Correct/update skipna docstrings for any and all (pandas-dev#23109)
Also include examples with NA values and clarify treatment of NA with `skipna == False`
1 parent f06b969 commit f95cef4

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

pandas/core/generic.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -9862,10 +9862,10 @@ def _add_numeric_operations(cls):
98629862
axis_descr, name, name2 = _doc_parms(cls)
98639863

98649864
cls.any = _make_logical_function(
9865-
cls, 'any', name, name2, axis_descr,
9865+
cls, 'any', name, name2, False, axis_descr,
98669866
_any_desc, nanops.nanany, _any_examples, _any_see_also)
98679867
cls.all = _make_logical_function(
9868-
cls, 'all', name, name2, axis_descr, _all_doc,
9868+
cls, 'all', name, name2, True, axis_descr, _all_doc,
98699869
nanops.nanall, _all_examples, _all_see_also)
98709870

98719871
@Substitution(outname='mad',
@@ -10188,8 +10188,10 @@ def _doc_parms(cls):
1018810188
Include only boolean columns. If None, will attempt to use everything,
1018910189
then use only boolean data. Not implemented for Series.
1019010190
skipna : boolean, default True
10191-
Exclude NA/null values. If an entire row/column is NA, the result
10192-
will be NA.
10191+
Exclude NA/null values. If the entire row/column is NA and skipna is
10192+
True, then the result will be %(empty_value)s, as for an empty row/column.
10193+
If skipna is False, then NA are treated as True, because these are not
10194+
equal to zero.
1019310195
level : int or level name, default None
1019410196
If the axis is a MultiIndex (hierarchical), count along a
1019510197
particular level, collapsing into a %(name1)s.
@@ -10219,6 +10221,10 @@ def _doc_parms(cls):
1021910221
True
1022010222
>>> pd.Series([True, False]).all()
1022110223
False
10224+
>>> pd.Series([]).all()
10225+
True
10226+
>>> pd.Series([np.nan]).all()
10227+
True
1022210228
1022310229
DataFrames
1022410230
@@ -10576,6 +10582,13 @@ def _doc_parms(cls):
1057610582
1057710583
>>> pd.Series([True, False]).any()
1057810584
True
10585+
>>> pd.Series([]).any()
10586+
False
10587+
>>> pd.Series([np.nan]).any()
10588+
False
10589+
>>> pd.Series([np.nan]).any(skipna=False)
10590+
True
10591+
1057910592
1058010593
**DataFrame**
1058110594
@@ -10860,9 +10873,9 @@ def cum_func(self, axis=None, skipna=True, *args, **kwargs):
1086010873
return set_function_name(cum_func, name, cls)
1086110874

1086210875

10863-
def _make_logical_function(cls, name, name1, name2, axis_descr, desc, f,
10876+
def _make_logical_function(cls, name, name1, name2, empty_value, axis_descr, desc, f,
1086410877
examples, see_also):
10865-
@Substitution(outname=name, desc=desc, name1=name1, name2=name2,
10878+
@Substitution(outname=name, desc=desc, name1=name1, name2=name2, empty_value=empty_value,
1086610879
axis_descr=axis_descr, examples=examples, see_also=see_also)
1086710880
@Appender(_bool_doc)
1086810881
def logical_func(self, axis=0, bool_only=None, skipna=True, level=None,

0 commit comments

Comments
 (0)