-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: positional getitem indexing with list on Series with duplicate integer index fails #26083
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
Conversation
Create test case for issue GH17347
Hello @tranctan96! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-04-15 17:04:32 UTC |
Codecov Report
@@ Coverage Diff @@
## master #26083 +/- ##
=========================================
Coverage ? 91.94%
=========================================
Files ? 175
Lines ? 52444
Branches ? 0
=========================================
Hits ? 48221
Misses ? 4223
Partials ? 0
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26083 +/- ##
=========================================
Coverage ? 91.95%
=========================================
Files ? 175
Lines ? 52412
Branches ? 0
=========================================
Hits ? 48195
Misses ? 4217
Partials ? 0
Continue to review full report at Codecov.
|
Create test case for issue GH17347
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments.
|
||
# Assert the duplicate indexes | ||
for idx in dup_idxes: | ||
assert s[idx].equals(s[[idx]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use tm.assert_series_equal
def test_duplicate_int_indexing(self, idx): | ||
# GH 17347 | ||
s = pd.Series(range(len(idx)), idx) | ||
dup_idx_filter = s.index.duplicated(keep=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose for all this duplicated
logic? You can just copy the example from the original issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi ! Thank you for your review. This is my first time making a test case contribution, so i just figured it out that i overdid it. I'm fixing it now!
def test_duplicate_int_indexing(self): | ||
# GH 17347 | ||
s = pd.Series(range(3), index=[1, 1, 3]) | ||
tm.assert_series_equal(s[1], s[[1]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also test loc
?
And format the test like
result = ...
expected = ...
tm.assert_series_equal(result, expected)
@@ -623,6 +623,15 @@ def test_index_type_coercion(self): | |||
idxr(s2)['0'] = 0 | |||
assert s2.index.is_object() | |||
|
|||
def test_duplicate_int_indexing(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use parameterize like
@pytest.parameterize('case', [lambda s: s.__getitem__, lambda: s.loc])
def test_duplicate_int_indexing(self, case):
expected = s.iloc[[1]]
result = case(s)[[1]]
def test_duplicate_int_indexing(self): | ||
# GH 17347 | ||
s = pd.Series(range(3), index=[1, 1, 3]) | ||
expected = s[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this after def test_dups_fancy_indexing2(self)
thanks @tranctan96 |
…nteger index fails (pandas-dev#26083)
Create test case for issue GH17347