Skip to content

setitem on empty DataFrame / Series casts to RangeIndex #17101

Closed
@TomAugspurger

Description

@TomAugspurger

I thought we had an issue for this, but couldn't find it.

In [41]: df = pd.DataFrame(columns=['A'])

In [42]: df.index.dtype
Out[42]: dtype('O')

In [43]: df['A'] = []

In [44]: df.index.dtype
Out[44]: dtype('int64')

In [45]: df.index
Out[45]: RangeIndex(start=0, stop=0, step=1)

I this should still be empty an empty Index (though see #16961 which proposes change pd.Series() to have that use a range index. Not sure if that's a good idea or not).

xref dask/dask#2564

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dtype ConversionsUnexpected or buggy dtype conversionsIndexingRelated to indexing on series/frames, not to indexes themselvesgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions