pandas-dev/pandas · error · NotImplementedError

Only flags=0 is implemented.

Error message

Only flags=0 is implemented.

What it means

Raised by ArrowExtensionArray._str_extract when the `flags` argument is non-zero. The PyArrow compute function pc.extract_regex does not accept regex flags, so the ArrowExtensionArray implementation rejects any non-zero flags with NotImplementedError. This is reached through Series.str.extract / str.extractall on a pyarrow-string-backed Series.

Source

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

    def _str_rpartition(self, sep: str, expand: bool) -> Self:
        predicate = lambda val: val.rpartition(sep)
        result = self._apply_elementwise(predicate)
        return self._from_pyarrow_array(pa.chunked_array(result))

    def _str_casefold(self) -> Self:
        predicate = lambda val: val.casefold()
        result = self._apply_elementwise(predicate)
        return self._from_pyarrow_array(pa.chunked_array(result))

    def _str_encode(self, encoding: str, errors: str = "strict") -> Self:
        predicate = lambda val: val.encode(encoding, errors)
        result = self._apply_elementwise(predicate)
        return self._from_pyarrow_array(pa.chunked_array(result))

    def _str_extract(self, pat: str, flags: int = 0, expand: bool = True):
        if flags:
            raise NotImplementedError("Only flags=0 is implemented.")
        groups = re.compile(pat).groupindex.keys()
        if len(groups) == 0:
            raise ValueError(f"{pat=} must contain a symbolic group name.")
        result = pc.extract_regex(self._pa_array, pat)
        if expand:
            return {
                col: self._from_pyarrow_array(pc.struct_field(result, [i]))
                for col, i in zip(groups, range(result.type.num_fields), strict=True)
            }
        else:
            return type(self)(pc.struct_field(result, [0]))

    def _str_findall(self, pat: str, flags: int = 0) -> Self:
        regex = re.compile(pat, flags=flags)
        predicate = lambda val: regex.findall(val)
        result = self._apply_elementwise(predicate)
        return self._from_pyarrow_array(pa.chunked_array(result))

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Inline the flag into the pattern itself, e.g. replace `re.IGNORECASE` with an inline `(?i)` group: `s.str.extract(r"(?i)(?P<name>\\w+)")`.
  2. Drop the flags argument (default flags=0) and make the pattern explicit for the cases you need.
  3. Cast the Series to object/string[python] for that operation: `s.astype("string[python]").str.extract(pat, flags=re.IGNORECASE)`.
  4. Pre-compile and lowercase both sides instead of relying on regex flags.

Example fix

# before
s = pd.Series(["Foo","bar"], dtype="string[pyarrow]")
s.str.extract(r"(?P<w>foo)", flags=re.IGNORECASE)  # NotImplementedError

# after: embed flag inline
s.str.extract(r"(?i)(?P<w>foo)")
Defensive patterns

Strategy: validation

Validate before calling

def safe_extract(s, pat, flags=0):
    if flags:
        # pyarrow backend only supports flags=0; bake flag into pattern
        import re as _re
        pat = _re.compile(pat, flags).pattern  # note: does not inline flags; see tip
        raise NotImplementedError("Use inline (?i)/(?x) in pattern for string[pyarrow]")
    return s.str.extract(pat)

Type guard

def flags_ok_for_pyarrow(flags: int) -> bool:
    return not flags

Try / catch

try:
    out = s.str.extract(pat, flags=flags)
except NotImplementedError:
    out = s.astype("string[python]").str.extract(pat, flags=flags)

Prevention

When it happens

Trigger: Calling `s.str.extract(pat, flags=re.IGNORECASE)` (or any re module flag such as re.VERBOSE, re.MULTILINE) where `s.dtype` is a pyarrow-backed string dtype (string[pyarrow] / large string). flags=0 is the only supported value.

Common situations: Case-insensitive extraction patterns written with re.IGNORECASE that worked on object/string[python] dtypes fail when the column is converted to string[pyarrow] for memory/performance reasons. Shared regex utility functions that pass flags unconditionally.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/4ba6bbda82844089. Report an issue: GitHub.