-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Duplicate ReportDuplicate issue or pull requestDuplicate issue or pull requestEnhancementExtensionArrayExtending pandas with custom dtypes or arrays.Extending pandas with custom dtypes or arrays.IndexRelated to the Index class or subclassesRelated to the Index class or subclasses

Description
Hello,
Is it possible to set pandas dtype-like to index.dtype
Pandas Dtypes Examples
pandas.Int64Dtype(), pandas.Int8Dtype()
Expected result
df.index = pd.Series(df['X'].astype('Int64'))
Index([1, 2, 3, 4, 5], dtype='Int64', name='X')
# instead of
Index([1, 2, 3, 4, 5], dtype='object', name='X')
Workaround
Im forcing change in dtype convertion (it expects to have not nullable values)
INDEX_TYPE_MAP = {
pandas.Int8Dtype(): numpy.int8,
pandas.Int16Dtype(): numpy.int16,
pandas.Int32Dtype(): numpy.int32,
pandas.Int64Dtype(): numpy.int64,
pandas.Float32Dtype(): numpy.float32,
pandas.Float64Dtype(): numpy.float64
}
Br
Nicolas
Metadata
Metadata
Assignees
Labels
Duplicate ReportDuplicate issue or pull requestDuplicate issue or pull requestEnhancementExtensionArrayExtending pandas with custom dtypes or arrays.Extending pandas with custom dtypes or arrays.IndexRelated to the Index class or subclassesRelated to the Index class or subclasses