ENH: Allow literal (non-regex) replacement using .str.replace #16808
State: closed

Adds `regex=True` default parameter to .str.replace. If `regex=False` is set, uses str.replace to replace occurrences of `pat` with `repl`. Raises `ValueError` if given a callable `repl` or a compiled re for `pat` in combination with `regex=False`.

- [ ] closes #16808
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: API Design
name: Strings
description: String extension data type and string data

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19584?src=pr&el=h1) Report
> Merging [#19584](https://codecov.io/gh/pandas-dev/pandas/pull/19584?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/14a38a64c054ff1c2b21e3687e544048044f9c38?src=pr&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/19584/graphs/tree.svg?height=150&width=650&token=eZ4WkYLtcO&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/19584?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #19584      +/-   ##
==========================================
+ Coverage   91.66%   91.69%   +0.02%     
==========================================
  Files         150      150              
  Lines       48976    48981       +5     
==========================================
+ Hits        44896    44913      +17     
+ Misses       4080     4068      -12
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.07% <100%> (+0.02%)` | :arrow_up: |
| #single | `41.85% <5.26%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/19584?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/strings.py](https://codecov.io/gh/pandas-dev/pandas/pull/19584/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3RyaW5ncy5weQ==) | `98.32% <100%> (+0.01%)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/19584/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `66.95% <0%> (+1.73%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19584?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/19584?src=pr&el=footer). Last update [14a38a6...1371cef](https://codecov.io/gh/pandas-dev/pandas/pull/19584?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Hello @Liam3851! Thanks for updating the PR.





Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on February 28, 2018 at 11:13 Hours UTC
@Liam3851 looks like an issue with your latest merge. Need any help with the git stuff?
@TomAugspurger Yes, thanks, I'm a git newb. I ran a git rebase upstream/master on the branch to get the latest code which seems to have been a not-great thing to do. What's the best way to fix this?
Taking a look now. Did you have any changes in your last push, or were you just rebasing?
@TomAugspurger I was just making a small doc change per jreback's comment. I can easily make the change again if there's a clean way to roll back the PR to the state it was before.
I just pushed a commit to your branch that should have just your commits (plus a small one by me cleaning up some whitespace). Take a look, and lmk if I messed anything up during the rebase.

And I had to force push to remove the extraneous commits, so make sure to pull before making additional changes.
If you have any troubles with the pull then

```
git fetch origin
git reset --hard origin/str_replace_regex
```

Should make your local copy exactly match the PR.
@TomAugspurger Thanks so much for cleaning that up! Sorry for the git problems.
thanks @Liam3851 nice patch!