8000 ENH: Allow literal (non-regex) replacement using .str.replace #16808 by Liam3851 · Pull Request #19584 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

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

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

Merged
merged 13 commits into from
Feb 28, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix PEP8 line length in tests.
  • Loading branch information
Liam3851 authored and TomAugspurger committed Feb 27, 2018
commit a28ef8fbdcc8d846dc0194d6b3fee8b4024e7012
9 changes: 6 additions & 3 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,15 @@ def test_replace_literal(self):
result = values.str.replace('f.', 'ba', regex=False)
tm.assert_series_equal(result, exp)

# Cannot do a literal replace if given a callable repl or compiled pattern
# Cannot do a literal replace if given a callable repl or compiled
# pattern
callable_repl = lambda m: m.group(0).swapcase()
compiled_pat = re.compile('[a-z][A-Z]{2}')

pytest.raises(ValueError, values.str.replace, 'abc', callable_repl, regex=False)
pytest.raises(ValueError, values.str.replace, compiled_pat, '', regex=False)
pytest.raises(ValueError, values.str.replace, 'abc', callable_repl,
regex=False)
pytest.raises(ValueError, values.str.replace, compiled_pat, '',
regex=False)

def test_repeat(self):
values = Series(['a', 'b', NA, 'c', NA, 'd'])
Expand Down
0