Skip to content

[DOC] Fix issues with DataFrame.aggregate page #24948

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 12 additions & 11 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6172,16 +6172,7 @@ def _gotitem(self,
# TODO: _shallow_copy(subset)?
return subset[key]

_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`,
`var`), where the default is to compute the aggregation of the flattened
array, e.g., ``numpy.mean(arr_2d)`` as opposed to ``numpy.mean(arr_2d,
axis=0)``.

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

_agg_see_also_doc = dedent("""
See Also
--------
DataFrame.apply : Perform any type of operations.
Expand Down Expand Up @@ -6226,9 +6217,19 @@ def _gotitem(self,
2 8.0
3 NaN
dtype: float64
""")
_agg_summary = 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`,
`var`), where the default is to compute the aggregation of the
flattened array, e.g., ``numpy.mean(arr_2d)`` as opposed to
``numpy.mean(arr_2d, axis=0)``.

""")

@Substitution(see_also=_agg_summary_and_see_also_doc,
@Substitution(summary=_agg_summary,
see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='.. versionadded:: 0.20.0',
**_shared_doc_kwargs)
Expand Down
10 changes: 6 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4926,6 +4926,8 @@ def pipe(self, func, *args, **kwargs):
_shared_docs['aggregate'] = dedent("""
Aggregate using one or more operations over the specified axis.

%(summary)s

%(versionadded)s

Parameters
Expand All @@ -4949,10 +4951,10 @@ def pipe(self, func, *args, **kwargs):
Returns
-------
DataFrame, Series or scalar
If DataFrame.agg is called with a single function, returns a Series
If DataFrame.agg is called with several functions, returns a DataFrame
If Series.agg is called with single function, returns a scalar
If Series.agg is called with several functions, returns a Series.
- If DataFrame.agg is called with a single function, returns a Series
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use asterisks here instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think this will fail once #25132 gets merged. Give that a look to see how to handle

- If DataFrame.agg is called with several functions, returns a DataFrame
- 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

Expand Down
6 changes: 4 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ def _selection_name(self):
def apply(self, func, *args, **kwargs):
return super(SeriesGroupBy, self).apply(func, *args, **kwargs)

@Substitution(see_also=_agg_see_also_doc,
@Substitution(summary='',
see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='',
klass='Series',
Expand Down Expand Up @@ -1306,7 +1307,8 @@ class DataFrameGroupBy(NDFrameGroupBy):
2 3 4 0.704907
""")

@Substitution(see_also=_agg_see_also_doc,
@Substitution(summary='',
see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='',
klass='DataFrame',
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ def pipe(self, func, *args, **kwargs):
2013-01-01 00:00:04 5 NaN
""")

@Substitution(see_also=_agg_see_also_doc,
@Substitution(summary='',
see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='',
klass='DataFrame',
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3492,7 +3492,8 @@ def _gotitem(self, key, ndim, subset=None):
dtype: int64
""")

@Substitution(see_also=_agg_see_also_doc,
@Substitution(summary='',
see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='.. versionadded:: 0.20.0',
**_shared_doc_kwargs)
Expand Down
12 changes: 8 additions & 4 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,8 @@ def f(arg, *args, **kwargs):
9 0.070889 0.134399 -0.031308
""")

@Substitution(see_also=_agg_see_also_doc,
@Substitution(summary='',
see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='',
klass='Series/DataFrame',
Expand Down Expand Up @@ -1675,7 +1676,8 @@ def _validate_freq(self):
9 0.212668 -1.647453
""")

@Substitution(see_also=_agg_see_also_doc,
@Substitution(summary='',
see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='',
klass='Series/Dataframe',
Expand Down Expand Up @@ -1953,7 +1955,8 @@ def _get_window(self, other=None):
9 -0.286980 0.618493 -0.694496
""")

@Substitution(see_also=_agg_see_also_doc,
@Substitution(summary='',
see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='',
klass='Series/Dataframe',
Expand Down Expand Up @@ -2265,7 +2268,8 @@ def _constructor(self):
9 -0.286980 0.618493 -0.694496
""")

@Substitution(see_also=_agg_see_also_doc,
@Substitution(summary='',
see_also=_agg_see_also_doc,
examples=_agg_examples_doc,
versionadded='',
klass='Series/Dataframe',
Expand Down