Skip to content

Commit 7119d97

Browse files
committed
revert to Appender in dynamically generated functions
1 parent d4477f6 commit 7119d97

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
@@ -10400,6 +10400,60 @@ def _doc_parms(cls):
1040010400
%(examples)s
1040110401
"""
1040210402

10403+
_num_ddof_doc = """
10404+
%(desc)s
10405+
Parameters
10406+
----------
10407+
axis : %(axis_descr)s
10408+
skipna : bool, default True
10409+
Exclude NA/null values. If an entire row/column is NA, the result
10410+
will be NA.
10411+
level : int or level name, default None
10412+
If the axis is a MultiIndex (hierarchical), count along a
10413+
particular level, collapsing into a %(name1)s.
10414+
ddof : int, default 1
10415+
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
10416+
where N represents the number of elements.
10417+
numeric_only : bool, default None
10418+
Include only float, int, boolean columns. If None, will attempt to use
10419+
everything, then use only numeric data. Not implemented for Series.
10420+
Returns
10421+
-------
10422+
%(name1)s or %(name2)s (if level specified)\n"""
10423+
10424+
_bool_doc = """
10425+
%(desc)s
10426+
Parameters
10427+
----------
10428+
axis : {0 or 'index', 1 or 'columns', None}, default 0
10429+
Indicate which axis or axes should be reduced.
10430+
* 0 / 'index' : reduce the index, return a Series whose index is the
10431+
original column labels.
10432+
* 1 / 'columns' : reduce the columns, return a Series whose index is the
10433+
original index.
10434+
* None : reduce all axes, return a scalar.
10435+
bool_only : bool, default None
10436+
Include only boolean columns. If None, will attempt to use everything,
10437+
then use only boolean data. Not implemented for Series.
10438+
skipna : bool, default True
10439+
Exclude NA/null values. If the entire row/column is NA and skipna is
10440+
True, then the result will be %(empty_value)s, as for an empty row/column.
10441+
If skipna is False, then NA are treated as True, because these are not
10442+
equal to zero.
10443+
level : int or level name, default None
10444+
If the axis is a MultiIndex (hierarchical), count along a
10445+
particular level, collapsing into a %(name1)s.
10446+
**kwargs : any, default None
10447+
Additional keywords have no effect but might be accepted for
10448+
compatibility with NumPy.
10449+
Returns
10450+
-------
10451+
%(name1)s or %(name2)s
10452+
If level is specified, then, %(name2)s is returned; otherwise, %(name1)s
10453+
is returned.
10454+
%(see_also)s
10455+
%(examples)s"""
10456+
1040310457
_all_desc = """\
1040410458
Return whether all elements are True, potentially over an axis.
1040510459
@@ -10460,6 +10514,36 @@ def _doc_parms(cls):
1046010514
DataFrame.any : Return True if one (or more) elements are True.
1046110515
"""
1046210516

10517+
_cnum_doc = """
10518+
Return cumulative %(desc)s over a DataFrame or Series axis.
10519+
Returns a DataFrame or Series of the same size containing the cumulative
10520+
%(desc)s.
10521+
Parameters
10522+
----------
10523+
axis : {0 or 'index', 1 or 'columns'}, default 0
10524+
The index or the name of the axis. 0 is equivalent to None or 'index'.
10525+
skipna : bool, default True
10526+
Exclude NA/null values. If an entire row/column is NA, the result
10527+
will be NA.
10528+
*args, **kwargs
10529+
Additional keywords have no effect but might be accepted for
10530+
compatibility with NumPy.
10531+
Returns
10532+
-------
10533+
%(name1)s or %(name2)s
10534+
Return cumulative %(desc)s of %(name1)s or %(name2)s.
10535+
See Also
10536+
--------
10537+
core.window.Expanding.%(accum_func_name)s : Similar functionality
10538+
but ignores ``NaN`` values.
10539+
%(name2)s.%(accum_func_name)s : Return the %(desc)s over
10540+
%(name2)s axis.
10541+
%(name2)s.cummax : Return cumulative maximum over %(name2)s axis.
10542+
%(name2)s.cummin : Return cumulative minimum over %(name2)s axis.
10543+
%(name2)s.cumsum : Return cumulative sum over %(name2)s axis.
10544+
%(name2)s.cumprod : Return cumulative product over %(name2)s axis.
10545+
%(examples)s"""
10546+
1046310547
_cummin_examples = """\
1046410548
Examples
1046510549
--------
@@ -11028,32 +11112,11 @@ def stat_func(
1102811112
def _make_stat_function_ddof(
1102911113
cls, name: str, name1: str, name2: str, axis_descr: str, desc: str, func: Callable
1103011114
) -> Callable:
11031-
@doc(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11115+
@Substitution(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11116+
@Appender(_num_ddof_doc)
1103211117
def stat_func(
1103311118
self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs
1103411119
):
11035-
"""
11036-
{desc}
11037-
11038-
Parameters
11039-
----------
11040-
axis : {axis_descr}
11041-
skipna : bool, default True
11042-
Exclude NA/null values. If an entire row/column is NA, the result
11043-
will be NA.
11044-
level : int or level name, default None
11045-
If the axis is a MultiIndex (hierarchical), count along a
11046-
particular level, collapsing into a %(name1)s.
11047-
ddof : int, default 1
11048-
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
11049-
where N represents the number of elements.
11050-
numeric_only : bool, default None
11051-
Include only float, int, boolean columns. If None, will attempt to use
11052-
everything, then use only numeric data. Not implemented for Series.
11053-
11054-
Returns
11055-
-------
11056-
{name1} or {name2} (if level specified)\n"""
1105711120
nv.validate_stat_ddof_func(tuple(), kwargs, fname=name)
1105811121
if skipna is None:
1105911122
skipna = True
@@ -11081,48 +11144,16 @@ def _make_cum_function(
1108111144
accum_func_name: str,
1108211145
examples: str,
1108311146
) -> Callable:
11084-
@doc(
11147+
@Substitution(
1108511148
desc=desc,
1108611149
name1=name1,
1108711150
name2=name2,
11151+
axis_descr=axis_descr,
1108811152
accum_func_name=accum_func_name,
1108911153
examples=examples,
1109011154
)
11155+
@Appender(_cnum_doc)
1109111156
def cum_func(self, axis=None, skipna=True, *args, **kwargs):
11092-
"""
11093-
Return cumulative {desc} over a DataFrame or Series axis.
11094-
11095-
Returns a DataFrame or Series of the same size containing the cumulative
11096-
{desc}.
11097-
11098-
Parameters
11099-
----------
11100-
axis : {{0 or 'index', 1 or 'columns'}}, default 0
11101-
The index or the name of the axis. 0 is equivalent to None or 'index'.
11102-
skipna : bool, default True
11103-
Exclude NA/null values. If an entire row/column is NA, the result
11104-
will be NA.
11105-
*args, **kwargs
11106-
Additional keywords have no effect but might be accepted for
11107-
compatibility with NumPy.
11108-
11109-
Returns
11110-
-------
11111-
{name1} or {name2}
11112-
Return cumulative {desc} of {name1} or {name2}.
11113-
11114-
See Also
11115-
--------
11116-
core.window.Expanding.{accum_func_name} : Similar functionality
11117-
but ignores ``NaN`` values.
11118-
{name2}.{accum_func_name} : Return the {desc} over
11119-
{name2} axis.
11120-
{name2}.cummax : Return cumulative maximum over {name2} axis.
11121-
{name2}.cummin : Return cumulative minimum over {name2} axis.
11122-
{name2}.cumsum : Return cumulative sum over {name2} axis.
11123-
{name2}.cumprod : Return cumulative product over {name2} axis.
11124-
11125-
{examples}"""
1112611157
skipna = nv.validate_cum_func_with_skipna(skipna, args, kwargs, name)
1112711158
if axis is None:
1112811159
axis = self._stat_axis_number
@@ -11159,52 +11190,17 @@ def _make_logical_function(
1115911190
examples: str,
1116011191
empty_value: bool,
1116111192
) -> Callable:
11162-
@doc(
11193+
@Substitution(
1116311194
desc=desc,
1116411195
name1=name1,
1116511196
name2=name2,
11197+
axis_descr=axis_descr,
1116611198
see_also=see_also,
1116711199
examples=examples,
11168-
empty_value=str(empty_value),
11200+
empty_value=empty_value,
1116911201
)
11202+
@Appender(_bool_doc)
1117011203
def logical_func(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs):
11171-
"""
11172-
{desc}
11173-
11174-
Parameters
11175-
----------
11176-
axis : {{0 or 'index', 1 or 'columns', None}}, default 0
11177-
Indicate which axis or axes should be reduced.
11178-
11179-
* 0 / 'index' : reduce the index, return a Series whose index is the
11180-
original column labels.
11181-
* 1 / 'columns' : reduce the columns, return a Series whose index is the
11182-
original index.
11183-
* None : reduce all axes, return a scalar.
11184-
11185-
bool_only : bool, default None
11186-
Include only boolean columns. If None, will attempt to use everything,
11187-
then use only boolean data. Not implemented for Series.
11188-
skipna : bool, default True
11189-
Exclude NA/null values. If the entire row/column is NA and skipna is
11190-
True, then the result will be {empty_value}, as for an empty row/column.
11191-
If skipna is False, then NA are treated as True, because these are not
11192-
equal to zero.
11193-
level : int or level name, default None
11194-
If the axis is a MultiIndex (hierarchical), count along a
11195-
particular level, collapsing into a {name1}.
11196-
**kwargs : any, default None
11197-
Additional keywords have no effect but might be accepted for
11198-
compatibility with NumPy.
11199-
11200-
Returns
11201-
-------
11202-
{name1} or {name2}
11203-
If level is specified, then, {name2} is returned; otherwise, {name1}
11204-
is returned.
11205-
11206-
{see_also}
11207-
{examples}"""
1120811204
nv.validate_logical_func(tuple(), kwargs, fname=name)
1120911205
if level is not None:
1121011206
if bool_only is not None:

0 commit comments

Comments
 (0)