From 1a7247adbff6fcfc7263224bb7fc31fffb387e55 Mon Sep 17 00:00:00 2001 From: Krishna Date: Tue, 23 Oct 2018 15:57:57 +0100 Subject: [PATCH 1/6] DOC: Added multi-indexed example for series.max --- pandas/core/generic.py | 44 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 31b700abcfdb3..ea31fcdf2cb86 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9362,7 +9362,7 @@ def compound(self, axis=None, skipna=None, level=None): """This method returns the maximum of the values in the object. If you want the *index* of the maximum, use ``idxmax``. This is the equivalent of the ``numpy.ndarray`` method ``argmax``.""", - nanops.nanmax) + nanops.nanmax, _max_examples) cls.min = _make_stat_function( cls, 'min', name, name2, axis_descr, """This method returns the minimum of the values in the object. @@ -10210,6 +10210,44 @@ def _doc_parms(cls): nan """ +_max_examples = """\ +Examples +-------- +``MultiIndex`` series example of monthly rainfall + +>>> index = [np.tile(['London', 'New York'], 3), +... np.repeat(['Jun', 'Jul', 'Aug'], 2)] +>>> s = pd.Series([47, 112, 35, 117, 54, 113], index=index) +>>> s.rename_axis(['city', 'month'], inplace=True) +>>> s +city month +London Jun 47 +New York Jun 112 +London Jul 35 +New York Jul 117 +London Aug 54 +New York Aug 113 +dtype: int64 + +>>> s.max() +117 + +Sum using level names, as well as indices + +>>> s.max(level='city') +city +London 54 +New York 117 +dtype: int64 + +>>> s.max(level=1) +month +Jun 112 +Jul 117 +Aug 113 +dtype: int64 +""" + _min_count_stub = """\ min_count : int, default 0 @@ -10247,9 +10285,9 @@ def stat_func(self, axis=None, skipna=None, level=None, numeric_only=None, return set_function_name(stat_func, name, cls) -def _make_stat_function(cls, name, name1, name2, axis_descr, desc, f): +def _make_stat_function(cls, name, name1, name2, axis_descr, desc, f, examples=''): @Substitution(outname=name, desc=desc, name1=name1, name2=name2, - axis_descr=axis_descr, min_count='', examples='') + axis_descr=axis_descr, min_count='', examples=examples) @Appender(_num_doc) def stat_func(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): From 29f788753ed648305de22005980c889415b7a838 Mon Sep 17 00:00:00 2001 From: Krishna Date: Tue, 23 Oct 2018 16:02:12 +0100 Subject: [PATCH 2/6] DOC: truncated line for PEP compliance --- pandas/core/generic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ea31fcdf2cb86..65aca38a809ed 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10285,7 +10285,8 @@ def stat_func(self, axis=None, skipna=None, level=None, numeric_only=None, return set_function_name(stat_func, name, cls) -def _make_stat_function(cls, name, name1, name2, axis_descr, desc, f, examples=''): +def _make_stat_function(cls, name, name1, name2, axis_descr, desc, f, + examples=''): @Substitution(outname=name, desc=desc, name1=name1, name2=name2, axis_descr=axis_descr, min_count='', examples=examples) @Appender(_num_doc) From d09fa157419ea3c35fea11791832cf20b5211051 Mon Sep 17 00:00:00 2001 From: Krishna Date: Thu, 25 Oct 2018 14:05:12 +0100 Subject: [PATCH 3/6] DOC: Typo corrected. --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 65aca38a809ed..f4ea28c891e2e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10232,7 +10232,7 @@ def _doc_parms(cls): >>> s.max() 117 -Sum using level names, as well as indices +Max using level names, as well as indices >>> s.max(level='city') city From 6deac4acb4d5a253d5dfe1522dbab7ccc818960b Mon Sep 17 00:00:00 2001 From: Krishna Date: Thu, 25 Oct 2018 15:06:59 +0100 Subject: [PATCH 4/6] DOC: Restructured indexing as requested. --- pandas/core/generic.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f4ea28c891e2e..d6328ea80c592 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10215,10 +10215,11 @@ def _doc_parms(cls): -------- ``MultiIndex`` series example of monthly rainfall ->>> index = [np.tile(['London', 'New York'], 3), -... np.repeat(['Jun', 'Jul', 'Aug'], 2)] +>>> index = pd.MultiIndex.from_arrays( +... [np.tile(['London', 'New York'], 3), +... np.repeat(['Jun', 'Jul', 'Aug'], 2)], +... names=['city', 'month']) >>> s = pd.Series([47, 112, 35, 117, 54, 113], index=index) ->>> s.rename_axis(['city', 'month'], inplace=True) >>> s city month London Jun 47 From e69359282fd5ddb9bff2817613564e91ae25e875 Mon Sep 17 00:00:00 2001 From: Krishna Date: Thu, 25 Oct 2018 16:26:31 +0100 Subject: [PATCH 5/6] DOC: Switched from MultiIndex.from_arrays to MultiIndex.from_product --- pandas/core/generic.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d6328ea80c592..4a3c4630911ea 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10215,19 +10215,18 @@ def _doc_parms(cls): -------- ``MultiIndex`` series example of monthly rainfall ->>> index = pd.MultiIndex.from_arrays( -... [np.tile(['London', 'New York'], 3), -... np.repeat(['Jun', 'Jul', 'Aug'], 2)], -... names=['city', 'month']) ->>> s = pd.Series([47, 112, 35, 117, 54, 113], index=index) +>>> index = pd.MultiIndex.from_product( +... [['London', 'New York'], ['Jun', 'Jul', 'Aug']], +... names=['city', 'month']) +>>> s = pd.Series([47, 35, 54, 112, 117, 113], index=index) >>> s city month London Jun 47 + Jul 35 + Aug 54 New York Jun 112 -London Jul 35 -New York Jul 117 -London Aug 54 -New York Aug 113 + Jul 117 + Aug 113 dtype: int64 >>> s.max() From 49b633023e60d7a6931b758a21bf473023d0d4d2 Mon Sep 17 00:00:00 2001 From: Krishna Date: Thu, 25 Oct 2018 16:44:52 +0100 Subject: [PATCH 6/6] DOC: Reformatting --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4a3c4630911ea..0dcd46fc11475 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10216,8 +10216,8 @@ def _doc_parms(cls): ``MultiIndex`` series example of monthly rainfall >>> index = pd.MultiIndex.from_product( -... [['London', 'New York'], ['Jun', 'Jul', 'Aug']], -... names=['city', 'month']) +... [['London', 'New York'], ['Jun', 'Jul', 'Aug']], +... names=['city', 'month']) >>> s = pd.Series([47, 35, 54, 112, 117, 113], index=index) >>> s city month