Skip to content

Commit 0acd7be

Browse files
add future deprecation test and clean code based on review
1 parent 35a3367 commit 0acd7be

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ Other API Changes
4040
Deprecations
4141
~~~~~~~~~~~~
4242

43-
-
44-
-
45-
-
43+
- :func:`Series.str.replace`, the default regex for single character might be deprecated.
4644

4745

4846
.. _whatsnew_0250.prior_deprecations:

pandas/core/strings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=None):
581581
# if regex is default None, and a single special character is given
582582
# in pat, still take it as a literal, and raise the Future warning
583583
if regex is None and len(pat) == 1 and re.findall(r"\W", pat):
584-
warnings.warn("'%s' is interpreted as a literal in " % pat +
584+
warnings.warn("'{}' is interpreted as a literal in ".format(pat) +
585585
"default, not regex. It will change in the future.",
586586
FutureWarning)
587587
f = lambda x: x.replace(pat, repl, n)

pandas/tests/test_strings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,10 +3441,13 @@ def test_replace_single_pattern(self, regex, expected_array):
34413441
expected = Series(expected_array)
34423442
tm.assert_series_equal(result, expected)
34433443

3444-
@pytest.mark.filterwarnings("ignore: '.' is interpreted as a literal")
34453444
def test_replace_without_specifying_regex_parameter(self):
34463445
values = Series(['a.c'])
34473446
# GH: 24804
3448-
result = values.str.replace('.', 'b')
3447+
# test future deprecation warning
3448+
msg = "'.' is interpreted as a literal"
3449+
with pytest.warns(FutureWarning, match=msg):
3450+
result = values.str.replace('.', 'b')
34493451
expected = Series(['abc'])
34503452
tm.assert_series_equal(result, expected)
3453+

0 commit comments

Comments
 (0)