diff --git a/pandas/core/strings.py b/pandas/core/strings.py index cad68036bfaab..59b8bac030c46 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -477,7 +477,6 @@ def str_match(arr, pat, case=True, flags=0, na=np.nan, as_indexer=None): flags : int, default 0 (no flags) re module flags, e.g. re.IGNORECASE na : default NaN, fill value for missing values. - as_indexer : ignored Returns ------- @@ -495,7 +494,10 @@ def str_match(arr, pat, case=True, flags=0, na=np.nan, as_indexer=None): regex = re.compile(pat, flags=flags) - if as_indexer is not None: + if (as_indexer is False) and (regex.groups > 0): + raise ValueError("as_indexer=False with a pattern with groups is no " + "longer supported. Use '.str.extract(pat)' instead") + elif as_indexer is not None: # Previously, this keyword was used for changing the default but # deprecated behaviour. This keyword is now no longer needed. warnings.warn("'as_indexer' keyword was specified but will be ignored;" @@ -1558,7 +1560,7 @@ def contains(self, pat, case=True, flags=0, na=np.nan, regex=True): return self._wrap_result(result) @copy(str_match) - def match(self, pat, case=True, flags=0, na=np.nan, as_indexer=False): + def match(self, pat, case=True, flags=0, na=np.nan, as_indexer=None): result = str_match(self._data, pat, case=case, flags=flags, na=na, as_indexer=as_indexer) return self._wrap_result(result) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 2d26589bbb49e..6df6eb0652d33 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -580,6 +580,11 @@ def test_match(self): with tm.assert_produces_warning(UserWarning): result = values.str.match('.*BAD[_]+.*BAD', as_indexer=False) tm.assert_series_equal(result, exp) + with tm.assert_produces_warning(UserWarning): + result = values.str.match('.*(BAD[_]+).*(BAD)', as_indexer=True) + tm.assert_series_equal(result, exp) + self.assertRaises(ValueError, values.str.match, '.*(BAD[_]+).*(BAD)', + as_indexer=False) # mixed mixed = Series(['aBAD_BAD', NA, 'BAD_b_BAD', True, datetime.today(),