Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: change regex try/except to checks #28121

Merged
merged 1 commit into from
Aug 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2830,9 +2830,9 @@ def _replace_single(
regex = regex_re or to_rep_re

# try to get the pattern attribute (compiled re) or it's a string
try:
if is_re(to_replace):
pattern = to_replace.pattern
except AttributeError:
else:
pattern = to_replace

# if the pattern is not empty and to_replace is either a string or a
Expand All @@ -2853,18 +2853,18 @@ def _replace_single(
if isna(value) or not isinstance(value, str):

def re_replacer(s):
try:
if is_re(rx) and isinstance(s, str):
return value if rx.search(s) is not None else s
except TypeError:
else:
return s

else:
# value is guaranteed to be a string here, s can be either a string
# or null if it's null it gets returned
def re_replacer(s):
try:
if is_re(rx) and isinstance(s, str):
return rx.sub(value, s)
except TypeError:
else:
return s

f = np.vectorize(re_replacer, otypes=[self.dtype])
Expand Down