Skip to content

Commit b1dd67c

Browse files
committed
revert to Appender in dynamically generated functions
1 parent 9588082 commit b1dd67c

File tree

1 file changed

+93
-97
lines changed

1 file changed

+93
-97
lines changed

pandas/core/generic.py

Lines changed: 93 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -10512,6 +10512,60 @@ def _doc_parms(cls):
1051210512
%(examples)s
1051310513
"""
1051410514

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

10629+
_cnum_doc = """
10630+
Return cumulative %(desc)s over a DataFrame or Series axis.
10631+
Returns a DataFrame or Series of the same size containing the cumulative
10632+
%(desc)s.
10633+
Parameters
10634+
----------
10635+
axis : {0 or 'index', 1 or 'columns'}, default 0
10636+
The index or the name of the axis. 0 is equivalent to None or 'index'.
10637+
skipna : bool, default True
10638+
Exclude NA/null values. If an entire row/column is NA, the result
10639+
will be NA.
10640+
*args, **kwargs
10641+
Additional keywords have no effect but might be accepted for
10642+
compatibility with NumPy.
10643+
Returns
10644+
-------
10645+
%(name1)s or %(name2)s
10646+
Return cumulative %(desc)s of %(name1)s or %(name2)s.
10647+
See Also
10648+
--------
10649+
core.window.Expanding.%(accum_func_name)s : Similar functionality
10650+
but ignores ``NaN`` values.
10651+
%(name2)s.%(accum_func_name)s : Return the %(desc)s over
10652+
%(name2)s axis.
10653+
%(name2)s.cummax : Return cumulative maximum over %(name2)s axis.
10654+
%(name2)s.cummin : Return cumulative minimum over %(name2)s axis.
10655+
%(name2)s.cumsum : Return cumulative sum over %(name2)s axis.
10656+
%(name2)s.cumprod : Return cumulative product over %(name2)s axis.
10657+
%(examples)s"""
10658+
1057510659
_cummin_examples = """\
1057610660
Examples
1057710661
--------
@@ -11140,32 +11224,11 @@ def stat_func(
1114011224
def _make_stat_function_ddof(
1114111225
cls, name: str, name1: str, name2: str, axis_descr: str, desc: str, func: Callable
1114211226
) -> Callable:
11143-
@doc(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11227+
@Substitution(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11228+
@Appender(_num_ddof_doc)
1114411229
def stat_func(
1114511230
self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs
1114611231
):
11147-
"""
11148-
{desc}
11149-
11150-
Parameters
11151-
----------
11152-
axis : {axis_descr}
11153-
skipna : bool, default True
11154-
Exclude NA/null values. If an entire row/column is NA, the result
11155-
will be NA.
11156-
level : int or level name, default None
11157-
If the axis is a MultiIndex (hierarchical), count along a
11158-
particular level, collapsing into a %(name1)s.
11159-
ddof : int, default 1
11160-
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
11161-
where N represents the number of elements.
11162-
numeric_only : bool, default None
11163-
Include only float, int, boolean columns. If None, will attempt to use
11164-
everything, then use only numeric data. Not implemented for Series.
11165-
11166-
Returns
11167-
-------
11168-
{name1} or {name2} (if level specified)\n"""
1116911232
nv.validate_stat_ddof_func(tuple(), kwargs, fname=name)
1117011233
if skipna is None:
1117111234
skipna = True
@@ -11193,48 +11256,16 @@ def _make_cum_function(
1119311256
accum_func_name: str,
1119411257
examples: str,
1119511258
) -> Callable:
11196-
@doc(
11259+
@Substitution(
1119711260
desc=desc,
1119811261
name1=name1,
1119911262
name2=name2,
11263+
axis_descr=axis_descr,
1120011264
accum_func_name=accum_func_name,
1120111265
examples=examples,
1120211266
)
11267+
@Appender(_cnum_doc)
1120311268
def cum_func(self, axis=None, skipna=True, *args, **kwargs):
11204-
"""
11205-
Return cumulative {desc} over a DataFrame or Series axis.
11206-
11207-
Returns a DataFrame or Series of the same size containing the cumulative
11208-
{desc}.
11209-
11210-
Parameters
11211-
----------
11212-
axis : {{0 or 'index', 1 or 'columns'}}, default 0
11213-
The index or the name of the axis. 0 is equivalent to None or 'index'.
11214-
skipna : bool, default True
11215-
Exclude NA/null values. If an entire row/column is NA, the result
11216-
will be NA.
11217-
*args, **kwargs
11218-
Additional keywords have no effect but might be accepted for
11219-
compatibility with NumPy.
11220-
11221-
Returns
11222-
-------
11223-
{name1} or {name2}
11224-
Return cumulative {desc} of {name1} or {name2}.
11225-
11226-
See Also
11227-
--------
11228-
core.window.Expanding.{accum_func_name} : Similar functionality
11229-
but ignores ``NaN`` values.
11230-
{name2}.{accum_func_name} : Return the {desc} over
11231-
{name2} axis.
11232-
{name2}.cummax : Return cumulative maximum over {name2} axis.
11233-
{name2}.cummin : Return cumulative minimum over {name2} axis.
11234-
{name2}.cumsum : Return cumulative sum over {name2} axis.
11235-
{name2}.cumprod : Return cumulative product over {name2} axis.
11236-
11237-
{examples}"""
1123811269
skipna = nv.validate_cum_func_with_skipna(skipna, args, kwargs, name)
1123911270
if axis is None:
1124011271
axis = self._stat_axis_number
@@ -11271,52 +11302,17 @@ def _make_logical_function(
1127111302
examples: str,
1127211303
empty_value: bool,
1127311304
) -> Callable:
11274-
@doc(
11305+
@Substitution(
1127511306
desc=desc,
1127611307
name1=name1,
1127711308
name2=name2,
11309+
axis_descr=axis_descr,
1127811310
see_also=see_also,
1127911311
examples=examples,
11280-
empty_value=str(empty_value),
11312+
empty_value=empty_value,
1128111313
)
11314+
@Appender(_bool_doc)
1128211315
def logical_func(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs):
11283-
"""
11284-
{desc}
11285-
11286-
Parameters
11287-
----------
11288-
axis : {{0 or 'index', 1 or 'columns', None}}, default 0
11289-
Indicate which axis or axes should be reduced.
11290-
11291-
* 0 / 'index' : reduce the index, return a Series whose index is the
11292-
original column labels.
11293-
* 1 / 'columns' : reduce the columns, return a Series whose index is the
11294-
original index.
11295-
* None : reduce all axes, return a scalar.
11296-
11297-
bool_only : bool, default None
11298-
Include only boolean columns. If None, will attempt to use everything,
11299-
then use only boolean data. Not implemented for Series.
11300-
skipna : bool, default True
11301-
Exclude NA/null values. If the entire row/column is NA and skipna is
11302-
True, then the result will be {empty_value}, as for an empty row/column.
11303-
If skipna is False, then NA are treated as True, because these are not
11304-
equal to zero.
11305-
level : int or level name, default None
11306-
If the axis is a MultiIndex (hierarchical), count along a
11307-
particular level, collapsing into a {name1}.
11308-
**kwargs : any, default None
11309-
Additional keywords have no effect but might be accepted for
11310-
compatibility with NumPy.
11311-
11312-
Returns
11313-
-------
11314-
{name1} or {name2}
11315-
If level is specified, then, {name2} is returned; otherwise, {name1}
11316-
is returned.
11317-
11318-
{see_also}
11319-
{examples}"""
1132011316
nv.validate_logical_func(tuple(), kwargs, fname=name)
1132111317
if level is not None:
1132211318
if bool_only is not None:

0 commit comments

Comments
 (0)