File tree 1 file changed +6
-6
lines changed
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -2830,9 +2830,9 @@ def _replace_single(
2830
2830
regex = regex_re or to_rep_re
2831
2831
2832
2832
# try to get the pattern attribute (compiled re) or it's a string
2833
- try :
2833
+ if is_re ( to_replace ) :
2834
2834
pattern = to_replace .pattern
2835
- except AttributeError :
2835
+ else :
2836
2836
pattern = to_replace
2837
2837
2838
2838
# if the pattern is not empty and to_replace is either a string or a
@@ -2853,18 +2853,18 @@ def _replace_single(
2853
2853
if isna (value ) or not isinstance (value , str ):
2854
2854
2855
2855
def re_replacer (s ):
2856
- try :
2856
+ if is_re ( rx ) and isinstance ( s , str ) :
2857
2857
return value if rx .search (s ) is not None else s
2858
- except TypeError :
2858
+ else :
2859
2859
return s
2860
2860
2861
2861
else :
2862
2862
# value is guaranteed to be a string here, s can be either a string
2863
2863
# or null if it's null it gets returned
2864
2864
def re_replacer (s ):
2865
- try :
2865
+ if is_re ( rx ) and isinstance ( s , str ) :
2866
2866
return rx .sub (value , s )
2867
- except TypeError :
2867
+ else :
2868
2868
return s
2869
2869
2870
2870
f = np .vectorize (re_replacer , otypes = [self .dtype ])
You can’t perform that action at this time.
0 commit comments