Skip to content

Commit 3345bc7

Browse files
committed
Revert changes to pandas/core/strings/accessor.py from PR #61946
1 parent b474604 commit 3345bc7

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

pandas/core/strings/accessor.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,31 +1350,13 @@ def contains(
13501350
4 False
13511351
dtype: bool
13521352
"""
1353-
if isinstance(self._data.dtype, ArrowDtype) and isinstance(pat, re.Pattern):
1354-
if flags != 0:
1355-
raise NotImplementedError(
1356-
"Series.str.contains() with a compiled regex pattern and flag is "
1357-
"not supported for Arrow-backed string arrays."
1358-
)
1359-
pat = pat.pattern
1360-
regex = True
1361-
1362-
if regex:
1363-
try:
1364-
_compiled = (
1365-
pat if isinstance(pat, re.Pattern) else re.compile(pat, flags=flags)
1366-
)
1367-
if _compiled.groups:
1368-
warnings.warn(
1369-
"This pattern is interpreted as a regular expression, and has "
1370-
"match groups. To actually get the groups, use str.extract.",
1371-
UserWarning,
1372-
stacklevel=find_stack_level(),
1373-
)
1374-
except re.error as e:
1375-
raise ValueError(
1376-
f"Invalid regex pattern passed to str.contains(): {e}"
1377-
) from e
1353+
if regex and re.compile(pat).groups:
1354+
warnings.warn(
1355+
"This pattern is interpreted as a regular expression, and has "
1356+
"match groups. To actually get the groups, use str.extract.",
1357+
UserWarning,
1358+
stacklevel=find_stack_level(),
1359+
)
13781360

13791361
result = self._data.array._str_contains(pat, case, flags, na, regex)
13801362
return self._wrap_result(result, fill_value=na, returns_string=False)

0 commit comments

Comments
 (0)