Skip to content

Commit 4baa0a7

Browse files
author
Joost Kranendonk
authored
add tests for .str.replace with callable repl
See pandas-dev#15055 and pandas-dev#15056
1 parent 91c883d commit 4baa0a7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pandas/tests/test_strings.py

+6
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,12 @@ def test_replace(self):
435435
for data in (['a', 'b', None], ['a', 'b', 'c', 'ad']):
436436
values = klass(data)
437437
self.assertRaises(TypeError, values.str.replace, 'a', repl)
438+
439+
# GH 15055, callable repl
440+
repl = lambda m: m.group(0).swapcase()
441+
result = values.str.replace('[a-z][A-Z]{2}', repl, n=2)
442+
exp = Series([u('foObaD__baRbaD'), NA])
443+
tm.assert_series_equal(result, exp)
438444

439445
def test_repeat(self):
440446
values = Series(['a', 'b', NA, 'c', NA, 'd'])

0 commit comments

Comments
 (0)