-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN/DEPR: removed deprecated as_indexer arg from str.match() #22356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
c079870
f6612aa
72f74b2
ce529e9
454612e
db7f34e
07cff36
23604e9
b109d19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -709,7 +709,7 @@ def rep(x, r): | |
return result | ||
|
||
|
||
def str_match(arr, pat, case=True, flags=0, na=np.nan, as_indexer=None): | ||
def str_match(arr, pat, case=True, flags=0, na=np.nan): | ||
""" | ||
Determine if each string matches a regular expression. | ||
|
||
|
@@ -722,8 +722,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 | ||
.. deprecated:: 0.21.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so is this just wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @HyunTruth can you see when this was added? if it was in 0.21.0 then we can't remove this yet, if it was a mistake / typo then we could. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll check on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback It seems to be a typo, as in whatsnew v0.20.0, it is stated that
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok then |
||
|
||
Returns | ||
------- | ||
|
@@ -741,17 +739,6 @@ 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 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 is ignored " | ||
"(match now returns a boolean indexer by default), " | ||
"and will be removed in a future version.", | ||
FutureWarning, stacklevel=3) | ||
|
||
dtype = bool | ||
f = lambda x: bool(regex.match(x)) | ||
|
||
|
@@ -2469,9 +2456,8 @@ 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=None): | ||
result = str_match(self._parent, pat, case=case, flags=flags, na=na, | ||
as_indexer=as_indexer) | ||
def match(self, pat, case=True, flags=0, na=np.nan): | ||
result = str_match(self._parent, pat, case=case, flags=flags, na=na) | ||
return self._wrap_result(result) | ||
|
||
@copy(str_replace) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -938,20 +938,13 @@ def test_match(self): | |
exp = Series([True, NA, False]) | ||
tm.assert_series_equal(result, exp) | ||
|
||
# test passing as_indexer still works but is ignored | ||
# GH 22316 test the removal of as_indexer from match | ||
values = Series(['fooBAD__barBAD', NA, 'foo']) | ||
exp = Series([True, NA, False]) | ||
with tm.assert_produces_warning(FutureWarning): | ||
with tm.assert_raises_regex(TypeError, | ||
"match() got an unexpected " | ||
"keyword argument 'as_indexer'"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the thought. However, we generally just drop all of the relevant tests when a keyword is getting dropped after a deprecation. |
||
result = values.str.match('.*BAD[_]+.*BAD', as_indexer=True) | ||
tm.assert_series_equal(result, exp) | ||
with tm.assert_produces_warning(FutureWarning): | ||
result = values.str.match('.*BAD[_]+.*BAD', as_indexer=False) | ||
tm.assert_series_equal(result, exp) | ||
with tm.assert_produces_warning(FutureWarning): | ||
result = values.str.match('.*(BAD[_]+).*(BAD)', as_indexer=True) | ||
tm.assert_series_equal(result, exp) | ||
pytest.raises(ValueError, values.str.match, '.*(BAD[_]+).*(BAD)', | ||
as_indexer=False) | ||
|
||
# mixed | ||
mixed = Series(['aBAD_BAD', NA, 'BAD_b_BAD', True, datetime.today(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.20.0
? You can also just remove that parenthetical comment.Removal of prior version deprecations/changes
section.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, will fix it straight away