Skip to content

Commit 8db2167

Browse files
benjaminrTomAugspurger
authored andcommitted
DOC: Fix docstrings with the sections in the wrong order pandas-dev#24280 (pandas-dev#24288)
1 parent ed6627b commit 8db2167

File tree

8 files changed

+158
-127
lines changed

8 files changed

+158
-127
lines changed

ci/code_checks.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ fi
212212
### DOCSTRINGS ###
213213
if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
214214

215-
MSG='Validate docstrings (GL09, GL06, SS04, PR03, PR05, EX04)' ; echo $MSG
216-
$BASE_DIR/scripts/validate_docstrings.py --format=azure --errors=GL09,GL06,SS04,PR03,PR05,EX04
215+
MSG='Validate docstrings (GL06, GL07, GL09, SS04, PR03, PR05, EX04)' ; echo $MSG
216+
$BASE_DIR/scripts/validate_docstrings.py --format=azure --errors=GL06,GL07,GL09,SS04,PR03,PR05,EX04
217217
RET=$(($RET + $?)) ; echo $MSG "DONE"
218218

219219
fi

pandas/core/frame.py

+19-16
Original file line numberDiff line numberDiff line change
@@ -6091,7 +6091,7 @@ def _gotitem(self,
60916091
# TODO: _shallow_copy(subset)?
60926092
return subset[key]
60936093

6094-
_agg_doc = dedent("""
6094+
_agg_summary_and_see_also_doc = dedent("""
60956095
The aggregation operations are always performed over an axis, either the
60966096
index (default) or the column axis. This behavior is different from
60976097
`numpy` aggregation functions (`mean`, `median`, `prod`, `sum`, `std`,
@@ -6101,6 +6101,19 @@ def _gotitem(self,
61016101
61026102
`agg` is an alias for `aggregate`. Use the alias.
61036103
6104+
See Also
6105+
--------
6106+
DataFrame.apply : Perform any type of operations.
6107+
DataFrame.transform : Perform transformation type operations.
6108+
pandas.core.groupby.GroupBy : Perform operations over groups.
6109+
pandas.core.resample.Resampler : Perform operations over resampled bins.
6110+
pandas.core.window.Rolling : Perform operations over rolling window.
6111+
pandas.core.window.Expanding : Perform operations over expanding window.
6112+
pandas.core.window.EWM : Perform operation over exponential weighted
6113+
window.
6114+
""")
6115+
6116+
_agg_examples_doc = dedent("""
61046117
Examples
61056118
--------
61066119
>>> df = pd.DataFrame([[1, 2, 3],
@@ -6132,23 +6145,13 @@ def _gotitem(self,
61326145
2 8.0
61336146
3 NaN
61346147
dtype: float64
6135-
6136-
See Also
6137-
--------
6138-
DataFrame.apply : Perform any type of operations.
6139-
DataFrame.transform : Perform transformation type operations.
6140-
pandas.core.groupby.GroupBy : Perform operations over groups.
6141-
pandas.core.resample.Resampler : Perform operations over resampled bins.
6142-
pandas.core.window.Rolling : Perform operations over rolling window.
6143-
pandas.core.window.Expanding : Perform operations over expanding window.
6144-
pandas.core.window.EWM : Perform operation over exponential weighted
6145-
window.
61466148
""")
61476149

6148-
@Appender(_agg_doc)
6149-
@Appender(_shared_docs['aggregate'] % dict(
6150-
versionadded='.. versionadded:: 0.20.0',
6151-
**_shared_doc_kwargs))
6150+
@Substitution(see_also=_agg_summary_and_see_also_doc,
6151+
examples=_agg_examples_doc,
6152+
versionadded='.. versionadded:: 0.20.0',
6153+
**_shared_doc_kwargs)
6154+
@Appender(_shared_docs['aggregate'])
61526155
def aggregate(self, func, axis=0, *args, **kwargs):
61536156
axis = self._get_axis_number(axis)
61546157

pandas/core/generic.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import gc
55
import json
66
import operator
7+
from textwrap import dedent
78
import warnings
89
import weakref
910

@@ -4895,7 +4896,7 @@ def sample(self, n=None, frac=None, replace=False, weights=None,
48954896
def pipe(self, func, *args, **kwargs):
48964897
return com._pipe(self, func, *args, **kwargs)
48974898

4898-
_shared_docs['aggregate'] = ("""
4899+
_shared_docs['aggregate'] = dedent("""
48994900
Aggregate using one or more operations over the specified axis.
49004901
49014902
%(versionadded)s
@@ -4926,11 +4927,15 @@ def pipe(self, func, *args, **kwargs):
49264927
if Series.agg is called with single function, returns a scalar
49274928
if Series.agg is called with several functions, returns a Series
49284929
4930+
%(see_also)s
4931+
49294932
Notes
49304933
-----
49314934
`agg` is an alias for `aggregate`. Use the alias.
49324935
49334936
A passed user-defined-function will be passed a Series for evaluation.
4937+
4938+
%(examples)s
49344939
""")
49354940

49364941
_shared_docs['transform'] = ("""

pandas/core/groupby/generic.py

+30-26
Original file line numberDiff line numberDiff line change
@@ -706,10 +706,17 @@ def _selection_name(self):
706706
else:
707707
return self._selection
708708

709-
_agg_doc = dedent("""
710-
Examples
709+
_agg_see_also_doc = dedent("""
710+
See Also
711711
--------
712+
pandas.Series.groupby.apply
713+
pandas.Series.groupby.transform
714+
pandas.Series.aggregate
715+
""")
712716

717+
_agg_examples_doc = dedent("""
718+
Examples
719+
--------
713720
>>> s = pd.Series([1, 2, 3, 4])
714721
715722
>>> s
@@ -733,13 +740,6 @@ def _selection_name(self):
733740
min max
734741
1 1 2
735742
2 3 4
736-
737-
See Also
738-
--------
739-
pandas.Series.groupby.apply
740-
pandas.Series.groupby.transform
741-
pandas.Series.aggregate
742-
743743
""")
744744

745745
@Appender(_apply_docs['template']
@@ -748,11 +748,12 @@ def _selection_name(self):
748748
def apply(self, func, *args, **kwargs):
749749
return super(SeriesGroupBy, self).apply(func, *args, **kwargs)
750750

751-
@Appender(_agg_doc)
752-
@Appender(_shared_docs['aggregate'] % dict(
753-
klass='Series',
754-
versionadded='',
755-
axis=''))
751+
@Substitution(see_also=_agg_see_also_doc,
752+
examples=_agg_examples_doc,
753+
versionadded='',
754+
klass='Series',
755+
axis='')
756+
@Appender(_shared_docs['aggregate'])
756757
def aggregate(self, func_or_funcs, *args, **kwargs):
757758
_level = kwargs.pop('_level', None)
758759
if isinstance(func_or_funcs, compat.string_types):
@@ -1246,7 +1247,15 @@ class DataFrameGroupBy(NDFrameGroupBy):
12461247

12471248
_block_agg_axis = 1
12481249

1249-
_agg_doc = dedent("""
1250+
_agg_see_also_doc = dedent("""
1251+
See Also
1252+
--------
1253+
pandas.DataFrame.groupby.apply
1254+
pandas.DataFrame.groupby.transform
1255+
pandas.DataFrame.aggregate
1256+
""")
1257+
1258+
_agg_examples_doc = dedent("""
12501259
Examples
12511260
--------
12521261
@@ -1294,19 +1303,14 @@ class DataFrameGroupBy(NDFrameGroupBy):
12941303
A
12951304
1 1 2 0.590716
12961305
2 3 4 0.704907
1297-
1298-
See Also
1299-
--------
1300-
pandas.DataFrame.groupby.apply
1301-
pandas.DataFrame.groupby.transform
1302-
pandas.DataFrame.aggregate
13031306
""")
13041307

1305-
@Appender(_agg_doc)
1306-
@Appender(_shared_docs['aggregate'] % dict(
1307-
klass='DataFrame',
1308-
versionadded='',
1309-
axis=''))
1308+
@Substitution(see_also=_agg_see_also_doc,
1309+
examples=_agg_examples_doc,
1310+
versionadded='',
1311+
klass='DataFrame',
1312+
axis='')
1313+
@Appender(_shared_docs['aggregate'])
13101314
def aggregate(self, arg, *args, **kwargs):
13111315
return super(DataFrameGroupBy, self).aggregate(arg, *args, **kwargs)
13121316

0 commit comments

Comments
 (0)