Skip to content

Commit df91bcb

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 df91bcb

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ Other Enhancements
366366
- :meth:`DataFrame.to_stata` and :class:` pandas.io.stata.StataWriter117` can write mixed sting columns to Stata strl format (:issue:`23633`)
367367
- :meth:`DataFrame.between_time` and :meth:`DataFrame.at_time` have gained the an ``axis`` parameter (:issue: `8839`)
368368
- :class:`IntervalIndex` has gained the :attr:`~IntervalIndex.is_overlapping` attribute to indicate if the ``IntervalIndex`` contains any overlapping intervals (:issue:`23309`)
369+
- :meth:`any` and :meth:`all` aggregation methods have corrected/improved docstrings for the ``skipna`` parameter (:issue:`23019`).
369370

370371
.. _whatsnew_0240.api_breaking:
371372

pandas/core/generic.py

+21-7
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,10 +10873,11 @@ 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,
10864-
examples, see_also):
10876+
def _make_logical_function(cls, name, name1, name2, empty_value, axis_descr,
10877+
desc, f, examples, see_also):
1086510878
@Substitution(outname=name, desc=desc, name1=name1, name2=name2,
10866-
axis_descr=axis_descr, examples=examples, see_also=see_also)
10879+
empty_value=empty_value, axis_descr=axis_descr,
10880+
examples=examples, see_also=see_also)
1086710881
@Appender(_bool_doc)
1086810882
def logical_func(self, axis=0, bool_only=None, skipna=True, level=None,
1086910883
**kwargs):

0 commit comments

Comments
 (0)