Skip to content

Commit 84280cb

Browse files
code change based on tom review
1 parent de1253f commit 84280cb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/core/strings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=None):
459459
regex : boolean, default None
460460
- If True, assumes the passed-in pattern is a regular expression.
461461
- If False, treats the pattern as a literal string
462-
- If pat is single special character, default regex is False.
462+
- If `pat` is a single character and `regex` is not specified, `pat`
463+
is interpreted as a string literal. If `pat` is also a regular
464+
expression symbol, a warning is issued that in the future `pat`
465+
will be interpreted as a regex, rather than a literal.
463466
- Cannot be set to False if `pat` is a compiled regex or `repl` is
464467
a callable.
465468
@@ -580,7 +583,7 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=None):
580583
"regex=False")
581584
# if regex is default None, and a single special character is given
582585
# in pat, still take it as a literal, and raise the Future warning
583-
if regex is None and len(pat) == 1 and re.findall(r"\W", pat):
586+
if regex is None and len(pat) == 1 and re.escape(pat) != pat:
584587
warnings.warn("'{}' is interpreted as a literal in ".format(pat) +
585588
"default, not regex. It will change in the future.",
586589
FutureWarning)

0 commit comments

Comments
 (0)