-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
API: Deprecate regex=True default in Series.str.replace #36695
Conversation
There are many tests that are using this (and are now raising a warning) that would need updating. While I agree that a default of |
Yeah this is a good point, I think looking for regex special characters and only then warning could make the most sense |
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.
Can you also add a whatsnew note?
Would this be an update for 1.1.4 or 1.2? |
Added an additional warning for single character regexes:
|
Updated the OP in that issue |
doc/source/user_guide/text.rst
Outdated
Some caution must be taken to keep regular expressions in mind! For example, the | ||
following code will cause trouble because of the regular expression meaning of | ||
``$``: | ||
Some caution must be taken when dealing with regular expressions! The current behavior |
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.
can you do this
doc/source/user_guide/text.rst
Outdated
Some caution must be taken to keep regular expressions in mind! For example, the | ||
following code will cause trouble because of the regular expression meaning of | ||
``$``: | ||
Some caution must be taken when dealing with regular expressions! The current behavior |
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.
also add a versionchanged tag
|
||
def test_str_replace_regex_default_raises_warning(self): | ||
# https://github.com/pandas-dev/pandas/pull/24809 | ||
s = pd.Series(["a", "b", "c"]) |
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.
can you check the messages on this warning
if isinstance(pat, str) and any(c in pat for c in ".+*|^$?[](){}\\"): | ||
# warn only in cases where regex behavior would differ from literal | ||
msg = ( | ||
"The default value of regex will change from True to False " |
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.
an you make sure that we are testing both of these warnings (as i see you only added a single test)
doc/source/user_guide/text.rst
Outdated
Some caution must be taken to keep regular expressions in mind! For example, the | ||
following code will cause trouble because of the regular expression meaning of | ||
``$``: | ||
Some caution must be taken when dealing with regular expressions! The current behavior |
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.
no i mean a ..note::
a sphinx-note (which puts a highlite box around this)
doc/source/user_guide/text.rst
Outdated
Some caution must be taken to keep regular expressions in mind! For example, the | ||
following code will cause trouble because of the regular expression meaning of | ||
``$``: | ||
Some caution must be taken when dealing with regular expressions! The current behavior |
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.
we could also do a ..warning::
which is a red-box and more prominent, but either way want to call out this
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.
very nice
|
||
# This does what you'd naively expect: | ||
dollars.str.replace("$", "") | ||
.. warning:: |
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.
great
merge on most builds green (some are giving issues now). |
From some old discussion it looks like there was interest in changing the default value of regex from True to False within Series.str.replace. I think this makes sense since it would align this method with others within pandas along with the standard library, and would also make fixing #24804 slightly less disruptive. I'm assuming this would warrant a deprecation note in the next whatsnew?
I think this part of the docs will need to be updated: https://pandas.pydata.org/pandas-docs/stable/user_guide/text.html#splitting-and-replacing-strings
#24809