pandas-dev/pandas · warning · NotImplementedError

repeat is not implemented when repeats is

Error message

repeat is not implemented when repeats is {type(repeats).__name__}

What it means

_str_repeat dispatches to pyarrow.compute.binary_repeat, which only accepts a scalar repeat count. If repeats is a sequence (per-element counts), pandas raises NotImplementedError naming the type, because pyarrow has no per-element repeat kernel in this path.

Solutions

  1. Use a scalar repeat: s.str.repeat(2).
  2. Loop with a list comprehension: pd.array([s_*r for s_, r in zip(s, repeats)], dtype=s.dtype).
  3. Fall back to object dtype: s.astype(object).str.repeat(repeats).

Example fix

// before
s = pd.Series(["a", "b"], dtype="string[pyarrow]")
s.str.repeat([1, 2])
// after
s = pd.Series(["a", "b"], dtype="string[pyarrow]")
s.str.repeat(2)  # scalar
Defensive patterns

Strategy: fallback

Validate before calling

def safe_str_repeat(s, repeats):
    if not isinstance(repeats, int):
        # fall back to per-element loop
        import pandas as pd
        return pd.array([v * r for v, r in zip(s, repeats)], dtype=s.dtype)
    return s.str.repeat(repeats)

Type guard

def is_scalar_repeat(repeats) -> bool:
    return isinstance(repeats, int)

Try / catch

try:
    s.str.repeat(repeats)
except NotImplementedError:
    s.astype(object).str.repeat(repeats)

Prevention

When it happens

Trigger: s.str.repeat([1, 2, 3]) on a string[pyarrow] Series — passing a list/array of repeats whose length matches the series.

Common situations: Vectorized expansion where each string repeats a different number of times; building repeated keys for joins.

Related errors


AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11). Data as JSON: /api/errors/fd04c6add85a6d8a. Report an issue: GitHub.

Appendix: source

Thrown at pandas/core/arrays/arrow/array.py:3652

    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):
        if expand:
            # rows of three strings, so a list array rather than Self
            return ArrowExtensionArray(

View on GitHub (pinned to 3b7651241d)