From 3e334066151cfa8be6274ad06bdc7ea300b1814d Mon Sep 17 00:00:00 2001 From: Aly Sivji Date: Sun, 4 Mar 2018 14:40:44 -0600 Subject: [PATCH 1/7] Fix docstring --- pandas/core/indexes/base.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 0813c12d573d5..d60963d814c4a 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -695,13 +695,31 @@ def memory_usage(self, deep=False): # ops compat @deprecate_kwarg(old_arg_name='n', new_arg_name='repeats') def repeat(self, repeats, *args, **kwargs): - """ - Repeat elements of an Index. Refer to `numpy.ndarray.repeat` - for more information about the `repeats` argument. + """Repeat elements of an Index. + + Parameters + ---------- + repeats : int + The number of repetitions for each element. + + Returns + ------- + pandas.Index + Newly created Index with repeated elements. See also -------- numpy.ndarray.repeat + + Examples + -------- + >>> idx = pd.Index([1, 2, 3]) + >>> idx + Int64Index([1, 2, 3], dtype='int64') + >>> idx.repeat(2) + Int64Index([1, 1, 2, 2, 3, 3], dtype='int64') + >>> idx.repeat(3) + Int64Index([1, 1, 1, 2, 2, 2, 3, 3, 3], dtype='int64') """ nv.validate_repeat(args, kwargs) return self._shallow_copy(self._values.repeat(repeats)) From 1fc4b33fab0404ef28fa2790a3523b729eea388d Mon Sep 17 00:00:00 2001 From: Aly Sivji Date: Sun, 4 Mar 2018 17:01:25 -0600 Subject: [PATCH 2/7] Update location of underlying numpy function --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index d60963d814c4a..ba319c9fc0d76 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -709,7 +709,7 @@ def repeat(self, repeats, *args, **kwargs): See also -------- - numpy.ndarray.repeat + numpy.repeat Examples -------- From 52703630ef7d6de91e8b27aa1d0c7fd9ff30e06d Mon Sep 17 00:00:00 2001 From: Aly Sivji Date: Wed, 7 Mar 2018 08:05:45 -0600 Subject: [PATCH 3/7] Update with PR comments --- pandas/core/indexes/base.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ba319c9fc0d76..b7400035b9749 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -697,6 +697,10 @@ def memory_usage(self, deep=False): def repeat(self, repeats, *args, **kwargs): """Repeat elements of an Index. + Returns a new index where each element of the current index + is repeated consecutively a given number of times. Can be used + to create an index that quickly summarizes data (see Examples). + Parameters ---------- repeats : int @@ -707,9 +711,10 @@ def repeat(self, repeats, *args, **kwargs): pandas.Index Newly created Index with repeated elements. - See also + See Also -------- - numpy.repeat + Series.repeat : Equivalent function for Series + numpy.repeat : Underlying implementation Examples -------- @@ -720,6 +725,22 @@ def repeat(self, repeats, *args, **kwargs): Int64Index([1, 1, 2, 2, 3, 3], dtype='int64') >>> idx.repeat(3) Int64Index([1, 1, 1, 2, 2, 2, 3, 3, 3], dtype='int64') + + >>> idx = pd.Index([1, 2, 3]). repeat(2) + >>> df = pd.DataFrame([5, 6, 7, 3, 4, 1], index=idx) + >>> df + 0 + 1 5 + 1 6 + 2 7 + 2 3 + 3 4 + 3 1 + >>> df.groupby(level=0).mean() + 0 + 1 5.5 + 2 5.0 + 3 2.5 """ nv.validate_repeat(args, kwargs) return self._shallow_copy(self._values.repeat(repeats)) From d4fd5292a9cc1ea282a01aeca32e6ad69aaf84b6 Mon Sep 17 00:00:00 2001 From: Aly Sivji Date: Wed, 7 Mar 2018 08:29:41 -0600 Subject: [PATCH 4/7] Simplify docstring --- pandas/core/indexes/base.py | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b7400035b9749..e6d2be919f6f5 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -698,8 +698,7 @@ def repeat(self, repeats, *args, **kwargs): """Repeat elements of an Index. Returns a new index where each element of the current index - is repeated consecutively a given number of times. Can be used - to create an index that quickly summarizes data (see Examples). + is repeated consecutively a given number of times. Parameters ---------- @@ -725,22 +724,6 @@ def repeat(self, repeats, *args, **kwargs): Int64Index([1, 1, 2, 2, 3, 3], dtype='int64') >>> idx.repeat(3) Int64Index([1, 1, 1, 2, 2, 2, 3, 3, 3], dtype='int64') - - >>> idx = pd.Index([1, 2, 3]). repeat(2) - >>> df = pd.DataFrame([5, 6, 7, 3, 4, 1], index=idx) - >>> df - 0 - 1 5 - 1 6 - 2 7 - 2 3 - 3 4 - 3 1 - >>> df.groupby(level=0).mean() - 0 - 1 5.5 - 2 5.0 - 3 2.5 """ nv.validate_repeat(args, kwargs) return self._shallow_copy(self._values.repeat(repeats)) From 9a57c254f26b054eb040946213f3efb11499e636 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 8 Mar 2018 11:58:14 +0100 Subject: [PATCH 5/7] Update for change in the docstring guide --- pandas/core/indexes/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index e6d2be919f6f5..94f74cb72df20 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -695,7 +695,8 @@ def memory_usage(self, deep=False): # ops compat @deprecate_kwarg(old_arg_name='n', new_arg_name='repeats') def repeat(self, repeats, *args, **kwargs): - """Repeat elements of an Index. + """ + Repeat elements of an Index. Returns a new index where each element of the current index is repeated consecutively a given number of times. From cf4999ff0c7d52f0cabf464893e3cf41531d8b73 Mon Sep 17 00:00:00 2001 From: Aly Sivji Date: Thu, 8 Mar 2018 19:16:02 -0600 Subject: [PATCH 6/7] Add kwargs to parameters list --- pandas/core/indexes/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index e6d2be919f6f5..db86736c13bc9 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -704,6 +704,9 @@ def repeat(self, repeats, *args, **kwargs): ---------- repeats : int The number of repetitions for each element. + kwargs : keyword, value pairs + Additional keywords have no effect but might be accepted for + compatibility with numpy. Returns ------- From 84869696d87891cb673398a67419d940da27aad7 Mon Sep 17 00:00:00 2001 From: Aly Sivji Date: Thu, 8 Mar 2018 20:22:14 -0600 Subject: [PATCH 7/7] Fix keyword argument parameter in docstring --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 3ec57b424c338..880e283af9186 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -705,7 +705,7 @@ def repeat(self, repeats, *args, **kwargs): ---------- repeats : int The number of repetitions for each element. - kwargs : keyword, value pairs + **kwargs Additional keywords have no effect but might be accepted for compatibility with numpy.