Skip to content

Commit ba6df36

Browse files
committed
DOC: inline docstring for ExtensionArray.repeat; remove Substitution/Appender
DOC: restore shared 'repeat' template; keep inline docstring for ExtensionArray.repeat
1 parent e97a56e commit ba6df36

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

pandas/core/arrays/base.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
from pandas.compat.numpy import function as nv
3131
from pandas.errors import AbstractMethodError
3232
from pandas.util._decorators import (
33-
Appender,
34-
Substitution,
3533
cache_readonly,
3634
)
3735
from pandas.util._validators import (
@@ -1669,9 +1667,48 @@ def factorize(
16691667
Categories (3, str): ['a', 'b', 'c']
16701668
"""
16711669

1672-
@Substitution(klass="ExtensionArray")
1673-
@Appender(_extension_array_shared_docs["repeat"])
16741670
def repeat(self, repeats: int | Sequence[int], axis: AxisInt | None = None) -> Self:
1671+
"""
1672+
Repeat elements of an ExtensionArray.
1673+
1674+
Returns a new ExtensionArray where each element of the current ExtensionArray
1675+
is repeated consecutively a given number of times.
1676+
1677+
Parameters
1678+
----------
1679+
repeats : int or array of ints
1680+
The number of repetitions for each element. This should be a
1681+
non-negative integer. Repeating 0 times will return an empty
1682+
ExtensionArray.
1683+
axis : None
1684+
Must be ``None``. Has no effect but is accepted for compatibility
1685+
with numpy.
1686+
1687+
Returns
1688+
-------
1689+
ExtensionArray
1690+
Newly created ExtensionArray with repeated elements.
1691+
1692+
See Also
1693+
--------
1694+
Series.repeat : Equivalent function for Series.
1695+
Index.repeat : Equivalent function for Index.
1696+
numpy.repeat : Similar method for :class:`numpy.ndarray`.
1697+
ExtensionArray.take : Take arbitrary positions.
1698+
1699+
Examples
1700+
--------
1701+
>>> cat = pd.Categorical(["a", "b", "c"])
1702+
>>> cat
1703+
['a', 'b', 'c']
1704+
Categories (3, str): ['a', 'b', 'c']
1705+
>>> cat.repeat(2)
1706+
['a', 'a', 'b', 'b', 'c', 'c']
1707+
Categories (3, str): ['a', 'b', 'c']
1708+
>>> cat.repeat([1, 2, 3])
1709+
['a', 'b', 'b', 'c', 'c', 'c']
1710+
Categories (3, str): ['a', 'b', 'c']
1711+
"""
16751712
nv.validate_repeat((), {"axis": axis})
16761713
ind = np.arange(len(self)).repeat(repeats)
16771714
return self.take(ind)

0 commit comments

Comments
 (0)