@@ -478,40 +478,6 @@ def maybe_cast_pointwise_result(
478
478
return result
479
479
480
480
481
- def maybe_cast_to_pyarrow_result (result : ArrayLike , obj_dtype : DtypeObj ) -> ArrayLike :
482
- """
483
- Try casting result of a pointwise operation to its pyarrow dtype
484
- and arrow extension array if appropriate. If not possible,
485
- returns np.ndarray.
486
-
487
- Parameters
488
- ----------
489
- result : array-like
490
- Result to cast.
491
-
492
- Returns
493
- -------
494
- result : array-like
495
- result maybe casted to the dtype.
496
- """
497
- from pandas .core .construction import array as pd_array
498
-
499
- # maybe_convert_objects is unable to detect NA as nan
500
- # (detects it as object instead)
501
- stripped_result = result [~ isna (result )]
502
- npvalues = lib .maybe_convert_objects (stripped_result , try_float = False )
503
-
504
- if stripped_result .size == 0 :
505
- return maybe_cast_pointwise_result (npvalues , obj_dtype , numeric_only = True )
506
-
507
- try :
508
- dtype = convert_dtypes (npvalues , dtype_backend = "pyarrow" )
509
- out = pd_array (result , dtype = dtype )
510
- except (TypeError , ValueError , np .ComplexWarning ):
511
- out = npvalues
512
- return out
513
-
514
-
515
481
def _maybe_cast_to_extension_array (
516
482
cls : type [ExtensionArray ], obj : ArrayLike , dtype : ExtensionDtype | None = None
517
483
) -> ArrayLike :
@@ -1061,7 +1027,6 @@ def convert_dtypes(
1061
1027
np.dtype, or ExtensionDtype
1062
1028
"""
1063
1029
inferred_dtype : str | DtypeObj
1064
- orig_inferred_dtype = None
1065
1030
1066
1031
if (
1067
1032
convert_string or convert_integer or convert_boolean or convert_floating
@@ -1070,7 +1035,6 @@ def convert_dtypes(
1070
1035
inferred_dtype = lib .infer_dtype (input_array )
1071
1036
else :
1072
1037
inferred_dtype = input_array .dtype
1073
- orig_inferred_dtype = inferred_dtype
1074
1038
1075
1039
if is_string_dtype (inferred_dtype ):
1076
1040
if not convert_string or inferred_dtype == "bytes" :
@@ -1168,8 +1132,7 @@ def convert_dtypes(
1168
1132
elif isinstance (inferred_dtype , StringDtype ):
1169
1133
base_dtype = np .dtype (str )
1170
1134
else :
1171
- base_dtype = _infer_pyarrow_dtype (input_array , orig_inferred_dtype )
1172
-
1135
+ base_dtype = inferred_dtype
1173
1136
if (
1174
1137
base_dtype .kind == "O" # type: ignore[union-attr]
1175
1138
and input_array .size > 0
@@ -1180,10 +1143,8 @@ def convert_dtypes(
1180
1143
pa_type = pa .null ()
1181
1144
else :
1182
1145
pa_type = to_pyarrow_type (base_dtype )
1183
-
1184
1146
if pa_type is not None :
1185
1147
inferred_dtype = ArrowDtype (pa_type )
1186
-
1187
1148
elif dtype_backend == "numpy_nullable" and isinstance (inferred_dtype , ArrowDtype ):
1188
1149
# GH 53648
1189
1150
inferred_dtype = _arrow_dtype_mapping ()[inferred_dtype .pyarrow_dtype ]
@@ -1193,40 +1154,6 @@ def convert_dtypes(
1193
1154
return inferred_dtype # type: ignore[return-value]
1194
1155
1195
1156
1196
- def _infer_pyarrow_dtype (
1197
- input_array : ArrayLike ,
1198
- inferred_dtype : str ,
1199
- ) -> DtypeObj :
1200
- import pyarrow as pa
1201
-
1202
- if inferred_dtype == "date" :
1203
- return ArrowDtype (pa .date32 ())
1204
- elif inferred_dtype == "time" :
1205
- return ArrowDtype (pa .time64 ("us" ))
1206
- elif inferred_dtype == "bytes" :
1207
- return ArrowDtype (pa .binary ())
1208
- elif inferred_dtype == "decimal" :
1209
- from pyarrow import (
1210
- ArrowInvalid ,
1211
- ArrowMemoryError ,
1212
- ArrowNotImplementedError ,
1213
- )
1214
-
1215
- try :
1216
- pyarrow_array = pa .array (input_array )
1217
- return ArrowDtype (pyarrow_array .type )
1218
- except (
1219
- TypeError ,
1220
- ValueError ,
1221
- ArrowInvalid ,
1222
- ArrowMemoryError ,
1223
- ArrowNotImplementedError ,
1224
- ):
1225
- return input_array .dtype
1226
-
1227
- return input_array .dtype
1228
-
1229
-
1230
1157
def maybe_infer_to_datetimelike (
1231
1158
value : npt .NDArray [np .object_ ],
1232
1159
) -> np .ndarray | DatetimeArray | TimedeltaArray | PeriodArray | IntervalArray :
0 commit comments