Skip to content

Commit 78a5b25

Browse files
committed
revert to Appender in dynamically generated functions
1 parent 7d433c0 commit 78a5b25

File tree

1 file changed

+93
-97
lines changed

1 file changed

+93
-97
lines changed

pandas/core/generic.py

+93-97
Original file line numberDiff line numberDiff line change
@@ -10515,6 +10515,60 @@ def _doc_parms(cls):
1051510515
%(examples)s
1051610516
"""
1051710517

10518+
_num_ddof_doc = """
10519+
%(desc)s
10520+
Parameters
10521+
----------
10522+
axis : %(axis_descr)s
10523+
skipna : bool, default True
10524+
Exclude NA/null values. If an entire row/column is NA, the result
10525+
will be NA.
10526+
level : int or level name, default None
10527+
If the axis is a MultiIndex (hierarchical), count along a
10528+
particular level, collapsing into a %(name1)s.
10529+
ddof : int, default 1
10530+
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
10531+
where N represents the number of elements.
10532+
numeric_only : bool, default None
10533+
Include only float, int, boolean columns. If None, will attempt to use
10534+
everything, then use only numeric data. Not implemented for Series.
10535+
Returns
10536+
-------
10537+
%(name1)s or %(name2)s (if level specified)\n"""
10538+
10539+
_bool_doc = """
10540+
%(desc)s
10541+
Parameters
10542+
----------
10543+
axis : {0 or 'index', 1 or 'columns', None}, default 0
10544+
Indicate which axis or axes should be reduced.
10545+
* 0 / 'index' : reduce the index, return a Series whose index is the
10546+
original column labels.
10547+
* 1 / 'columns' : reduce the columns, return a Series whose index is the
10548+
original index.
10549+
* None : reduce all axes, return a scalar.
10550+
bool_only : bool, default None
10551+
Include only boolean columns. If None, will attempt to use everything,
10552+
then use only boolean data. Not implemented for Series.
10553+
skipna : bool, default True
10554+
Exclude NA/null values. If the entire row/column is NA and skipna is
10555+
True, then the result will be %(empty_value)s, as for an empty row/column.
10556+
If skipna is False, then NA are treated as True, because these are not
10557+
equal to zero.
10558+
level : int or level name, default None
10559+
If the axis is a MultiIndex (hierarchical), count along a
10560+
particular level, collapsing into a %(name1)s.
10561+
**kwargs : any, default None
10562+
Additional keywords have no effect but might be accepted for
10563+
compatibility with NumPy.
10564+
Returns
10565+
-------
10566+
%(name1)s or %(name2)s
10567+
If level is specified, then, %(name2)s is returned; otherwise, %(name1)s
10568+
is returned.
10569+
%(see_also)s
10570+
%(examples)s"""
10571+
1051810572
_all_desc = """\
1051910573
Return whether all elements are True, potentially over an axis.
1052010574
@@ -10575,6 +10629,36 @@ def _doc_parms(cls):
1057510629
DataFrame.any : Return True if one (or more) elements are True.
1057610630
"""
1057710631

10632+
_cnum_doc = """
10633+
Return cumulative %(desc)s over a DataFrame or Series axis.
10634+
Returns a DataFrame or Series of the same size containing the cumulative
10635+
%(desc)s.
10636+
Parameters
10637+
----------
10638+
axis : {0 or 'index', 1 or 'columns'}, default 0
10639+
The index or the name of the axis. 0 is equivalent to None or 'index'.
10640+
skipna : bool, default True
10641+
Exclude NA/null values. If an entire row/column is NA, the result
10642+
will be NA.
10643+
*args, **kwargs
10644+
Additional keywords have no effect but might be accepted for
10645+
compatibility with NumPy.
10646+
Returns
10647+
-------
10648+
%(name1)s or %(name2)s
10649+
Return cumulative %(desc)s of %(name1)s or %(name2)s.
10650+
See Also
10651+
--------
10652+
core.window.Expanding.%(accum_func_name)s : Similar functionality
10653+
but ignores ``NaN`` values.
10654+
%(name2)s.%(accum_func_name)s : Return the %(desc)s over
10655+
%(name2)s axis.
10656+
%(name2)s.cummax : Return cumulative maximum over %(name2)s axis.
10657+
%(name2)s.cummin : Return cumulative minimum over %(name2)s axis.
10658+
%(name2)s.cumsum : Return cumulative sum over %(name2)s axis.
10659+
%(name2)s.cumprod : Return cumulative product over %(name2)s axis.
10660+
%(examples)s"""
10661+
1057810662
_cummin_examples = """\
1057910663
Examples
1058010664
--------
@@ -11143,32 +11227,11 @@ def stat_func(
1114311227
def _make_stat_function_ddof(
1114411228
cls, name: str, name1: str, name2: str, axis_descr: str, desc: str, func: Callable
1114511229
) -> Callable:
11146-
@doc(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11230+
@Substitution(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11231+
@Appender(_num_ddof_doc)
1114711232
def stat_func(
1114811233
self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs
1114911234
):
11150-
"""
11151-
{desc}
11152-
11153-
Parameters
11154-
----------
11155-
axis : {axis_descr}
11156-
skipna : bool, default True
11157-
Exclude NA/null values. If an entire row/column is NA, the result
11158-
will be NA.
11159-
level : int or level name, default None
11160-
If the axis is a MultiIndex (hierarchical), count along a
11161-
particular level, collapsing into a %(name1)s.
11162-
ddof : int, default 1
11163-
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
11164-
where N represents the number of elements.
11165-
numeric_only : bool, default None
11166-
Include only float, int, boolean columns. If None, will attempt to use
11167-
everything, then use only numeric data. Not implemented for Series.
11168-
11169-
Returns
11170-
-------
11171-
{name1} or {name2} (if level specified)\n"""
1117211235
nv.validate_stat_ddof_func(tuple(), kwargs, fname=name)
1117311236
if skipna is None:
1117411237
skipna = True
@@ -11196,48 +11259,16 @@ def _make_cum_function(
1119611259
accum_func_name: str,
1119711260
examples: str,
1119811261
) -> Callable:
11199-
@doc(
11262+
@Substitution(
1120011263
desc=desc,
1120111264
name1=name1,
1120211265
name2=name2,
11266+
axis_descr=axis_descr,
1120311267
accum_func_name=accum_func_name,
1120411268
examples=examples,
1120511269
)
11270+
@Appender(_cnum_doc)
1120611271
def cum_func(self, axis=None, skipna=True, *args, **kwargs):
11207-
"""
11208-
Return cumulative {desc} over a DataFrame or Series axis.
11209-
11210-
Returns a DataFrame or Series of the same size containing the cumulative
11211-
{desc}.
11212-
11213-
Parameters
11214-
----------
11215-
axis : {{0 or 'index', 1 or 'columns'}}, default 0
11216-
The index or the name of the axis. 0 is equivalent to None or 'index'.
11217-
skipna : bool, default True
11218-
Exclude NA/null values. If an entire row/column is NA, the result
11219-
will be NA.
11220-
*args, **kwargs
11221-
Additional keywords have no effect but might be accepted for
11222-
compatibility with NumPy.
11223-
11224-
Returns
11225-
-------
11226-
{name1} or {name2}
11227-
Return cumulative {desc} of {name1} or {name2}.
11228-
11229-
See Also
11230-
--------
11231-
core.window.Expanding.{accum_func_name} : Similar functionality
11232-
but ignores ``NaN`` values.
11233-
{name2}.{accum_func_name} : Return the {desc} over
11234-
{name2} axis.
11235-
{name2}.cummax : Return cumulative maximum over {name2} axis.
11236-
{name2}.cummin : Return cumulative minimum over {name2} axis.
11237-
{name2}.cumsum : Return cumulative sum over {name2} axis.
11238-
{name2}.cumprod : Return cumulative product over {name2} axis.
11239-
11240-
{examples}"""
1124111272
skipna = nv.validate_cum_func_with_skipna(skipna, args, kwargs, name)
1124211273
if axis is None:
1124311274
axis = self._stat_axis_number
@@ -11274,52 +11305,17 @@ def _make_logical_function(
1127411305
examples: str,
1127511306
empty_value: bool,
1127611307
) -> Callable:
11277-
@doc(
11308+
@Substitution(
1127811309
desc=desc,
1127911310
name1=name1,
1128011311
name2=name2,
11312+
axis_descr=axis_descr,
1128111313
see_also=see_also,
1128211314
examples=examples,
11283-
empty_value=str(empty_value),
11315+
empty_value=empty_value,
1128411316
)
11317+
@Appender(_bool_doc)
1128511318
def logical_func(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs):
11286-
"""
11287-
{desc}
11288-
11289-
Parameters
11290-
----------
11291-
axis : {{0 or 'index', 1 or 'columns', None}}, default 0
11292-
Indicate which axis or axes should be reduced.
11293-
11294-
* 0 / 'index' : reduce the index, return a Series whose index is the
11295-
original column labels.
11296-
* 1 / 'columns' : reduce the columns, return a Series whose index is the
11297-
original index.
11298-
* None : reduce all axes, return a scalar.
11299-
11300-
bool_only : bool, default None
11301-
Include only boolean columns. If None, will attempt to use everything,
11302-
then use only boolean data. Not implemented for Series.
11303-
skipna : bool, default True
11304-
Exclude NA/null values. If the entire row/column is NA and skipna is
11305-
True, then the result will be {empty_value}, as for an empty row/column.
11306-
If skipna is False, then NA are treated as True, because these are not
11307-
equal to zero.
11308-
level : int or level name, default None
11309-
If the axis is a MultiIndex (hierarchical), count along a
11310-
particular level, collapsing into a {name1}.
11311-
**kwargs : any, default None
11312-
Additional keywords have no effect but might be accepted for
11313-
compatibility with NumPy.
11314-
11315-
Returns
11316-
-------
11317-
{name1} or {name2}
11318-
If level is specified, then, {name2} is returned; otherwise, {name1}
11319-
is returned.
11320-
11321-
{see_also}
11322-
{examples}"""
1132311319
nv.validate_logical_func(tuple(), kwargs, fname=name)
1132411320
if level is not None:
1132511321
if bool_only is not None:

0 commit comments

Comments
 (0)