Skip to content

Commit 067a7a8

Browse files
author
Joost Kranendonk
authored
Fix testing bug for .str.replace
I copied a previous test as a draft, assumed that I could reuse `values` but did not mention it was redefined in the unicode and GH 13438 tests. Now corrected. Just redefine `values`. I could have put my test before the unicode tests but this keeps the order.
1 parent 30d4727 commit 067a7a8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pandas/tests/test_strings.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,19 @@ def test_replace(self):
436436
values = klass(data)
437437
self.assertRaises(TypeError, values.str.replace, 'a', repl)
438438

439-
# GH 15055, callable repl
439+
## GH 15055, callable repl
440+
values = Series(['fooBAD__barBAD', NA])
441+
442+
# test with callable
443+
repl = lambda m: m.group(0).swapcase()
444+
result = values.str.replace('[a-z][A-Z]{2}', repl, n=2)
445+
exp = Series(['foObaD__baRbaD', NA])
446+
tm.assert_series_equal(result, exp)
447+
448+
# test with wrong type
440449
repl = lambda m: m.group(0).swapcase()
441450
result = values.str.replace('[a-z][A-Z]{2}', repl, n=2)
442-
exp = Series([u('foObaD__baRbaD'), NA])
451+
exp = Series(['foObaD__baRbaD', NA])
443452
tm.assert_series_equal(result, exp)
444453

445454
def test_repeat(self):

0 commit comments

Comments
 (0)