Skip to content

PERF: improve Integer/BooleanArray astype to numeric dtypes #29839

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

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:

# 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

No one assigned

    Labels

    AstypeNA - MaskedArraysRelated to pd.NA and nullable extension arraysPerformanceMemory or execution speed performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions