{"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":"warning","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":3647,"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":3629,"sourceCodeEnd":3665,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/arrow/array.py#L3629-L3665","documentation":"_str_count dispatches to pyarrow.compute.count_substring_regex, which does not accept regex flags. If a non-zero flags argument is passed, pandas raises NotImplementedError rather than silently ignoring the flags or falling back to the slower object path.","triggerScenarios":"s.str.count(r'\\d+', flags=re.IGNORECASE) on a string[pyarrow] Series — passing any non-zero int as flags.","commonSituations":"Porting regex calls that use re.IGNORECASE / re.MULTILINE; sharing flag constants between pandas str and re module code.","solutions":["Inline the flag into the pattern (e.g. '(?i)\\d+') instead of using the flags argument.","Convert to object dtype for the call: s.astype(object).str.count(pat, flags=...).","Drop the flags argument if case sensitivity is acceptable."],"exampleFix":"// before\ns = pd.Series([\"A1\", \"b2\"], dtype=\"string[pyarrow]\")\ns.str.count(r\"[a-z]\", flags=re.IGNORECASE)\n// after\ns = pd.Series([\"A1\", \"b2\"], dtype=\"string[pyarrow]\")\ns.str.count(r\"(?i)[a-z]\")","handlingStrategy":"validation","validationCode":"import re\n\ndef safe_str_count(s, pat, flags=0):\n    if flags:\n        # inline flags into the pattern\n        flag_prefix = \"\"\n        if flags & re.IGNORECASE: flag_prefix += \"(?i)\"\n        if flags & re.MULTILINE: flag_prefix += \"(?m)\"\n        if flags & re.DOTALL: flag_prefix += \"(?s)\"\n        pat = flag_prefix + pat\n    return s.str.count(pat)","typeGuard":"def flags_inlineable() -> bool:\n    return True  # always preferred for arrow-backed str","tryCatchPattern":"try:\n    s.str.count(pat, flags=flags)\nexcept NotImplementedError:\n    s.astype(object).str.count(pat, flags=flags)","preventionTips":["Inline regex flags into the pattern with (?i)/(?m)/(?s).","Avoid passing re flags to str methods on pyarrow string series."],"tags":["pyarrow","str","count","regex","flags"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}