Skip to content

Commit

Permalink
Make the conversion from dtype to subclass just a little faster (#49393)
Browse files Browse the repository at this point in the history
Use kind to speed up dtype decision
  • Loading branch information
hmaarrfk authored Nov 2, 2022
1 parent 4e7ade7 commit a793802
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a793802

Please sign in to comment.