@@ -1106,20 +1106,29 @@ def convert_dtypes(
1106
1106
from pandas .core .arrays .arrow .dtype import ArrowDtype
1107
1107
from pandas .core .arrays .string_ import StringDtype
1108
1108
1109
- if isinstance (inferred_dtype , PandasExtensionDtype ):
1110
- base_dtype = inferred_dtype .base
1111
- elif isinstance (inferred_dtype , (BaseMaskedDtype , ArrowDtype )):
1112
- base_dtype = inferred_dtype .numpy_dtype
1113
- elif isinstance (inferred_dtype , StringDtype ):
1114
- base_dtype = np .dtype (str )
1115
- else :
1116
- # error: Incompatible types in assignment (expression has type
1117
- # "Union[str, Any, dtype[Any], ExtensionDtype]",
1118
- # variable has type "Union[dtype[Any], ExtensionDtype, None]")
1119
- base_dtype = inferred_dtype # type: ignore[assignment]
1120
- pa_type = to_pyarrow_type (base_dtype )
1121
- if pa_type is not None :
1122
- inferred_dtype = ArrowDtype (pa_type )
1109
+ assert not isinstance (inferred_dtype , str )
1110
+
1111
+ if (
1112
+ (convert_integer and inferred_dtype .kind in "iu" )
1113
+ or (convert_floating and inferred_dtype .kind in "fc" )
1114
+ or (convert_boolean and inferred_dtype .kind == "b" )
1115
+ or (convert_string and isinstance (inferred_dtype , StringDtype ))
1116
+ or (
1117
+ inferred_dtype .kind not in "iufcb"
1118
+ and not isinstance (inferred_dtype , StringDtype )
1119
+ )
1120
+ ):
1121
+ if isinstance (inferred_dtype , PandasExtensionDtype ):
1122
+ base_dtype = inferred_dtype .base
1123
+ elif isinstance (inferred_dtype , (BaseMaskedDtype , ArrowDtype )):
1124
+ base_dtype = inferred_dtype .numpy_dtype
1125
+ elif isinstance (inferred_dtype , StringDtype ):
1126
+ base_dtype = np .dtype (str )
1127
+ else :
1128
+ base_dtype = inferred_dtype
1129
+ pa_type = to_pyarrow_type (base_dtype )
1130
+ if pa_type is not None :
1131
+ inferred_dtype = ArrowDtype (pa_type )
1123
1132
1124
1133
# error: Incompatible return value type (got "Union[str, Union[dtype[Any],
1125
1134
# ExtensionDtype]]", expected "Union[dtype[Any], ExtensionDtype]")
0 commit comments