Skip to content

Commit bc2fd6e

Browse files
committed
BUG: Fix handling of compiled regex in Series.str.contains for Arrow-backed strings
1 parent fc4f736 commit bc2fd6e

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

pandas/core/strings/accessor.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from pandas.core.dtypes.dtypes import ArrowDtype
4+
35
import codecs
46
from functools import wraps
57
import re
@@ -1338,13 +1340,6 @@ def contains(
13381340
4 False
13391341
dtype: bool
13401342
"""
1341-
from pandas.core.dtypes.dtypes import ArrowDtype
1342-
import re
1343-
1344-
# --- Handle Arrow-backed string arrays with compiled regex patterns ---
1345-
# Arrow backend does not support compiled regex objects or Python regex flags.
1346-
# If a compiled regex is passed, only allow it if no flags are set.
1347-
13481343
if isinstance(self._data.dtype, ArrowDtype) and isinstance(pat, re.Pattern):
13491344
if flags != 0:
13501345
raise NotImplementedError(
@@ -1371,7 +1366,6 @@ def contains(
13711366
f"Invalid regex pattern passed to str.contains(): {e}"
13721367
) from e
13731368

1374-
13751369
result = self._data.array._str_contains(pat, case, flags, na, regex)
13761370
return self._wrap_result(result, fill_value=na, returns_string=False)
13771371

0 commit comments

Comments
 (0)