Skip to content

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

Merged
merged 8 commits into from
Apr 16, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,27 @@ def test_index_type_coercion(self):
idxr(s2)['0'] = 0
assert s2.index.is_object()

@pytest.mark.parametrize('idx', [
Index([1, 1, 3]),
Index(['a', 'a', 'b', 'c', 'c', 'd']),
Index([1, 1, 1, 2, 2, 3]),
Index([1, 1, 2, 3, 1, 2, 3, 3])
])
def test_duplicate_int_indexing(self, idx):
# GH 17347
s = pd.Series(range(len(idx)), idx)
dup_idx_filter = s.index.duplicated(keep=False)
Copy link
Member

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.

Copy link
Contributor Author

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!


# Check if s contains duplicated idx
if not dup_idx_filter.any:
pass
# Find the duplicate indexes
dup_idxes = s[dup_idx_filter].index.unique()

# Assert the duplicate indexes
for idx in dup_idxes:
assert s[idx].equals(s[[idx]])
Copy link
Member

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



class TestMisc(Base):

Expand Down