Skip to content

Commit

Permalink
Fix testing bug for .str.replace
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Joost Kranendonk committed Jan 6, 2017
1 parent 30d4727 commit 067a7a8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,19 @@ def test_replace(self):
values = klass(data)
self.assertRaises(TypeError, values.str.replace, 'a', repl)

# GH 15055, callable repl
## GH 15055, callable repl
values = Series(['fooBAD__barBAD', NA])

# test with callable
repl = lambda m: m.group(0).swapcase()
result = values.str.replace('[a-z][A-Z]{2}', repl, n=2)
exp = Series(['foObaD__baRbaD', NA])
tm.assert_series_equal(result, exp)

# test with wrong type
repl = lambda m: m.group(0).swapcase()
result = values.str.replace('[a-z][A-Z]{2}', repl, n=2)
exp = Series([u('foObaD__baRbaD'), NA])
exp = Series(['foObaD__baRbaD', NA])
tm.assert_series_equal(result, exp)

def test_repeat(self):
Expand Down

0 comments on commit 067a7a8

Please sign in to comment.