Skip to content

Commit 23bb2aa

Browse files
committed
revert to Appender in dynamically generated functions
1 parent 33910b0 commit 23bb2aa

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
@@ -10365,6 +10365,60 @@ def _doc_parms(cls):
1036510365
%(examples)s
1036610366
"""
1036710367

10368+
_num_ddof_doc = """
10369+
%(desc)s
10370+
Parameters
10371+
----------
10372+
axis : %(axis_descr)s
10373+
skipna : bool, default True
10374+
Exclude NA/null values. If an entire row/column is NA, the result
10375+
will be NA.
10376+
level : int or level name, default None
10377+
If the axis is a MultiIndex (hierarchical), count along a
10378+
particular level, collapsing into a %(name1)s.
10379+
ddof : int, default 1
10380+
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
10381+
where N represents the number of elements.
10382+
numeric_only : bool, default None
10383+
Include only float, int, boolean columns. If None, will attempt to use
10384+
everything, then use only numeric data. Not implemented for Series.
10385+
Returns
10386+
-------
10387+
%(name1)s or %(name2)s (if level specified)\n"""
10388+
10389+
_bool_doc = """
10390+
%(desc)s
10391+
Parameters
10392+
----------
10393+
axis : {0 or 'index', 1 or 'columns', None}, default 0
10394+
Indicate which axis or axes should be reduced.
10395+
* 0 / 'index' : reduce the index, return a Series whose index is the
10396+
original column labels.
10397+
* 1 / 'columns' : reduce the columns, return a Series whose index is the
10398+
original index.
10399+
* None : reduce all axes, return a scalar.
10400+
bool_only : bool, default None
10401+
Include only boolean columns. If None, will attempt to use everything,
10402+
then use only boolean data. Not implemented for Series.
10403+
skipna : bool, default True
10404+
Exclude NA/null values. If the entire row/column is NA and skipna is
10405+
True, then the result will be %(empty_value)s, as for an empty row/column.
10406+
If skipna is False, then NA are treated as True, because these are not
10407+
equal to zero.
10408+
level : int or level name, default None
10409+
If the axis is a MultiIndex (hierarchical), count along a
10410+
particular level, collapsing into a %(name1)s.
10411+
**kwargs : any, default None
10412+
Additional keywords have no effect but might be accepted for
10413+
compatibility with NumPy.
10414+
Returns
10415+
-------
10416+
%(name1)s or %(name2)s
10417+
If level is specified, then, %(name2)s is returned; otherwise, %(name1)s
10418+
is returned.
10419+
%(see_also)s
10420+
%(examples)s"""
10421+
1036810422
_all_desc = """\
1036910423
Return whether all elements are True, potentially over an axis.
1037010424
@@ -10425,6 +10479,36 @@ def _doc_parms(cls):
1042510479
DataFrame.any : Return True if one (or more) elements are True.
1042610480
"""
1042710481

10482+
_cnum_doc = """
10483+
Return cumulative %(desc)s over a DataFrame or Series axis.
10484+
Returns a DataFrame or Series of the same size containing the cumulative
10485+
%(desc)s.
10486+
Parameters
10487+
----------
10488+
axis : {0 or 'index', 1 or 'columns'}, default 0
10489+
The index or the name of the axis. 0 is equivalent to None or 'index'.
10490+
skipna : bool, default True
10491+
Exclude NA/null values. If an entire row/column is NA, the result
10492+
will be NA.
10493+
*args, **kwargs
10494+
Additional keywords have no effect but might be accepted for
10495+
compatibility with NumPy.
10496+
Returns
10497+
-------
10498+
%(name1)s or %(name2)s
10499+
Return cumulative %(desc)s of %(name1)s or %(name2)s.
10500+
See Also
10501+
--------
10502+
core.window.Expanding.%(accum_func_name)s : Similar functionality
10503+
but ignores ``NaN`` values.
10504+
%(name2)s.%(accum_func_name)s : Return the %(desc)s over
10505+
%(name2)s axis.
10506+
%(name2)s.cummax : Return cumulative maximum over %(name2)s axis.
10507+
%(name2)s.cummin : Return cumulative minimum over %(name2)s axis.
10508+
%(name2)s.cumsum : Return cumulative sum over %(name2)s axis.
10509+
%(name2)s.cumprod : Return cumulative product over %(name2)s axis.
10510+
%(examples)s"""
10511+
1042810512
_cummin_examples = """\
1042910513
Examples
1043010514
--------
@@ -10993,32 +11077,11 @@ def stat_func(
1099311077
def _make_stat_function_ddof(
1099411078
cls, name: str, name1: str, name2: str, axis_descr: str, desc: str, func: Callable
1099511079
) -> Callable:
10996-
@doc(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11080+
@Substitution(desc=desc, name1=name1, name2=name2, axis_descr=axis_descr)
11081+
@Appender(_num_ddof_doc)
1099711082
def stat_func(
1099811083
self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs
1099911084
):
11000-
"""
11001-
{desc}
11002-
11003-
Parameters
11004-
----------
11005-
axis : {axis_descr}
11006-
skipna : bool, default True
11007-
Exclude NA/null values. If an entire row/column is NA, the result
11008-
will be NA.
11009-
level : int or level name, default None
11010-
If the axis is a MultiIndex (hierarchical), count along a
11011-
particular level, collapsing into a %(name1)s.
11012-
ddof : int, default 1
11013-
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
11014-
where N represents the number of elements.
11015-
numeric_only : bool, default None
11016-
Include only float, int, boolean columns. If None, will attempt to use
11017-
everything, then use only numeric data. Not implemented for Series.
11018-
11019-
Returns
11020-
-------
11021-
{name1} or {name2} (if level specified)\n"""
1102211085
nv.validate_stat_ddof_func(tuple(), kwargs, fname=name)
1102311086
if skipna is None:
1102411087
skipna = True
@@ -11046,48 +11109,16 @@ def _make_cum_function(
1104611109
accum_func_name: str,
1104711110
examples: str,
1104811111
) -> Callable:
11049-
@doc(
11112+
@Substitution(
1105011113
desc=desc,
1105111114
name1=name1,
1105211115
name2=name2,
11116+
axis_descr=axis_descr,
1105311117
accum_func_name=accum_func_name,
1105411118
examples=examples,
1105511119
)
11120+
@Appender(_cnum_doc)
1105611121
def cum_func(self, axis=None, skipna=True, *args, **kwargs):
11057-
"""
11058-
Return cumulative {desc} over a DataFrame or Series axis.
11059-
11060-
Returns a DataFrame or Series of the same size containing the cumulative
11061-
{desc}.
11062-
11063-
Parameters
11064-
----------
11065-
axis : {{0 or 'index', 1 or 'columns'}}, default 0
11066-
The index or the name of the axis. 0 is equivalent to None or 'index'.
11067-
skipna : bool, default True
11068-
Exclude NA/null values. If an entire row/column is NA, the result
11069-
will be NA.
11070-
*args, **kwargs
11071-
Additional keywords have no effect but might be accepted for
11072-
compatibility with NumPy.
11073-
11074-
Returns
11075-
-------
11076-
{name1} or {name2}
11077-
Return cumulative {desc} of {name1} or {name2}.
11078-
11079-
See Also
11080-
--------
11081-
core.window.Expanding.{accum_func_name} : Similar functionality
11082-
but ignores ``NaN`` values.
11083-
{name2}.{accum_func_name} : Return the {desc} over
11084-
{name2} axis.
11085-
{name2}.cummax : Return cumulative maximum over {name2} axis.
11086-
{name2}.cummin : Return cumulative minimum over {name2} axis.
11087-
{name2}.cumsum : Return cumulative sum over {name2} axis.
11088-
{name2}.cumprod : Return cumulative product over {name2} axis.
11089-
11090-
{examples}"""
1109111122
skipna = nv.validate_cum_func_with_skipna(skipna, args, kwargs, name)
1109211123
if axis is None:
1109311124
axis = self._stat_axis_number
@@ -11126,52 +11157,17 @@ def _make_logical_function(
1112611157
examples: str,
1112711158
empty_value: bool,
1112811159
) -> Callable:
11129-
@doc(
11160+
@Substitution(
1113011161
desc=desc,
1113111162
name1=name1,
1113211163
name2=name2,
11164+
axis_descr=axis_descr,
1113311165
see_also=see_also,
1113411166
examples=examples,
11135-
empty_value=str(empty_value),
11167+
empty_value=empty_value,
1113611168
)
11169+
@Appender(_bool_doc)
1113711170
def logical_func(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs):
11138-
"""
11139-
{desc}
11140-
11141-
Parameters
11142-
----------
11143-
axis : {{0 or 'index', 1 or 'columns', None}}, default 0
11144-
Indicate which axis or axes should be reduced.
11145-
11146-
* 0 / 'index' : reduce the index, return a Series whose index is the
11147-
original column labels.
11148-
* 1 / 'columns' : reduce the columns, return a Series whose index is the
11149-
original index.
11150-
* None : reduce all axes, return a scalar.
11151-
11152-
bool_only : bool, default None
11153-
Include only boolean columns. If None, will attempt to use everything,
11154-
then use only boolean data. Not implemented for Series.
11155-
skipna : bool, default True
11156-
Exclude NA/null values. If the entire row/column is NA and skipna is
11157-
True, then the result will be {empty_value}, as for an empty row/column.
11158-
If skipna is False, then NA are treated as True, because these are not
11159-
equal to zero.
11160-
level : int or level name, default None
11161-
If the axis is a MultiIndex (hierarchical), count along a
11162-
particular level, collapsing into a {name1}.
11163-
**kwargs : any, default None
11164-
Additional keywords have no effect but might be accepted for
11165-
compatibility with NumPy.
11166-
11167-
Returns
11168-
-------
11169-
{name1} or {name2}
11170-
If level is specified, then, {name2} is returned; otherwise, {name1}
11171-
is returned.
11172-
11173-
{see_also}
11174-
{examples}"""
1117511171
nv.validate_logical_func(tuple(), kwargs, fname=name)
1117611172
if level is not None:
1117711173
if bool_only is not None:

0 commit comments

Comments
 (0)