Skip to content

Commit 75eb02e

Browse files
committed
DOC: restore shared 'repeat' template; keep inline docstring for ExtensionArray.repeat
1 parent 67c24ad commit 75eb02e

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

pandas/core/arrays/base.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
from pandas.compat import set_function_name
3030
from pandas.compat.numpy import function as nv
3131
from pandas.errors import AbstractMethodError
32-
from pandas.util._decorators import cache_readonly
32+
from pandas.util._decorators import (
33+
cache_readonly,
34+
)
3335
from pandas.util._validators import (
3436
validate_bool_kwarg,
3537
validate_insert_loc,
@@ -1623,6 +1625,48 @@ def factorize(
16231625
uniques_ea = self._from_factorized(uniques, self)
16241626
return codes, uniques_ea
16251627

1628+
_extension_array_shared_docs["repeat"] = """
1629+
Repeat elements of a %(klass)s.
1630+
1631+
Returns a new %(klass)s where each element of the current %(klass)s
1632+
is repeated consecutively a given number of times.
1633+
1634+
Parameters
1635+
----------
1636+
repeats : int or array of ints
1637+
The number of repetitions for each element. This should be a
1638+
non-negative integer. Repeating 0 times will return an empty
1639+
%(klass)s.
1640+
axis : None
1641+
Must be ``None``. Has no effect but is accepted for compatibility
1642+
with numpy.
1643+
1644+
Returns
1645+
-------
1646+
%(klass)s
1647+
Newly created %(klass)s with repeated elements.
1648+
1649+
See Also
1650+
--------
1651+
Series.repeat : Equivalent function for Series.
1652+
Index.repeat : Equivalent function for Index.
1653+
numpy.repeat : Similar method for :class:`numpy.ndarray`.
1654+
ExtensionArray.take : Take arbitrary positions.
1655+
1656+
Examples
1657+
--------
1658+
>>> cat = pd.Categorical(['a', 'b', 'c'])
1659+
>>> cat
1660+
['a', 'b', 'c']
1661+
Categories (3, str): ['a', 'b', 'c']
1662+
>>> cat.repeat(2)
1663+
['a', 'a', 'b', 'b', 'c', 'c']
1664+
Categories (3, str): ['a', 'b', 'c']
1665+
>>> cat.repeat([1, 2, 3])
1666+
['a', 'b', 'b', 'c', 'c', 'c']
1667+
Categories (3, str): ['a', 'b', 'c']
1668+
"""
1669+
16261670
def repeat(self, repeats: int | Sequence[int], axis: AxisInt | None = None) -> Self:
16271671
"""
16281672
Repeat elements of an ExtensionArray.

0 commit comments

Comments
 (0)