diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index b5f3af5af8e38..d5abd1606edec 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -1212,8 +1212,8 @@ def contains(self, pat, case=True, flags=0, na=None, regex=True): """ if regex and re.compile(pat).groups: warnings.warn( - "This pattern has match groups. To actually get the " - "groups, use str.extract.", + "This pattern is interpreted as a regular expression, and has " + "match groups. To actually get the groups, use str.extract.", UserWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/tests/strings/test_find_replace.py b/pandas/tests/strings/test_find_replace.py index f390cbf492202..067bcf5969587 100644 --- a/pandas/tests/strings/test_find_replace.py +++ b/pandas/tests/strings/test_find_replace.py @@ -919,7 +919,7 @@ def test_flags_kwarg(any_string_dtype): result = data.str.count(pat, flags=re.IGNORECASE) assert result[0] == 1 - msg = "This pattern has match groups" + msg = "has match groups" with tm.assert_produces_warning(UserWarning, match=msg): result = data.str.contains(pat, flags=re.IGNORECASE) assert result[0]