From 9ed49eb936f2dcbe824a91fa1339647f052f73f3 Mon Sep 17 00:00:00 2001 From: Jeremy Schendel Date: Wed, 26 Dec 2018 17:06:15 -0700 Subject: [PATCH] API: Simplify repeat signature (#24447) --- pandas/core/arrays/base.py | 13 +++++-------- pandas/core/arrays/categorical.py | 4 ++-- pandas/core/arrays/interval.py | 4 ++-- pandas/core/indexes/base.py | 13 +++++-------- pandas/core/indexes/datetimelike.py | 4 ++-- pandas/core/indexes/multi.py | 4 ++-- pandas/core/series.py | 13 +++++-------- 7 files changed, 23 insertions(+), 32 deletions(-) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index ef80c42c59ccb..739c8174c7d87 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -605,12 +605,9 @@ def factorize(self, na_sentinel=-1): The number of repetitions for each element. This should be a non-negative integer. Repeating 0 times will return an empty %(klass)s. - *args - Additional arguments have no effect but might be accepted for - compatibility with numpy. - **kwargs - Additional keywords have no effect but might be accepted for - compatibility with numpy. + axis : None + Must be ``None``. Has no effect but is accepted for compatibility + with numpy. Returns ------- @@ -640,8 +637,8 @@ def factorize(self, na_sentinel=-1): @Substitution(klass='ExtensionArray') @Appender(_extension_array_shared_docs['repeat']) - def repeat(self, repeats, *args, **kwargs): - nv.validate_repeat(args, kwargs) + def repeat(self, repeats, axis=None): + nv.validate_repeat(tuple(), dict(axis=axis)) ind = np.arange(len(self)).repeat(repeats) return self.take(ind) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 86900c7d6b7b2..4c5883f9a8022 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -2402,8 +2402,8 @@ def describe(self): @Substitution(klass='Categorical') @Appender(_extension_array_shared_docs['repeat']) - def repeat(self, repeats, *args, **kwargs): - nv.validate_repeat(args, kwargs) + def repeat(self, repeats, axis=None): + nv.validate_repeat(tuple(), dict(axis=axis)) codes = self._codes.repeat(repeats) return self._constructor(values=codes, dtype=self.dtype, fastpath=True) diff --git a/pandas/core/arrays/interval.py b/pandas/core/arrays/interval.py index d67645c8b4451..1f74a2cb143c8 100644 --- a/pandas/core/arrays/interval.py +++ b/pandas/core/arrays/interval.py @@ -1002,8 +1002,8 @@ def to_tuples(self, na_tuple=True): return tuples @Appender(_extension_array_shared_docs['repeat'] % _shared_docs_kwargs) - def repeat(self, repeats, *args, **kwargs): - nv.validate_repeat(args, kwargs) + def repeat(self, repeats, axis=None): + nv.validate_repeat(tuple(), dict(axis=axis)) left_repeat = self.left.repeat(repeats) right_repeat = self.right.repeat(repeats) return self._shallow_copy(left=left_repeat, right=right_repeat) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fd0c904ba2245..2f29561af943b 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -846,12 +846,9 @@ def _assert_take_fillable(self, values, indices, allow_fill=True, The number of repetitions for each element. This should be a non-negative integer. Repeating 0 times will return an empty %(klass)s. - *args - Additional arguments have no effect but might be accepted for - compatibility with numpy. - **kwargs - Additional keywords have no effect but might be accepted for - compatibility with numpy. + axis : None + Must be ``None``. Has no effect but is accepted for compatibility + with numpy. Returns ------- @@ -875,8 +872,8 @@ def _assert_take_fillable(self, values, indices, allow_fill=True, """ @Appender(_index_shared_docs['repeat'] % _index_doc_kwargs) - def repeat(self, repeats, *args, **kwargs): - nv.validate_repeat(args, kwargs) + def repeat(self, repeats, axis=None): + nv.validate_repeat(tuple(), dict(axis=axis)) return self._shallow_copy(self._values.repeat(repeats)) # -------------------------------------------------------------------- diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 8a319a65314dd..e3d24bfbed7c3 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -451,8 +451,8 @@ def isin(self, values): return algorithms.isin(self.asi8, values.asi8) @Appender(_index_shared_docs['repeat'] % _index_doc_kwargs) - def repeat(self, repeats, *args, **kwargs): - nv.validate_repeat(args, kwargs) + def repeat(self, repeats, axis=None): + nv.validate_repeat(tuple(), dict(axis=axis)) freq = self.freq if is_period_dtype(self) else None return self._shallow_copy(self.asi8.repeat(repeats), freq=freq) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index ef4a85e964cad..60059d5a43440 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1858,8 +1858,8 @@ def argsort(self, *args, **kwargs): return self.values.argsort(*args, **kwargs) @Appender(_index_shared_docs['repeat'] % _index_doc_kwargs) - def repeat(self, repeats, *args, **kwargs): - nv.validate_repeat(args, kwargs) + def repeat(self, repeats, axis=None): + nv.validate_repeat(tuple(), dict(axis=axis)) return MultiIndex(levels=self.levels, codes=[level_codes.view(np.ndarray).repeat(repeats) for level_codes in self.codes], diff --git a/pandas/core/series.py b/pandas/core/series.py index 4a8759c88fa6e..84b81e29cb8a8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1037,7 +1037,7 @@ def _set_values(self, key, value): self._data = self._data.setitem(indexer=key, value=value) self._maybe_update_cacher() - def repeat(self, repeats, *args, **kwargs): + def repeat(self, repeats, axis=None): """ Repeat elements of a Series. @@ -1050,12 +1050,9 @@ def repeat(self, repeats, *args, **kwargs): The number of repetitions for each element. This should be a non-negative integer. Repeating 0 times will return an empty Series. - *args - Additional arguments have no effect but might be accepted for - compatibility with numpy. - **kwargs - Additional keywords have no effect but might be accepted for - compatibility with numpy. + axis : None + Must be ``None``. Has no effect but is accepted for compatibility + with numpy. Returns ------- @@ -1092,7 +1089,7 @@ def repeat(self, repeats, *args, **kwargs): 2 c dtype: object """ - nv.validate_repeat(args, kwargs) + nv.validate_repeat(tuple(), dict(axis=axis)) new_index = self.index.repeat(repeats) new_values = self._values.repeat(repeats) return self._constructor(new_values,