From a793802ca08ba159558e36db95f8242fb0f44156 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Tue, 1 Nov 2022 21:02:17 -0400 Subject: [PATCH] Make the conversion from dtype to subclass just a little faster (#49393) Use kind to speed up dtype decision --- pandas/core/indexes/base.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index d8300bb29c274..590fb187e9a1f 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -106,7 +106,6 @@ is_scalar, is_signed_integer_dtype, is_string_dtype, - is_unsigned_integer_dtype, needs_i8_conversion, pandas_dtype, validate_all_hashable, @@ -591,20 +590,20 @@ def _dtype_to_subclass(cls, dtype: DtypeObj): return TimedeltaIndex - elif is_float_dtype(dtype): + elif dtype.kind == "f": from pandas.core.api import Float64Index return Float64Index - elif is_unsigned_integer_dtype(dtype): + elif dtype.kind == "u": from pandas.core.api import UInt64Index return UInt64Index - elif is_signed_integer_dtype(dtype): + elif dtype.kind == "i": from pandas.core.api import Int64Index return Int64Index - elif dtype == _dtype_obj: + elif dtype.kind == "O": # NB: assuming away MultiIndex return Index