@@ -487,6 +487,8 @@ def __new__(
487487 if data .dtype .kind in ["i" , "u" , "f" ]:
488488 # maybe coerce to a sub-class
489489 arr = data
490+ elif data .dtype .kind in ["c" ]:
491+ arr = np .asarray (data )
490492 else :
491493 arr = com .asarray_tuplesafe (data , dtype = _dtype_obj )
492494
@@ -614,7 +616,9 @@ def _dtype_to_subclass(cls, dtype: DtypeObj):
614616 # NB: assuming away MultiIndex
615617 return Index
616618
617- elif issubclass (dtype .type , (str , bool , np .bool_ )):
619+ elif issubclass (
620+ dtype .type , (str , bool , np .bool_ , complex , np .complex64 , np .complex128 )
621+ ):
618622 return Index
619623
620624 raise NotImplementedError (dtype )
@@ -858,6 +862,11 @@ def _engine(
858862 # TODO(ExtensionIndex): use libindex.ExtensionEngine(self._values)
859863 return libindex .ObjectEngine (self ._get_engine_target ())
860864
865+ elif self .values .dtype == np .complex64 :
866+ return libindex .Complex64Engine (self ._get_engine_target ())
867+ elif self .values .dtype == np .complex128 :
868+ return libindex .Complex128Engine (self ._get_engine_target ())
869+
861870 # to avoid a reference cycle, bind `target_values` to a local variable, so
862871 # `self` is not passed into the lambda.
863872 target_values = self ._get_engine_target ()
@@ -5980,8 +5989,6 @@ def _find_common_type_compat(self, target) -> DtypeObj:
59805989 # FIXME: find_common_type incorrect with Categorical GH#38240
59815990 # FIXME: some cases where float64 cast can be lossy?
59825991 dtype = np .dtype (np .float64 )
5983- if dtype .kind == "c" :
5984- dtype = _dtype_obj
59855992 return dtype
59865993
59875994 @final
@@ -7120,7 +7127,7 @@ def _maybe_cast_data_without_dtype(
71207127 FutureWarning ,
71217128 stacklevel = 3 ,
71227129 )
7123- if result .dtype .kind in ["b" , "c" ]:
7130+ if result .dtype .kind in ["b" ]:
71247131 return subarr
71257132 result = ensure_wrapped_if_datetimelike (result )
71267133 return result
0 commit comments