Skip to content

DOC: Fix docstrings with the sections in the wrong order #24280 #24288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ fi
### DOCSTRINGS ###
if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then

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

fi
Expand Down
35 changes: 19 additions & 16 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6037,7 +6037,7 @@ def _gotitem(self,
# TODO: _shallow_copy(subset)?
return subset[key]

_agg_doc = dedent("""
_agg_summary_and_see_also_doc = dedent("""
The aggregation operations are always performed over an axis, either the
index (default) or the column axis. This behavior is different from
`numpy` aggregation functions (`mean`, `median`, `prod`, `sum`, `std`,
Expand All @@ -6047,6 +6047,19 @@ def _gotitem(self,

`agg` is an alias for `aggregate`. Use the alias.

See Also
--------
DataFrame.apply : Perform any type of operations.
DataFrame.transform : Perform transformation type operations.
pandas.core.groupby.GroupBy : Perform operations over groups.
pandas.core.resample.Resampler : Perform operations over resampled bins.
pandas.core.window.Rolling : Perform operations over rolling window.
pandas.core.window.Expanding : Perform operations over expanding window.
pandas.core.window.EWM : Perform operation over exponential weighted
window.
""")

_agg_examples_doc = dedent("""
Examples
--------
>>> df = pd.DataFrame([[1, 2, 3],
Expand Down Expand Up @@ -6078,23 +6091,13 @@ def _gotitem(self,
2 8.0
3 NaN
dtype: float64

See Also
--------
DataFrame.apply : Perform any type of operations.
DataFrame.transform : Perform transformation type operations.
pandas.core.groupby.GroupBy : Perform operations over groups.
pandas.core.resample.Resampler : Perform operations over resampled bins.
pandas.core.window.Rolling : Perform operations over rolling window.
pandas.core.window.Expanding : Perform operations over expanding window.
pandas.core.window.EWM : Perform operation over exponential weighted
window.
""")

@Appender(_agg_doc)
@Appender(_shared_docs['aggregate'] % dict(
versionadded='.. versionadded:: 0.20.0',
**_shared_doc_kwargs))
@Substitution(see_also=_agg_summary_and_see_also_doc,
examples=_agg_examples_doc,
versionadded='.. versionadded:: 0.20.0',
**_shared_doc_kwargs)
@Appender(_shared_docs['aggregate'])
def aggregate(self, func, axis=0, *args, **kwargs):
axis = self._get_axis_number(axis)

Expand Down
7 changes: 6 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gc
import json
import operator
from textwrap import dedent
import warnings
import weakref

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

_shared_docs['aggregate'] = ("""
_shared_docs['aggregate'] = dedent("""
Aggregate using one or more operations over the specified axis.

%(versionadded)s
Expand Down Expand Up @@ -4926,11 +4927,15 @@ def pipe(self, func, *args, **kwargs):
if Series.agg is called with single function, returns a scalar
if Series.agg is called with several functions, returns a Series

%(see_also)s

Notes
-----
`agg` is an alias for `aggregate`. Use the alias.

A passed user-defined-function will be passed a Series for evaluation.

%(examples)s
""")

_shared_docs['transform'] = ("""
Expand Down
56 changes: 30 additions & 26 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,17 @@ def _selection_name(self):
else:
return self._selection

_agg_doc = dedent("""
Examples
_agg_see_also_doc = dedent("""
See Also
--------
pandas.Series.groupby.apply
pandas.Series.groupby.transform
pandas.Series.aggregate
""")

_agg_examples_doc = dedent("""
Examples
--------
>>> s = pd.Series([1, 2, 3, 4])

>>> s
Expand All @@ -733,13 +740,6 @@ def _selection_name(self):
min max
1 1 2
2 3 4

See Also
--------
pandas.Series.groupby.apply
pandas.Series.groupby.transform
pandas.Series.aggregate

""")

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

@Appender(_agg_doc)
@Appender(_shared_docs['aggregate'] % dict(
klass='Series',
versionadded='',
axis=''))
@Substitution(see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='',
klass='Series',
axis='')
@Appender(_shared_docs['aggregate'])
def aggregate(self, func_or_funcs, *args, **kwargs):
_level = kwargs.pop('_level', None)
if isinstance(func_or_funcs, compat.string_types):
Expand Down Expand Up @@ -1246,7 +1247,15 @@ class DataFrameGroupBy(NDFrameGroupBy):

_block_agg_axis = 1

_agg_doc = dedent("""
_agg_see_also_doc = dedent("""
See Also
--------
pandas.DataFrame.groupby.apply
pandas.DataFrame.groupby.transform
pandas.DataFrame.aggregate
""")

_agg_examples_doc = dedent("""
Examples
--------

Expand Down Expand Up @@ -1294,19 +1303,14 @@ class DataFrameGroupBy(NDFrameGroupBy):
A
1 1 2 0.590716
2 3 4 0.704907

See Also
--------
pandas.DataFrame.groupby.apply
pandas.DataFrame.groupby.transform
pandas.DataFrame.aggregate
""")

@Appender(_agg_doc)
@Appender(_shared_docs['aggregate'] % dict(
klass='DataFrame',
versionadded='',
axis=''))
@Substitution(see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='',
klass='DataFrame',
axis='')
@Appender(_shared_docs['aggregate'])
def aggregate(self, arg, *args, **kwargs):
return super(DataFrameGroupBy, self).aggregate(arg, *args, **kwargs)

Expand Down
Loading