Skip to content

BUG: position indexing in getitem with duplicated index #11747

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
jreback opened this issue Dec 2, 2015 · 5 comments · Fixed by #41431
Closed

BUG: position indexing in getitem with duplicated index #11747

jreback opened this issue Dec 2, 2015 · 5 comments · Fixed by #41431
Assignees
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Dec 2, 2015

in py3, the following should correctly raise an IndexError

In [1]: s = Series(range(5),index=list('aacde'))

In [2]: s[5]
IndexError

however
a positional indexer that is in the range should work
s[3]

Further more, this must be a monotonic increasing duplicated index to trigger

In [8]: Series(range(5),index=list('aabcd'))[3]
IndexError: 3

In [9]: Series(range(5),index=list('aadcb'))[3]
Out[9]: 3

simple change needed here
in that if its an integer and in the range of the index it can return that value.

Though maybe we should just detect this in the cython code (index.pyx/Index/_get_loc_duplicated)

needless to say, no tests for this :<

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Difficulty Novice labels Dec 2, 2015
@jreback jreback added this to the 0.18.0 milestone Dec 2, 2015
@jreback jreback modified the milestones: Next Major Release, 0.18.0 Feb 10, 2016
@topper-123
Copy link
Contributor

Removing the 2/3 compat label, as this is no longer compat related, as we now only support Python3.

@jbrockmendel
Copy link
Member

This works on master, needs test

@jbrockmendel jbrockmendel added the Needs Tests Unit test(s) needed to prevent regressions label Nov 5, 2020
@jbrockmendel jbrockmendel changed the title BUG: position indexing in getitem with duplicated index object under py3 BUG: position indexing in getitem with duplicated index Nov 5, 2020
@mroeschke mroeschke added good first issue and removed Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Apr 21, 2021
@jackzyliu
Copy link
Contributor

take

@jackzyliu
Copy link
Contributor

Hi, I am planning on putting the tests in pandas/tests/series/indexing/test_getitem.py. Please let me know if there is preference for another location (e.g. test_indexing.py).

@jbrockmendel
Copy link
Member

pandas/tests/series/indexing/test_getitem.py

perfect

@jreback jreback modified the milestones: Contributions Welcome, 1.3 May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants