Skip to content

Commit

Permalink
BUG: GH12896 where extra elements are returned in MultiIndex slicing
Browse files Browse the repository at this point in the history
closes #12896

Author: Ka Wo Chen <kawoc@tepper.cmu.edu>

Closes #13117 from kawochen/BUG-FIX-12896 and squashes the following commits:

7d49346 [Ka Wo Chen] BUG: GH12896 where extra elements are returned in MultiIndex slicing
  • Loading branch information
kawochen authored and jreback committed May 14, 2016
1 parent b385799 commit 2de2884
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.18.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Bug Fixes




- Bug in ``MultiIndex`` slicing where extra elements were returned when level is non-unique (:issue:`12896`)



Expand Down
3 changes: 2 additions & 1 deletion pandas/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,8 @@ def convert_indexer(start, stop, step, indexer=indexer, labels=labels):

else:
m = np.zeros(len(labels), dtype=bool)
m[np.in1d(labels, r, assume_unique=True)] = True
m[np.in1d(labels, r,
assume_unique=Index(labels).is_unique)] = True

return m

Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,18 @@ def test_multiindex_slicers_non_unique(self):
self.assertFalse(result.index.is_unique)
assert_frame_equal(result, expected)

# GH12896
# numpy-implementation dependent bug
ints = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 13, 14, 14, 16,
17, 18, 19, 200000, 200000]
n = len(ints)
idx = MultiIndex.from_arrays([['a'] * n, ints])
result = Series([1] * n, index=idx)
result = result.sort_index()
result = result.loc[(slice(None), slice(100000))]
expected = Series([1] * (n - 2), index=idx[:-2]).sort_index()
assert_series_equal(result, expected)

def test_multiindex_slicers_datetimelike(self):

# GH 7429
Expand Down

0 comments on commit 2de2884

Please sign in to comment.