Skip to content

Commit 7f2fc6a

Browse files
ENH: ArrayManager.convert without block fallback (#40196)
1 parent fd0bd91 commit 7f2fc6a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

pandas/core/internals/array_manager.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
astype_array_safe,
3131
find_common_type,
3232
infer_dtype_from_scalar,
33+
soft_convert_objects,
3334
)
3435
from pandas.core.dtypes.common import (
3536
is_bool_dtype,
@@ -527,13 +528,19 @@ def convert(
527528
numeric: bool = True,
528529
timedelta: bool = True,
529530
) -> ArrayManager:
530-
return self.apply_with_block(
531-
"convert",
532-
copy=copy,
533-
datetime=datetime,
534-
numeric=numeric,
535-
timedelta=timedelta,
536-
)
531+
def _convert(arr):
532+
if is_object_dtype(arr.dtype):
533+
return soft_convert_objects(
534+
arr,
535+
datetime=datetime,
536+
numeric=numeric,
537+
timedelta=timedelta,
538+
copy=copy,
539+
)
540+
else:
541+
return arr.copy() if copy else arr
542+
543+
return self.apply(_convert)
537544

538545
def replace(self, value, **kwargs) -> ArrayManager:
539546
assert np.ndim(value) == 0, value

0 commit comments

Comments
 (0)