Skip to content

Commit 5bdb2a6

Browse files
committed
Revert changes to pandas/core/strings/accessor.py from PR pandas-dev#61946
1 parent 47c0826 commit 5bdb2a6

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
@@ -1338,31 +1338,13 @@ def contains(
13381338
4 False
13391339
dtype: bool
13401340
"""
1341-
if isinstance(self._data.dtype, ArrowDtype) and isinstance(pat, re.Pattern):
1342-
if flags != 0:
1343-
raise NotImplementedError(
1344-
"Series.str.contains() with a compiled regex pattern and flag is "
1345-
"not supported for Arrow-backed string arrays."
1346-
)
1347-
pat = pat.pattern
1348-
regex = True
1349-
1350-
if regex:
1351-
try:
1352-
_compiled = (
1353-
pat if isinstance(pat, re.Pattern) else re.compile(pat, flags=flags)
1354-
)
1355-
if _compiled.groups:
1356-
warnings.warn(
1357-
"This pattern is interpreted as a regular expression, and has "
1358-
"match groups. To actually get the groups, use str.extract.",
1359-
UserWarning,
1360-
stacklevel=find_stack_level(),
1361-
)
1362-
except re.error as e:
1363-
raise ValueError(
1364-
f"Invalid regex pattern passed to str.contains(): {e}"
1365-
) from e
1341+
if regex and re.compile(pat).groups:
1342+
warnings.warn(
1343+
"This pattern is interpreted as a regular expression, and has "
1344+
"match groups. To actually get the groups, use str.extract.",
1345+
UserWarning,
1346+
stacklevel=find_stack_level(),
1347+
)
13661348

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

0 commit comments

Comments
 (0)