Skip to content

reindex from a duplicate axis: inconsistent behaviour #8849

Open
@urraca

Description

@urraca

The behaviour below occurs in version '0.15.1'.

When a series has a duplicate index, the method reindex will raise an exception, unless the index passed to reindex is identical to the series' index.

I propose that when a series has a duplicate index, the method reindex should always raise an exception, because when a series with a duplicate index is to be conformed to a new index, the intended behaviour is always ambiguous.

This issue applies to the methods reindex_like and reindex_axis too.

Examples of current behaviour:

(a)

>>> pd.Series([1, 2, 3], index=['a', 'b', 'b']).reindex(['a', 'b'])
ValueError: cannot reindex from a duplicate axis

(b)

>>> pd.Series([1, 2, 3], index=['a', 'b', 'b']).reindex(['a', 'b', 'b'])
a    1
b    2
b    3
dtype: int64

The exception message in (a) implies that (b) should raise; but it doesn't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions