Skip to content

ENH: Index Pandas Dtype #43857

@ghost

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

No one assigned

    Labels

    Duplicate ReportDuplicate issue or pull requestEnhancementExtensionArrayExtending pandas with custom dtypes or arrays.IndexRelated to the Index class or subclasses

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions