@@ -975,6 +975,7 @@ def _replace_regex(
975975 inplace : bool = False ,
976976 mask = None ,
977977 using_cow : bool = False ,
978+ convert_string : bool = True ,
978979 already_warned = None ,
979980 ) -> list [Block ]:
980981 """
@@ -1025,7 +1026,7 @@ def _replace_regex(
10251026 already_warned .warned_already = True
10261027
10271028 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
10291030 )
10301031 opt = get_option ("future.no_silent_downcasting" )
10311032 if (len (nbs ) > 1 or nbs [0 ].dtype != block .dtype ) and not opt :
@@ -1057,8 +1058,6 @@ def replace_list(
10571058 """
10581059 values = self .values
10591060
1060- convert_string = self .dtype != _dtype_obj
1061-
10621061 if isinstance (values , Categorical ):
10631062 # TODO: avoid special-casing
10641063 # GH49404
@@ -1067,6 +1066,8 @@ def replace_list(
10671066 values ._replace (to_replace = src_list , value = dest_list , inplace = True )
10681067 return [blk ]
10691068
1069+ convert_string = self .dtype != _dtype_obj
1070+
10701071 # Exclude anything that we know we won't contain
10711072 pairs = [
10721073 (x , y ) for x , y in zip (src_list , dest_list ) if self ._can_hold_element (x )
@@ -1234,6 +1235,7 @@ def _replace_coerce(
12341235 inplace = inplace ,
12351236 mask = mask ,
12361237 using_cow = using_cow ,
1238+ convert_string = convert_string ,
12371239 )
12381240 else :
12391241 if value is None :
0 commit comments