pandas-dev/pandas · error · NotImplementedError
repeat is not implemented when repeats is {type(repeats).__n
Error message
repeat is not implemented when repeats is {type(repeats).__name__} What it means
Raised by ArrowExtensionArray._str_repeat when the `repeats` argument is not a plain int (e.g. a list, tuple, numpy array, or Series). Although the signature advertises `int | Sequence[int]`, the PyArrow-backed implementation only supports a scalar int via pc.binary_repeat. Passing any sequence type falls into the `not isinstance(repeats, int)` branch and raises NotImplementedError. It surfaces through Series.str.repeat() on a string-backed ArrowExtensionArray.
Source
Thrown at pandas/core/arrays/arrow/array.py:3629
def _convert_bool_result(self, result, na=lib.no_default, method_name=None):
if na is not lib.no_default and not isna(na): # pyright: ignore [reportGeneralTypeIssues]
result = result.fill_null(na)
return self._from_pyarrow_array(result)
def _convert_int_result(self, result):
return self._from_pyarrow_array(result)
def _convert_rank_result(self, result):
return self._from_pyarrow_array(result)
def _str_count(self, pat: str, flags: int = 0) -> Self:
if flags:
raise NotImplementedError(f"count not implemented with {flags=}")
return self._from_pyarrow_array(pc.count_substring_regex(self._pa_array, pat))
def _str_repeat(self, repeats: int | Sequence[int]) -> Self:
if not isinstance(repeats, int):
raise NotImplementedError(
f"repeat is not implemented when repeats is {type(repeats).__name__}"
)
return self._from_pyarrow_array(pc.binary_repeat(self._pa_array, repeats))
def _str_join(self, sep: str) -> Self:
if pa.types.is_string(self._pa_array.type) or pa.types.is_large_string(
self._pa_array.type
):
result = self._apply_elementwise(list)
result = pa.chunked_array(result, type=pa.list_(pa.string()))
else:
result = self._pa_array
return self._from_pyarrow_array(pc.binary_join(result, sep))
def _str_partition(self, sep: str, expand: bool) -> Self:
predicate = lambda val: val.partition(sep)
result = self._apply_elementwise(predicate)
return self._from_pyarrow_array(pa.chunked_array(result))View on GitHub (pinned to 71959b8cb9)
Solutions
- Pass a scalar int: `s.str.repeat(2)`.
- If you need per-element repeats, fall back to numpy object dtype: `s.astype(object).str.repeat(repeats)` or `s.astype("string[python]").str.repeat(repeats)`.
- Implement per-element repeat manually: `s.to_numpy().astype(object)` then `[v * r for v, r in zip(values, repeats)]` and wrap back into a Series.
- Track upstream: file/monitor a pandas issue to extend the PyArrow backend to support per-element repeats (pc.binary_repeat is scalar-only).
Example fix
# before
s = pd.Series(["a","bb","ccc"], dtype="string[pyarrow]")
out = s.str.repeat([1, 2, 3]) # NotImplementedError
# after (scalar only)
out = s.str.repeat(2)
# after (per-element via object fallback)
out = pd.Series(
[v * r for v, r in zip(s.to_numpy(), [1, 2, 3])],
dtype="string[pyarrow]",
) Defensive patterns
Strategy: validation
Validate before calling
import numbers
def safe_repeat(s, repeats):
if not isinstance(repeats, numbers.Integral):
raise TypeError(
"string[pyarrow] backend supports only scalar int repeats; "
f"got {type(repeats).__name__}. Cast to object/string[python] for per-element repeats."
)
return s.str.repeat(int(repeats)) Type guard
import numbers
def is_scalar_int(v) -> bool:
# numpy integer scalars also qualify
return isinstance(v, numbers.Integral) Try / catch
try:
out = s.str.repeat(repeats)
except NotImplementedError:
# per-element repeat fallback
out = pd.Series([v * r for v, r in zip(s.to_numpy(), repeats)], dtype="string[pyarrow]") Prevention
- Default to scalar int repeats when working with string[pyarrow] columns.
- Gate per-element repeat paths behind an explicit dtype check: if s.dtype.storage == 'pyarrow': use scalar.
- Document backend limitations in shared string utilities.
When it happens
Trigger: Calling `s.str.repeat([1,2,3])` or `s.str.repeat(n_array)` where `s.dtype` is `string[pyarrow]`/`string[pyarrow_python]`/large_string pyarrow and `repeats` is anything other than a Python int. A pandas Series, numpy array, or tuple of repeats all trigger it; only a scalar int does not.
Common situations: Porting code from object-dtype or pandas StringDtype strings where per-element repeat lists worked, then switching the column to `dtype="string[pyarrow]"`. Dynamically building `repeats` from another column. ML/notebook code that computes a repeat vector at runtime.
Related errors
- Only flags=0 is implemented.
- replace is not supported with a re.Pattern, callable repl, c
- contains not implemented with {flags=}
- Converting strings to {pa_type} is not implemented.
- {op.__name__} not implemented for {type(other)}
AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07).
Data as JSON: /api/errors/fd04c6add85a6d8a.
Report an issue: GitHub.