From 44a8e4000cf06307821412e0e4433ea5cd1dc686 Mon Sep 17 00:00:00 2001 From: bion howard Date: Sun, 7 Jan 2024 10:27:59 -0500 Subject: [PATCH] Remove warning about unused groups This warning is annoying and serves to discourage use of named capturing groups (which are more maintainable) because users must either switch to extracting the groups (not always necessary) or replace their named groups with "(?:" (unnamed groups are harder to maintain because it's less clear what is their objective within a greater regex pattern). If users need to specialize their regex patterns to each command, then they need to maintain multiple copies, some with unnamed groups, some without, just to silence some warning, also, if they remove the groups, then later on when they want to use them, they might have to figure out how to replace groups they removed just to silence a warning, and be frustrated. If we remove this unnecessary warning, then we no longer discourage users who use named capturing groups, thus facilitating readability of the patterns, and portability to other contexts, such as debuggers or the "extract" method mentioned in the removed warning. TL;DR: This warning doesn't need to exist, so I'm removing it. If there are tests which expect it, then they could also be removed. Code to silence the warning should still work, but could also be removed. --- pandas/core/strings/accessor.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 7c6dca3bad7d9..6302fb29d0ea4 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -1320,14 +1320,6 @@ def contains( 4 False dtype: bool """ - if regex and re.compile(pat).groups: - warnings.warn( - "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(), - ) - result = self._data.array._str_contains(pat, case, flags, na, regex) return self._wrap_result(result, fill_value=na, returns_string=False)