Skip to content

Commit 8dc4341

Browse files
authored
DOC/REF: Rolling/Expanding/EWM docstrings (#39219)
* Create new system for rolling docs * Add doc decorators to all rolling methods * Remove redundant Notes section * Add new template for numba params * Remove old shared docs method * Fix small typos in docstrings * Move versionadded to notes * try fixing count? * Capitalize summary name * Fix docstring validation errors * Fix docbuild warnings * More docstring validation fixes * Fix docstring for expanding sum * Refactor doc templating for rolling * Refactor expanding docstrings * Refactor ewm docstrings * Fix some local docstring warnings * Truncate empty string at the end * Remove trailing extra newline * Fix example for doctest * Fix another agg docstring * Add ddof param to docs * Fix NumPy and SciPy references
1 parent dae99c7 commit 8dc4341

File tree

5 files changed

+1390
-1122
lines changed

5 files changed

+1390
-1122
lines changed

pandas/core/window/common.py

-16
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@
88
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
99

1010
from pandas.core.indexes.api import MultiIndex
11-
from pandas.core.shared_docs import _shared_docs
12-
13-
_shared_docs = dict(**_shared_docs)
14-
_doc_template = """
15-
Returns
16-
-------
17-
Series or DataFrame
18-
Return type is determined by the caller.
19-
20-
See Also
21-
--------
22-
pandas.Series.%(name)s : Calling object with Series data.
23-
pandas.DataFrame.%(name)s : Calling object with DataFrame data.
24-
pandas.Series.%(func_name)s : Similar method for Series.
25-
pandas.DataFrame.%(func_name)s : Similar method for DataFrame.
26-
"""
2711

2812

2913
def flex_binary_moment(arg1, arg2, f, pairwise=False):

pandas/core/window/doc.py

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
"""Any shareable docstring components for rolling/expanding/ewm"""
2+
from textwrap import dedent
3+
4+
from pandas.core.shared_docs import _shared_docs
5+
6+
_shared_docs = dict(**_shared_docs)
7+
8+
9+
def create_section_header(header: str) -> str:
10+
"""Create numpydoc section header"""
11+
return "\n".join((header, "-" * len(header))) + "\n"
12+
13+
14+
template_header = "Calculate the {window_method} {aggregation_description}.\n\n"
15+
16+
template_returns = dedent(
17+
"""
18+
Series or DataFrame
19+
Return type is the same as the original object.\n
20+
"""
21+
).replace("\n", "", 1)
22+
23+
template_see_also = dedent(
24+
"""
25+
pandas.Series.{window_method} : Calling {window_method} with Series data.
26+
pandas.DataFrame.{window_method} : Calling {window_method} with DataFrames.
27+
pandas.Series.{agg_method} : Aggregating {agg_method} for Series.
28+
pandas.DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n
29+
"""
30+
).replace("\n", "", 1)
31+
32+
args_compat = dedent(
33+
"""
34+
*args
35+
For NumPy compatibility and will not have an effect on the result.\n
36+
"""
37+
).replace("\n", "", 1)
38+
39+
kwargs_compat = dedent(
40+
"""
41+
**kwargs
42+
For NumPy compatibility and will not have an effect on the result.\n
43+
"""
44+
).replace("\n", "", 1)
45+
46+
kwargs_scipy = dedent(
47+
"""
48+
**kwargs
49+
Keyword arguments to configure the ``SciPy`` weighted window type.\n
50+
"""
51+
).replace("\n", "", 1)
52+
53+
window_apply_parameters = dedent(
54+
"""
55+
func : function
56+
Must produce a single value from an ndarray input if ``raw=True``
57+
or a single value from a Series if ``raw=False``. Can also accept a
58+
Numba JIT function with ``engine='numba'`` specified.
59+
60+
.. versionchanged:: 1.0.0
61+
62+
raw : bool, default None
63+
* ``False`` : passes each row or column as a Series to the
64+
function.
65+
* ``True`` : the passed function will receive ndarray
66+
objects instead.
67+
If you are just applying a NumPy reduction function this will
68+
achieve much better performance.
69+
70+
engine : str, default None
71+
* ``'cython'`` : Runs rolling apply through C-extensions from cython.
72+
* ``'numba'`` : Runs rolling apply through JIT compiled code from numba.
73+
Only available when ``raw`` is set to ``True``.
74+
* ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
75+
76+
.. versionadded:: 1.0.0
77+
78+
engine_kwargs : dict, default None
79+
* For ``'cython'`` engine, there are no accepted ``engine_kwargs``
80+
* For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
81+
and ``parallel`` dictionary keys. The values must either be ``True`` or
82+
``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
83+
``{{'nopython': True, 'nogil': False, 'parallel': False}}`` and will be
84+
applied to both the ``func`` and the ``apply`` rolling aggregation.
85+
86+
.. versionadded:: 1.0.0
87+
88+
args : tuple, default None
89+
Positional arguments to be passed into func.
90+
91+
kwargs : dict, default None
92+
Keyword arguments to be passed into func.\n
93+
"""
94+
).replace("\n", "", 1)
95+
96+
numba_notes = (
97+
"See :ref:`window.numba_engine` for extended documentation "
98+
"and performance considerations for the Numba engine.\n"
99+
)
100+
101+
window_agg_numba_parameters = dedent(
102+
"""
103+
engine : str, default None
104+
* ``'cython'`` : Runs the operation through C-extensions from cython.
105+
* ``'numba'`` : Runs the operation through JIT compiled code from numba.
106+
* ``None`` : Defaults to ``'cython'`` or globally setting ``compute.use_numba``
107+
108+
.. versionadded:: 1.3.0
109+
110+
engine_kwargs : dict, default None
111+
* For ``'cython'`` engine, there are no accepted ``engine_kwargs``
112+
* For ``'numba'`` engine, the engine can accept ``nopython``, ``nogil``
113+
and ``parallel`` dictionary keys. The values must either be ``True`` or
114+
``False``. The default ``engine_kwargs`` for the ``'numba'`` engine is
115+
``{{'nopython': True, 'nogil': False, 'parallel': False}}``
116+
117+
.. versionadded:: 1.3.0\n
118+
"""
119+
).replace("\n", "", 1)

0 commit comments

Comments
 (0)