Skip to content

Commit 2b756ad

Browse files
authored
Clarify regex interpretation in str.contains (#44812)
1 parent 8f052de commit 2b756ad

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pandas/core/strings/accessor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1212,8 +1212,8 @@ def contains(self, pat, case=True, flags=0, na=None, regex=True):
12121212
"""
12131213
if regex and re.compile(pat).groups:
12141214
warnings.warn(
1215-
"This pattern has match groups. To actually get the "
1216-
"groups, use str.extract.",
1215+
"This pattern is interpreted as a regular expression, and has "
1216+
"match groups. To actually get the groups, use str.extract.",
12171217
UserWarning,
12181218
stacklevel=find_stack_level(),
12191219
)

pandas/tests/strings/test_find_replace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ def test_flags_kwarg(any_string_dtype):
919919
result = data.str.count(pat, flags=re.IGNORECASE)
920920
assert result[0] == 1
921921

922-
msg = "This pattern has match groups"
922+
msg = "has match groups"
923923
with tm.assert_produces_warning(UserWarning, match=msg):
924924
result = data.str.contains(pat, flags=re.IGNORECASE)
925925
assert result[0]

0 commit comments

Comments
 (0)