Skip to content

Commit 0b16375

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

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
@@ -1350,13 +1352,6 @@ def contains(
13501352
4 False
13511353
dtype: bool
13521354
"""
1353-
from pandas.core.dtypes.dtypes import ArrowDtype
1354-
import re
1355-
1356-
# --- Handle Arrow-backed string arrays with compiled regex patterns ---
1357-
# Arrow backend does not support compiled regex objects or Python regex flags.
1358-
# If a compiled regex is passed, only allow it if no flags are set.
1359-
13601355
if isinstance(self._data.dtype, ArrowDtype) and isinstance(pat, re.Pattern):
13611356
if flags != 0:
13621357
raise NotImplementedError(
@@ -1383,7 +1378,6 @@ def contains(
13831378
f"Invalid regex pattern passed to str.contains(): {e}"
13841379
) from e
13851380

1386-
13871381
result = self._data.array._str_contains(pat, case, flags, na, regex)
13881382
return self._wrap_result(result, fill_value=na, returns_string=False)
13891383

0 commit comments

Comments
 (0)