{"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":"warning","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":3652,"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):\n        if expand:\n            # rows of three strings, so a list array rather than Self\n            return ArrowExtensionArray(","sourceCodeStart":3634,"sourceCodeEnd":3670,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/arrow/array.py#L3634-L3670","documentation":"_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.","triggerScenarios":"s.str.repeat([1, 2, 3]) on a string[pyarrow] Series — passing a list/array of repeats whose length matches the series.","commonSituations":"Vectorized expansion where each string repeats a different number of times; building repeated keys for joins.","solutions":["Use a scalar repeat: s.str.repeat(2).","Loop with a list comprehension: pd.array([s_*r for s_, r in zip(s, repeats)], dtype=s.dtype).","Fall back to object dtype: s.astype(object).str.repeat(repeats)."],"exampleFix":"// before\ns = pd.Series([\"a\", \"b\"], dtype=\"string[pyarrow]\")\ns.str.repeat([1, 2])\n// after\ns = pd.Series([\"a\", \"b\"], dtype=\"string[pyarrow]\")\ns.str.repeat(2)  # scalar","handlingStrategy":"fallback","validationCode":"def safe_str_repeat(s, repeats):\n    if not isinstance(repeats, int):\n        # fall back to per-element loop\n        import pandas as pd\n        return pd.array([v * r for v, r in zip(s, repeats)], dtype=s.dtype)\n    return s.str.repeat(repeats)","typeGuard":"def is_scalar_repeat(repeats) -> bool:\n    return isinstance(repeats, int)","tryCatchPattern":"try:\n    s.str.repeat(repeats)\nexcept NotImplementedError:\n    s.astype(object).str.repeat(repeats)","preventionTips":["Use a scalar repeat count for vectorized performance.","Fall back to object dtype when per-element repeats are required."],"tags":["pyarrow","str","repeat","vectorized"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}