Skip to content

Commit f0cf004

Browse files
jbrockmendelproost
authored andcommitted
Change trys to checks (pandas-dev#28121)
1 parent 269d00c commit f0cf004

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pandas/core/internals/blocks.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2830,9 +2830,9 @@ def _replace_single(
28302830
regex = regex_re or to_rep_re
28312831

28322832
# try to get the pattern attribute (compiled re) or it's a string
2833-
try:
2833+
if is_re(to_replace):
28342834
pattern = to_replace.pattern
2835-
except AttributeError:
2835+
else:
28362836
pattern = to_replace
28372837

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

28552855
def re_replacer(s):
2856-
try:
2856+
if is_re(rx) and isinstance(s, str):
28572857
return value if rx.search(s) is not None else s
2858-
except TypeError:
2858+
else:
28592859
return s
28602860

28612861
else:
28622862
# value is guaranteed to be a string here, s can be either a string
28632863
# or null if it's null it gets returned
28642864
def re_replacer(s):
2865-
try:
2865+
if is_re(rx) and isinstance(s, str):
28662866
return rx.sub(value, s)
2867-
except TypeError:
2867+
else:
28682868
return s
28692869

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

0 commit comments

Comments
 (0)