From 66eac112800cd229c4d29c59f3916d645d0a7752 Mon Sep 17 00:00:00 2001 From: rotuna Date: Sat, 26 Jan 2019 18:41:47 +0530 Subject: [PATCH 1/4] [DOC] Fix issues with DataFrame.aggregate page Fixed some formatting issues. Description was gettign rendered in the wrong location. Moved a line from generic.py to frame.py to help with the rendering. Moved the description being clubbed with see also to doc string with the function declaration in frame.py --- pandas/core/frame.py | 25 ++++++++++++++----------- pandas/core/generic.py | 11 +++++------ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b4f79bda25517..942546920e4d7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6224,16 +6224,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. @@ -6280,12 +6271,24 @@ def _gotitem(self, dtype: float64 """) - @Substitution(see_also=_agg_summary_and_see_also_doc, + @Substitution(see_also=_agg_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): + """ + Aggregate using one or more operations over the specified axis. + + 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)``. + + """ + axis = self._get_axis_number(axis) result = None diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2b97661fe9ec3..066b6276887e2 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4911,8 +4911,7 @@ def pipe(self, func, *args, **kwargs): return com._pipe(self, func, *args, **kwargs) _shared_docs['aggregate'] = dedent(""" - Aggregate using one or more operations over the specified axis. - + %(versionadded)s Parameters @@ -4936,10 +4935,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 + - 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 From 9fc48fae1eec359c39543c3018bb39c0ff3e862c Mon Sep 17 00:00:00 2001 From: rotuna Date: Sat, 26 Jan 2019 19:00:02 +0530 Subject: [PATCH 2/4] Fix pep8 issues --- pandas/core/frame.py | 15 +++++++-------- pandas/core/generic.py | 1 - 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 942546920e4d7..ecc389c2fb572 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6277,16 +6277,15 @@ def _gotitem(self, **_shared_doc_kwargs) @Appender(_shared_docs['aggregate']) def aggregate(self, func, axis=0, *args, **kwargs): - """ + """ Aggregate using one or more operations over the specified axis. - - The aggregation operations are always performed over an axis, either the - index (default) or the column axis. This behavior is different from + + 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)``. - + `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)``. """ axis = self._get_axis_number(axis) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 066b6276887e2..426bea8402ecd 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4911,7 +4911,6 @@ def pipe(self, func, *args, **kwargs): return com._pipe(self, func, *args, **kwargs) _shared_docs['aggregate'] = dedent(""" - %(versionadded)s Parameters From 4782f0495585d3146d2ee0b80a24dfd088f9d0a7 Mon Sep 17 00:00:00 2001 From: rotuna Date: Sat, 26 Jan 2019 21:41:51 +0530 Subject: [PATCH 3/4] Fix SS04 issue found in azure --- pandas/core/frame.py | 11 ----------- pandas/core/generic.py | 9 +++++++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ecc389c2fb572..caa88c743fd44 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6277,17 +6277,6 @@ def _gotitem(self, **_shared_doc_kwargs) @Appender(_shared_docs['aggregate']) def aggregate(self, func, axis=0, *args, **kwargs): - """ - Aggregate using one or more operations over the specified axis. - - 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)``. - """ - axis = self._get_axis_number(axis) result = None diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 426bea8402ecd..b26dc2e0a0860 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4911,6 +4911,15 @@ def pipe(self, func, *args, **kwargs): return com._pipe(self, func, *args, **kwargs) _shared_docs['aggregate'] = dedent(""" + Aggregate using one or more operations over the specified axis. + + 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)``. + %(versionadded)s Parameters From 92dd88e8ffd76d48ea460947c4f4d230d6931a25 Mon Sep 17 00:00:00 2001 From: rotuna Date: Sun, 27 Jan 2019 10:14:20 +0530 Subject: [PATCH 4/4] Added "summary" to page template The summary intended for DataFrame.aggregate was not rendered properly. Added a summary variable in the aggregate template in generic.py. Added an empty summary in all pages using the shared doc. --- pandas/core/frame.py | 12 +++++++++++- pandas/core/generic.py | 7 +------ pandas/core/groupby/generic.py | 6 ++++-- pandas/core/resample.py | 3 ++- pandas/core/series.py | 3 ++- pandas/core/window.py | 12 ++++++++---- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index caa88c743fd44..86d3c23e8a826 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6270,8 +6270,18 @@ def _gotitem(self, 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_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) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b26dc2e0a0860..19c6c801374fc 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4913,12 +4913,7 @@ def pipe(self, func, *args, **kwargs): _shared_docs['aggregate'] = dedent(""" Aggregate using one or more operations over the specified axis. - 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)``. + %(summary)s %(versionadded)s diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index c5142a4ee98cc..ca7635db184db 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -748,7 +748,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', @@ -1305,7 +1306,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', diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 6822225273906..12fb5d06b2525 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -256,7 +256,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', diff --git a/pandas/core/series.py b/pandas/core/series.py index 0c8e697c572e8..13fb63981d9e0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3424,7 +3424,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) diff --git a/pandas/core/window.py b/pandas/core/window.py index 5a9157b43ecd6..b627baeeeada3 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -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', @@ -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', @@ -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', @@ -2258,7 +2261,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',