Skip to content

Commit

Permalink
API: Simplify repeat signature (#24447)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschendel authored and jreback committed Dec 27, 2018
1 parent 9fa063e commit 9ed49eb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 32 deletions.
13 changes: 5 additions & 8 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 5 additions & 8 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand All @@ -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))

# --------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
13 changes: 5 additions & 8 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
-------
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9ed49eb

Please sign in to comment.