From f3391a45f96e3be0900f7ef0a40b4e61d64785aa Mon Sep 17 00:00:00 2001 From: Patrick Hoefler <61934744+phofl@users.noreply.github.com> Date: Sat, 12 Aug 2023 14:06:02 +0200 Subject: [PATCH] Backport PR #54498: Speed up string inference in maybe_convert_objects --- pandas/_libs/lib.pyx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 55819ebd1f15e..a96152ccdf3cc 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -2681,14 +2681,13 @@ def maybe_convert_objects(ndarray[object] objects, seen.object_ = True elif seen.str_: - if is_string_array(objects, skipna=True): - if using_pyarrow_string_dtype(): - import pyarrow as pa + if using_pyarrow_string_dtype() and is_string_array(objects, skipna=True): + import pyarrow as pa - from pandas.core.dtypes.dtypes import ArrowDtype + from pandas.core.dtypes.dtypes import ArrowDtype - dtype = ArrowDtype(pa.string()) - return dtype.construct_array_type()._from_sequence(objects, dtype=dtype) + dtype = ArrowDtype(pa.string()) + return dtype.construct_array_type()._from_sequence(objects, dtype=dtype) seen.object_ = True elif seen.interval_: