PERF: improve Integer/BooleanArray astype to numeric dtypes #29839
Labels
Astype
NA - MaskedArrays
Related to pd.NA and nullable extension arrays
Performance
Memory or execution speed performance
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
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)The text was updated successfully, but these errors were encountered: