-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
AstypeNA - MaskedArraysRelated to pd.NA and nullable extension arraysRelated to pd.NA and nullable extension arraysPerformanceMemory or execution speed performanceMemory or execution speed performance
Description
Currently, in the IntegerArray or BooleanArray astype
, we first convert to object dtype, and then convert to the requested dtype.
For example, in IntegerArray.astype
:
pandas/pandas/core/arrays/integer.py
Lines 551 to 553 in 7d7f885
# coerce | |
data = self._coerce_to_ndarray() | |
return astype_nansafe(data, dtype, copy=None) |
where self._coerce_to_ndarray()
creates an object ndarray.
In case of converting to integer (and if there are no NaNs), or in case of converting to float, this roundtrip through object dtype is not needed (we can directly convert the _data
and in case of float set NaNs)
Metadata
Metadata
Assignees
Labels
AstypeNA - MaskedArraysRelated to pd.NA and nullable extension arraysRelated to pd.NA and nullable extension arraysPerformanceMemory or execution speed performanceMemory or execution speed performance