-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Closed
Labels
IndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesNeeds TestsUnit test(s) needed to prevent regressionsUnit test(s) needed to prevent regressionsgood first issue
Milestone
Description
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: int64It 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)
Metadata
Metadata
Assignees
Labels
IndexingRelated to indexing on series/frames, not to indexes themselvesRelated to indexing on series/frames, not to indexes themselvesNeeds TestsUnit test(s) needed to prevent regressionsUnit test(s) needed to prevent regressionsgood first issue