-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Should str.replace accept a compiled expression? #15446
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
Comments
I can't think of one. Feel free to give it a shot! |
yup these reasonable (and straightforward) to do. |
str.replace
accept a compiled expression from the re
module?.str.replace now accepts a compiled regular expression. See pandas-dev#15446
.str.replace now accepts a compiled regular expression. See pandas-dev#15446 TODO before merging: - Consider moving check for compiled regex to `pandas.types` and using a dummy compiled regex for type checking. - Consider what to do with `case` and `flags` parameters, which are noop when `pat` is a compiled regex. - Add compiled regex tests for `str_replace` - Add compiled regex documentation for `str_replace`
.str.replace now accepts a compiled regular expression. See pandas-dev#15446 TODO before merging: - Consider moving check for compiled regex to `pandas.types` and using a dummy compiled regex for type checking. - Consider what to do with `case` and `flags` parameters, which are noop when `pat` is a compiled regex. - Add compiled regex tests for `str_replace` - Add compiled regex documentation for `str_replace`
I just submitted a PR after looking into this (apologies in advance for the unexpected triple-commit message above). Very simply, I added a check to A few questions that will help drive this to completion:
Note:
|
.str.replace now accepts a compiled regular expression. See pandas-dev#15446
.str.replace now accepts a compiled regular expression for `pat`. See pandas-dev#15446
.str.replace now accepts a compiled regular expression for `pat`. See pandas-dev#15446
.str.replace now accepts a compiled regular expression for `pat`. See pandas-dev#15446
- .str.replace now accepts a compiled regular expression for `pat`. - Signature for .str.replace changed, but remains backwards compatible. See pandas-dev#15446
- .str.replace now accepts a compiled regular expression for `pat`. - Signature for .str.replace changed, but remains backwards compatible. See pandas-dev#15446
- .str.replace now accepts a compiled regular expression for `pat`. - Signature for .str.replace changed, but remains backwards compatible. See pandas-dev#15446
- .str.replace now accepts a compiled regular expression for `pat`. - Signature for .str.replace changed, but remains backwards compatible. See pandas-dev#15446
- Series.str.replace now accepts a compiled regular expression for `pat`. - Signature for .str.replace changed, but remains backwards compatible. See pandas-dev#15446
- Series.str.replace now accepts a compiled regular expression for `pat`. - Signature for .str.replace changed, but remains backwards compatible. See pandas-dev#15446
- Series.str.replace now accepts a compiled regular expression for `pat`. - Signature for .str.replace changed, but remains backwards compatible. See pandas-dev#15446
- Series.str.replace now accepts a compiled regular expression for `pat`. - Signature for .str.replace changed, but remains backwards compatible. See #15446
Wow, thank you! |
- Series.str.replace now accepts a compiled regular expression for `pat`. - Signature for .str.replace changed, but remains backwards compatible. See pandas-dev#15446
The current solution is to call
str.replace(<compiled_re>.pattern, flags=<compiled_re>.flags)
which is relatively ugly and verbose in my opnion.Here's a contrived example of removing stopwords and normalizing whitespace afterwards:
Why do I think this is better?
Is there a good reason not to implement this?
The text was updated successfully, but these errors were encountered: