From 8250e361fdcc340d4448aa30fba32a0f2f1e6365 Mon Sep 17 00:00:00 2001 From: Skipper Seabold Date: Sun, 19 May 2013 00:01:25 -0400 Subject: [PATCH 1/2] TST: Add failing str.replace test with flags --- pandas/tests/test_strings.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 2134eea186649..7763ed7bc75db 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -271,6 +271,13 @@ def test_replace(self): exp = Series([u'foobarBAD', NA]) tm.assert_series_equal(result, exp) + #flags + unicode + values = Series(["abcd,\xc3\xa0".decode("utf-8")]) + exp = Series(["abcd, \xc3\xa0".decode("utf-8")]) + result = values.str.replace("(?<=\w),(?=\w)", ", ", flags=re.UNICODE) + tm.assert_series_equal(result, exp) + + def test_repeat(self): values = Series(['a', 'b', NA, 'c', NA, 'd']) From 32d132354d8b2ef02e3ea8e4624abf59be32109f Mon Sep 17 00:00:00 2001 From: Skipper Seabold Date: Sun, 19 May 2013 00:11:33 -0400 Subject: [PATCH 2/2] ENH: Allow passing of flags in replace --- pandas/core/strings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 3521c9ff94b11..87a9ff7e9d95d 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -692,8 +692,9 @@ def contains(self, pat, case=True, flags=0, na=np.nan): return self._wrap_result(result) @copy(str_replace) - def replace(self, pat, repl, n=-1, case=True): - result = str_replace(self.series, pat, repl, n=n, case=case) + def replace(self, pat, repl, n=-1, case=True, flags=0): + result = str_replace(self.series, pat, repl, n=n, case=case, + flags=flags) return self._wrap_result(result) @copy(str_repeat)