From 2ae727178d07b36f9d2f52f183cdf6c46c6461c3 Mon Sep 17 00:00:00 2001 From: Luke Manley Date: Sat, 1 Apr 2023 12:05:27 -0400 Subject: [PATCH] PERF: DataFrame.values for pyarrow-backed numeric types --- pandas/core/internals/managers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index ed1a9b193b3e4..47bb9c9a59e99 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -50,6 +50,7 @@ import pandas.core.algorithms as algos from pandas.core.arrays._mixins import NDArrayBackedExtensionArray +from pandas.core.arrays.arrow import ArrowDtype from pandas.core.arrays.sparse import SparseDtype import pandas.core.common as com from pandas.core.construction import ( @@ -1769,6 +1770,13 @@ def _interleave( if isinstance(dtype, SparseDtype): dtype = dtype.subtype dtype = cast(np.dtype, dtype) + elif ( + isinstance(dtype, ArrowDtype) + and dtype.numpy_dtype is not None + and dtype.numpy_dtype.kind in "fciub" + and all(blk.dtype == dtype and not blk.values._hasna for blk in self.blocks) + ): + dtype = dtype.numpy_dtype elif isinstance(dtype, ExtensionDtype): dtype = np.dtype("object") elif is_dtype_equal(dtype, str):