Skip to content

BUG: positional getitem indexing with list on Series with duplicate integer index fails #17347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jorisvandenbossche opened this issue Aug 27, 2017 · 1 comment · Fixed by #26083
Labels
good first issue Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@jorisvandenbossche
Copy link
Member

Problem description

With a Series with integer index, __getitem__ / [] does positional indexing, but when you have a duplicate index and use a list indexer, you get a "ValueError: cannot reindex from a duplicate axis" (with .loc the same works OK)

Code Sample, a copy-pastable example if possible

In [28]: s = pd.Series(range(3), index=[1, 2, 3])

In [29]: s[1]
Out[29]: 0

In [30]: s[[1]]
Out[30]: 
1    0
dtype: int64

# duplicate index
In [31]: s = pd.Series(range(3), index=[1, 1, 3])

In [32]: s[1]
Out[32]: 
1    0
1    1
dtype: int64

In [33]: s[[1]]
...
ValueError: cannot reindex from a duplicate axis

In [34]: s.loc[[1]]
Out[34]: 
1    0
1    1
dtype: int64

It seems to only fail for integer index (eg with a string index s = pd.Series(range(3), index=['a', 'a', 'b']) the equivalent works ok)

@gfyoung gfyoung added the Indexing Related to indexing on series/frames, not to indexes themselves label Aug 27, 2017
@jorisvandenbossche
Copy link
Member Author

This seems to be fixed in the meantime. Would be good to add a test for it.

@jorisvandenbossche jorisvandenbossche added Needs Tests Unit test(s) needed to prevent regressions good first issue labels Mar 22, 2019
@jorisvandenbossche jorisvandenbossche added this to the Contributions Welcome milestone Mar 22, 2019
@jreback jreback modified the milestones: Contributions Welcome, 0.25.0 Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
3 participants