Skip to content

Make the conversion from dtype to subclass just a little faster #49393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure that object dtype is the only one with dtype.kind == "O"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# NB: assuming away MultiIndex
return Index

Expand Down