{"record":{"id":"2f8a724418cee417","repo":"pandas-dev/pandas","slug":"count-not-implemented-with-flags","errorCode":null,"errorMessage":"count not implemented with {flags=}","messagePattern":"count not implemented with (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":3624,"sourceCode":"                for val in chunk.to_numpy(zero_copy_only=False)\n            ]\n            for chunk in self._pa_array.iterchunks()\n        ]\n\n    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))","sourceCodeStart":3606,"sourceCodeEnd":3642,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/arrow/array.py#L3606-L3642","documentation":"Raised by _str_count (the string `.str.count` accessor on arrow-backed strings) when a non-zero `flags` argument is passed. pyarrow's count_substring_regex does not accept regex flags, so pandas rejects any non-zero flags value rather than silently ignoring them.","triggerScenarios":"Calling `s.str.count(pat, flags=re.IGNORECASE)` (or any non-zero flag) on a `string[pyarrow]` Series.","commonSituations":"Porting code that used `re.IGNORECASE`/`re.VERBOSE` flags with object/string Series `.str.count`, which worked because the object path deferred to the `re` module.","solutions":["Inline the flag into the pattern instead, e.g. use `(?i)...` for case-insensitive: `s.str.count(r'(?i)foo')`.","Switch the Series dtype to `object` or `string[python]` if you must pass re flags.","Pre-compile and apply via `.map` if more complex flag handling is needed."],"exampleFix":"// before\ns = pd.Series([\"Foo\", \"foo\"], dtype=\"string[pyarrow]\")\ns.str.count(\"foo\", flags=re.IGNORECASE)\n\n// after\ns.str.count(r\"(?i)foo\")","handlingStrategy":"validation","validationCode":"def safe_str_count(s, pat, flags=0):\n    if flags:\n        # inline common flags into pattern\n        import re\n        pat = ((\"(?i)\" if flags & re.IGNORECASE else \"\")\n               + (\"(?x)\" if flags & re.VERBOSE else \"\")\n               + pat)\n    return s.str.count(pat)","typeGuard":"def flags_inlineable(flags) -> bool:\n    import re\n    # only flags we know how to inline are supported on arrow path\n    return flags == 0 or (flags & ~(re.IGNORECASE | re.VERBOSE)) == 0","tryCatchPattern":"try:\n    s.str.count(pat, flags=flags)\nexcept NotImplementedError as e:\n    if \"count not implemented with flags\" in str(e):\n        s.astype(\"object\").str.count(pat, flags=flags)\n    else:\n        raise","preventionTips":["Prefer inline regex flags like (?i) over the flags kwarg for arrow-backed strings.","Switch to object/string[python] dtype when re-module flags are required.","Document arrow-str-accessor limitations for code migrated from object dtype."],"tags":["arrow","str-accessor","regex","count","flags"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}