|
29 | 29 | from pandas.compat import set_function_name
|
30 | 30 | from pandas.compat.numpy import function as nv
|
31 | 31 | from pandas.errors import AbstractMethodError
|
32 |
| -from pandas.util._decorators import cache_readonly |
| 32 | +from pandas.util._decorators import ( |
| 33 | + cache_readonly, |
| 34 | +) |
33 | 35 | from pandas.util._validators import (
|
34 | 36 | validate_bool_kwarg,
|
35 | 37 | validate_insert_loc,
|
@@ -1623,6 +1625,48 @@ def factorize(
|
1623 | 1625 | uniques_ea = self._from_factorized(uniques, self)
|
1624 | 1626 | return codes, uniques_ea
|
1625 | 1627 |
|
| 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 | + |
1626 | 1670 | def repeat(self, repeats: int | Sequence[int], axis: AxisInt | None = None) -> Self:
|
1627 | 1671 | """
|
1628 | 1672 | Repeat elements of an ExtensionArray.
|
|
0 commit comments