From ba6df36b5002ecd58abdcf020d86b0f4d4ad3d7c Mon Sep 17 00:00:00 2001 From: Radu Scobioala Date: Mon, 29 Sep 2025 06:56:51 +0300 Subject: [PATCH] DOC: inline docstring for ExtensionArray.repeat; remove Substitution/Appender DOC: restore shared 'repeat' template; keep inline docstring for ExtensionArray.repeat --- pandas/core/arrays/base.py | 45 ++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 84ec38e2f75d1..fcd7611b3e6b5 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -30,8 +30,6 @@ from pandas.compat.numpy import function as nv from pandas.errors import AbstractMethodError from pandas.util._decorators import ( - Appender, - Substitution, cache_readonly, ) from pandas.util._validators import ( @@ -1669,9 +1667,48 @@ def factorize( Categories (3, str): ['a', 'b', 'c'] """ - @Substitution(klass="ExtensionArray") - @Appender(_extension_array_shared_docs["repeat"]) def repeat(self, repeats: int | Sequence[int], axis: AxisInt | None = None) -> Self: + """ + Repeat elements of an ExtensionArray. + + Returns a new ExtensionArray where each element of the current ExtensionArray + is repeated consecutively a given number of times. + + Parameters + ---------- + repeats : int or array of ints + The number of repetitions for each element. This should be a + non-negative integer. Repeating 0 times will return an empty + ExtensionArray. + axis : None + Must be ``None``. Has no effect but is accepted for compatibility + with numpy. + + Returns + ------- + ExtensionArray + Newly created ExtensionArray with repeated elements. + + See Also + -------- + Series.repeat : Equivalent function for Series. + Index.repeat : Equivalent function for Index. + numpy.repeat : Similar method for :class:`numpy.ndarray`. + ExtensionArray.take : Take arbitrary positions. + + Examples + -------- + >>> cat = pd.Categorical(["a", "b", "c"]) + >>> cat + ['a', 'b', 'c'] + Categories (3, str): ['a', 'b', 'c'] + >>> cat.repeat(2) + ['a', 'a', 'b', 'b', 'c', 'c'] + Categories (3, str): ['a', 'b', 'c'] + >>> cat.repeat([1, 2, 3]) + ['a', 'b', 'b', 'c', 'c', 'c'] + Categories (3, str): ['a', 'b', 'c'] + """ nv.validate_repeat((), {"axis": axis}) ind = np.arange(len(self)).repeat(repeats) return self.take(ind)