{"record":{"id":"fd04c6add85a6d8a","repo":"pandas-dev/pandas","slug":"repeat-is-not-implemented-when-repeats-is-type-re","errorCode":null,"errorMessage":"repeat is not implemented when repeats is {type(repeats).__name__}","messagePattern":"repeat is not implemented when repeats is (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":3629,"sourceCode":"    def _convert_bool_result(self, result, na=lib.no_default, method_name=None):\n        if na is not lib.no_default and not isna(na):  # pyright: ignore [reportGeneralTypeIssues]\n            result = result.fill_null(na)\n        return self._from_pyarrow_array(result)\n\n    def _convert_int_result(self, result):\n        return self._from_pyarrow_array(result)\n\n    def _convert_rank_result(self, result):\n        return self._from_pyarrow_array(result)\n\n    def _str_count(self, pat: str, flags: int = 0) -> Self:\n        if flags:\n            raise NotImplementedError(f\"count not implemented with {flags=}\")\n        return self._from_pyarrow_array(pc.count_substring_regex(self._pa_array, pat))\n\n    def _str_repeat(self, repeats: int | Sequence[int]) -> Self:\n        if not isinstance(repeats, int):\n            raise NotImplementedError(\n                f\"repeat is not implemented when repeats is {type(repeats).__name__}\"\n            )\n        return self._from_pyarrow_array(pc.binary_repeat(self._pa_array, repeats))\n\n    def _str_join(self, sep: str) -> Self:\n        if pa.types.is_string(self._pa_array.type) or pa.types.is_large_string(\n            self._pa_array.type\n        ):\n            result = self._apply_elementwise(list)\n            result = pa.chunked_array(result, type=pa.list_(pa.string()))\n        else:\n            result = self._pa_array\n        return self._from_pyarrow_array(pc.binary_join(result, sep))\n\n    def _str_partition(self, sep: str, expand: bool) -> Self:\n        predicate = lambda val: val.partition(sep)\n        result = self._apply_elementwise(predicate)\n        return self._from_pyarrow_array(pa.chunked_array(result))","sourceCodeStart":3611,"sourceCodeEnd":3647,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/arrow/array.py#L3611-L3647","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"# before\ns = pd.Series([\"a\",\"bb\",\"ccc\"], dtype=\"string[pyarrow]\")\nout = s.str.repeat([1, 2, 3])  # NotImplementedError\n\n# after (scalar only)\nout = s.str.repeat(2)\n\n# after (per-element via object fallback)\nout = pd.Series(\n    [v * r for v, r in zip(s.to_numpy(), [1, 2, 3])],\n    dtype=\"string[pyarrow]\",\n)","handlingStrategy":"validation","validationCode":"import numbers\n\ndef safe_repeat(s, repeats):\n    if not isinstance(repeats, numbers.Integral):\n        raise TypeError(\n            \"string[pyarrow] backend supports only scalar int repeats; \"\n            f\"got {type(repeats).__name__}. Cast to object/string[python] for per-element repeats.\"\n        )\n    return s.str.repeat(int(repeats))","typeGuard":"import numbers\n\ndef is_scalar_int(v) -> bool:\n    # numpy integer scalars also qualify\n    return isinstance(v, numbers.Integral)","tryCatchPattern":"try:\n    out = s.str.repeat(repeats)\nexcept NotImplementedError:\n    # per-element repeat fallback\n    out = pd.Series([v * r for v, r in zip(s.to_numpy(), repeats)], dtype=\"string[pyarrow]\")","preventionTips":["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."],"tags":["pyarrow","string-accessor","not-implemented"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}