Skip to content

Commit c9a3a77

Browse files
committed
revert to Appender in dynamically generated functions
1 parent 5125499 commit c9a3a77

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
@@ -10624,6 +10624,60 @@ def _doc_parms(cls):
1062410624
%(examples)s
1062510625
"""
1062610626

10627+
_num_ddof_doc = """
10628+
%(desc)s
10629+
Parameters
10630+
----------
10631+
axis : %(axis_descr)s
10632+
skipna : bool, default True
10633+
Exclude NA/null values. If an entire row/column is NA, the result
10634+
will be NA.
10635+
level : int or level name, default None
10636+
If the axis is a MultiIndex (hierarchical), count along a
10637+
particular level, collapsing into a %(name1)s.
10638+
ddof : int, default 1
10639+
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
10640+
where N represents the number of elements.
10641+
numeric_only : bool, default None
10642+
Include only float, int, boolean columns. If None, will attempt to use
10643+
everything, then use only numeric data. Not implemented for Series.
10644+
Returns
10645+
-------
10646+
%(name1)s or %(name2)s (if level specified)\n"""
10647+
10648+
_bool_doc = """
10649+
%(desc)s
10650+
Parameters
10651+
----------
10652+
axis : {0 or 'index', 1 or 'columns', None}, default 0
10653+
Indicate which axis or axes should be reduced.
10654+
* 0 / 'index' : reduce the index, return a Series whose index is the
10655+
original column labels.
10656+
* 1 / 'columns' : reduce the columns, return a Series whose index is the
10657+
original index.
10658+
* None : reduce all axes, return a scalar.
10659+
bool_only : bool, default None
10660+
Include only boolean columns. If None, will attempt to use everything,
10661+
then use only boolean data. Not implemented for Series.
10662+
skipna : bool, default True
10663+
Exclude NA/null values. If the entire row/column is NA and skipna is
10664+
True, then the result will be %(empty_value)s, as for an empty row/column.
10665+
If skipna is False, then NA are treated as True, because these are not
10666+
equal to zero.
10667+
level : int or level name, default None
10668+
If the axis is a MultiIndex (hierarchical), count along a
10669+
particular level, collapsing into a %(name1)s.
10670+
**kwargs : any, default None
10671+
Additional keywords have no effect but might be accepted for
10672+
compatibility with NumPy.
10673+
Returns
10674+
-------
10675+
%(name1)s or %(name2)s
10676+
If level is specified, then, %(name2)s is returned; otherwise, %(name1)s
10677+
is returned.
10678+
%(see_also)s
10679+
%(examples)s"""
10680+
1062710681
_all_desc = """\
1062810682
Return whether all elements are True, potentially over an axis.
1062910683
@@ -10684,6 +10738,36 @@ def _doc_parms(cls):
1068410738
DataFrame.any : Return True if one (or more) elements are True.
1068510739
"""
1068610740

10741+
_cnum_doc = """
10742+
Return cumulative %(desc)s over a DataFrame or Series axis.
10743+
Returns a DataFrame or Series of the same size containing the cumulative
10744+
%(desc)s.
10745+
Parameters
10746+
----------
10747+
axis : {0 or 'index', 1 or 'columns'}, default 0
10748+
The index or the name of the axis. 0 is equivalent to None or 'index'.
10749+
skipna : bool, default True
10750+
Exclude NA/null values. If an entire row/column is NA, the result
10751+
will be NA.
10752+
*args, **kwargs
10753+
Additional keywords have no effect but might be accepted for
10754+
compatibility with NumPy.
10755+
Returns
10756+
-------
10757+
%(name1)s or %(name2)s
10758+
Return cumulative %(desc)s of %(name1)s or %(name2)s.
10759+
See Also
10760+
--------
10761+
core.window.Expanding.%(accum_func_name)s : Similar functionality
10762+
but ignores ``NaN`` values.
10763+
%(name2)s.%(accum_func_name)s : Return the %(desc)s over
10764+
%(name2)s axis.
10765+
%(name2)s.cummax : Return cumulative maximum over %(name2)s axis.
10766+
%(name2)s.cummin : Return cumulative minimum over %(name2)s axis.
10767+
%(name2)s.cumsum : Return cumulative sum over %(name2)s axis.
10768+
%(name2)s.cumprod : Return cumulative product over %(name2)s axis.
10769+
%(examples)s"""
10770+
1068710771
_cummin_examples = """\
1068810772
Examples
1068910773
--------
@@ -11252,32 +11336,11 @@ def stat_func(
1125211336
def _make_stat_function_ddof(
1125311337
cls, name: str, name1: str, name2: str, axis_descr: str, desc: str, func: Callable
1125411338
) -> Callable:
11255-
@doc(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11339+
@Substitution(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11340+
@Appender(_num_ddof_doc)
1125611341
def stat_func(
1125711342
self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs
1125811343
):
11259-
"""
11260-
{desc}
11261-
11262-
Parameters
11263-
----------
11264-
axis : {axis_descr}
11265-
skipna : bool, default True
11266-
Exclude NA/null values. If an entire row/column is NA, the result
11267-
will be NA.
11268-
level : int or level name, default None
11269-
If the axis is a MultiIndex (hierarchical), count along a
11270-
particular level, collapsing into a %(name1)s.
11271-
ddof : int, default 1
11272-
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
11273-
where N represents the number of elements.
11274-
numeric_only : bool, default None
11275-
Include only float, int, boolean columns. If None, will attempt to use
11276-
everything, then use only numeric data. Not implemented for Series.
11277-
11278-
Returns
11279-
-------
11280-
{name1} or {name2} (if level specified)\n"""
1128111344
nv.validate_stat_ddof_func(tuple(), kwargs, fname=name)
1128211345
if skipna is None:
1128311346
skipna = True
@@ -11305,48 +11368,16 @@ def _make_cum_function(
1130511368
accum_func_name: str,
1130611369
examples: str,
1130711370
) -> Callable:
11308-
@doc(
11371+
@Substitution(
1130911372
desc=desc,
1131011373
name1=name1,
1131111374
name2=name2,
11375+
axis_descr=axis_descr,
1131211376
accum_func_name=accum_func_name,
1131311377
examples=examples,
1131411378
)
11379+
@Appender(_cnum_doc)
1131511380
def cum_func(self, axis=None, skipna=True, *args, **kwargs):
11316-
"""
11317-
Return cumulative {desc} over a DataFrame or Series axis.
11318-
11319-
Returns a DataFrame or Series of the same size containing the cumulative
11320-
{desc}.
11321-
11322-
Parameters
11323-
----------
11324-
axis : {{0 or 'index', 1 or 'columns'}}, default 0
11325-
The index or the name of the axis. 0 is equivalent to None or 'index'.
11326-
skipna : bool, default True
11327-
Exclude NA/null values. If an entire row/column is NA, the result
11328-
will be NA.
11329-
*args, **kwargs
11330-
Additional keywords have no effect but might be accepted for
11331-
compatibility with NumPy.
11332-
11333-
Returns
11334-
-------
11335-
{name1} or {name2}
11336-
Return cumulative {desc} of {name1} or {name2}.
11337-
11338-
See Also
11339-
--------
11340-
core.window.Expanding.{accum_func_name} : Similar functionality
11341-
but ignores ``NaN`` values.
11342-
{name2}.{accum_func_name} : Return the {desc} over
11343-
{name2} axis.
11344-
{name2}.cummax : Return cumulative maximum over {name2} axis.
11345-
{name2}.cummin : Return cumulative minimum over {name2} axis.
11346-
{name2}.cumsum : Return cumulative sum over {name2} axis.
11347-
{name2}.cumprod : Return cumulative product over {name2} axis.
11348-
11349-
{examples}"""
1135011381
skipna = nv.validate_cum_func_with_skipna(skipna, args, kwargs, name)
1135111382
if axis is None:
1135211383
axis = self._stat_axis_number
@@ -11383,52 +11414,17 @@ def _make_logical_function(
1138311414
examples: str,
1138411415
empty_value: bool,
1138511416
) -> Callable:
11386-
@doc(
11417+
@Substitution(
1138711418
desc=desc,
1138811419
name1=name1,
1138911420
name2=name2,
11421+
axis_descr=axis_descr,
1139011422
see_also=see_also,
1139111423
examples=examples,
11392-
empty_value=str(empty_value),
11424+
empty_value=empty_value,
1139311425
)
11426+
@Appender(_bool_doc)
1139411427
def logical_func(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs):
11395-
"""
11396-
{desc}
11397-
11398-
Parameters
11399-
----------
11400-
axis : {{0 or 'index', 1 or 'columns', None}}, default 0
11401-
Indicate which axis or axes should be reduced.
11402-
11403-
* 0 / 'index' : reduce the index, return a Series whose index is the
11404-
original column labels.
11405-
* 1 / 'columns' : reduce the columns, return a Series whose index is the
11406-
original index.
11407-
* None : reduce all axes, return a scalar.
11408-
11409-
bool_only : bool, default None
11410-
Include only boolean columns. If None, will attempt to use everything,
11411-
then use only boolean data. Not implemented for Series.
11412-
skipna : bool, default True
11413-
Exclude NA/null values. If the entire row/column is NA and skipna is
11414-
True, then the result will be {empty_value}, as for an empty row/column.
11415-
If skipna is False, then NA are treated as True, because these are not
11416-
equal to zero.
11417-
level : int or level name, default None
11418-
If the axis is a MultiIndex (hierarchical), count along a
11419-
particular level, collapsing into a {name1}.
11420-
**kwargs : any, default None
11421-
Additional keywords have no effect but might be accepted for
11422-
compatibility with NumPy.
11423-
11424-
Returns
11425-
-------
11426-
{name1} or {name2}
11427-
If level is specified, then, {name2} is returned; otherwise, {name1}
11428-
is returned.
11429-
11430-
{see_also}
11431-
{examples}"""
1143211428
nv.validate_logical_func(tuple(), kwargs, fname=name)
1143311429
if level is not None:
1143411430
if bool_only is not None:

0 commit comments

Comments
 (0)