Skip to content

Commit a4f483f

Browse files
committed
fix: use arrow backend for "\\d" replacements
1 parent 6689722 commit a4f483f

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

pandas/core/arrays/_arrow_string_mixins.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,12 @@ def _str_replace(
173173
or callable(repl)
174174
or not case
175175
or flags
176-
or (
177-
isinstance(repl, str)
178-
and r"\g<" in repl # Block named group references (\g<name>); numeric groups (\1) are supported by PyArrow
179-
)
176+
or (isinstance(repl, str) and r"\g<" in repl)
180177
):
181178
raise NotImplementedError(
182179
"replace is not supported with a re.Pattern, callable repl, "
183180
"case=False, flags!=0, or when the replacement string contains "
184-
"named group references (\\g<...>, \\d+)"
181+
"named group references (\\g<...>)"
185182
)
186183

187184
func = pc.replace_substring_regex if regex else pc.replace_substring

pandas/core/arrays/string_arrow.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ def _str_replace(
425425
or flags
426426
or ( # substitution contains a named group pattern
427427
# https://docs.python.org/3/library/re.html
428-
isinstance(repl, str)
429-
and (r"\g<" in repl or re.search(r"\\\d", repl) is not None)
428+
isinstance(repl, str) and r"\g<" in repl
430429
)
431430
):
432431
return super()._str_replace(pat, repl, n, case, flags, regex)

0 commit comments

Comments
 (0)