@@ -975,6 +975,7 @@ def _replace_regex(
975
975
inplace : bool = False ,
976
976
mask = None ,
977
977
using_cow : bool = False ,
978
+ convert_string : bool = True ,
978
979
already_warned = None ,
979
980
) -> list [Block ]:
980
981
"""
@@ -1025,7 +1026,7 @@ def _replace_regex(
1025
1026
already_warned .warned_already = True
1026
1027
1027
1028
nbs = block .convert (
1028
- copy = False , using_cow = using_cow , convert_string = self . dtype != _dtype_obj
1029
+ copy = False , using_cow = using_cow , convert_string = convert_string
1029
1030
)
1030
1031
opt = get_option ("future.no_silent_downcasting" )
1031
1032
if (len (nbs ) > 1 or nbs [0 ].dtype != block .dtype ) and not opt :
@@ -1057,8 +1058,6 @@ def replace_list(
1057
1058
"""
1058
1059
values = self .values
1059
1060
1060
- convert_string = self .dtype != _dtype_obj
1061
-
1062
1061
if isinstance (values , Categorical ):
1063
1062
# TODO: avoid special-casing
1064
1063
# GH49404
@@ -1067,6 +1066,8 @@ def replace_list(
1067
1066
values ._replace (to_replace = src_list , value = dest_list , inplace = True )
1068
1067
return [blk ]
1069
1068
1069
+ convert_string = self .dtype != _dtype_obj
1070
+
1070
1071
# Exclude anything that we know we won't contain
1071
1072
pairs = [
1072
1073
(x , y ) for x , y in zip (src_list , dest_list ) if self ._can_hold_element (x )
@@ -1234,6 +1235,7 @@ def _replace_coerce(
1234
1235
inplace = inplace ,
1235
1236
mask = mask ,
1236
1237
using_cow = using_cow ,
1238
+ convert_string = convert_string ,
1237
1239
)
1238
1240
else :
1239
1241
if value is None :
0 commit comments