Skip to content

Commit c578893

Browse files
committed
BUG: Bug in multi-index slicing with a step in a sliced level (GH7400)
1 parent 27555e7 commit c578893

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

doc/source/v0.14.1.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ Bug Fixes
160160

161161

162162

163-
- Bug in multi-index slicing with incomplete indexers (:issue:`7399`)
164-
165-
166-
167-
- Bug in ``.ix`` getitem should always return a Series (:issue:`7150`)
168163

169164

170165

@@ -216,3 +211,6 @@ Bug Fixes
216211
(:issue:`7366`).
217212
- Bug where ``NDFrame.replace()`` didn't correctly replace objects with
218213
``Period`` values (:issue:`7379`).
214+
- Bug in ``.ix`` getitem should always return a Series (:issue:`7150`)
215+
- Bug in multi-index slicing with incomplete indexers (:issue:`7399`)
216+
- Bug in multi-index slicing with a step in a sliced level (:issue:`7400`)

pandas/core/index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3530,7 +3530,7 @@ def _get_level_indexer(self, key, level=0):
35303530
stop = level_index.get_loc(key.stop or len(level_index)-1)
35313531
step = key.step
35323532

3533-
if level > 0 or self.lexsort_depth == 0:
3533+
if level > 0 or self.lexsort_depth == 0 or step is not None:
35343534
# need to have like semantics here to right
35353535
# searching as when we are using a slice
35363536
# so include the stop+1 (so we include stop)

pandas/tests/test_indexing.py

+11
Original file line numberDiff line numberDiff line change
@@ -1329,14 +1329,25 @@ def test_loc_multiindex(self):
13291329
# incomplete indexers
13301330
s = pd.Series(np.arange(15,dtype='int64'),MultiIndex.from_product([range(5), ['a', 'b', 'c']]))
13311331
expected = s.loc[:, 'a':'c']
1332+
13321333
result = s.loc[0:4, 'a':'c']
13331334
assert_series_equal(result, expected)
1335+
assert_series_equal(result, expected)
13341336

13351337
result = s.loc[:4, 'a':'c']
13361338
assert_series_equal(result, expected)
1339+
assert_series_equal(result, expected)
13371340

13381341
result = s.loc[0:, 'a':'c']
13391342
assert_series_equal(result, expected)
1343+
assert_series_equal(result, expected)
1344+
1345+
# GH 7400
1346+
# multiindexer gettitem with list of indexers skips wrong element
1347+
s = pd.Series(np.arange(15,dtype='int64'),MultiIndex.from_product([range(5), ['a', 'b', 'c']]))
1348+
expected = s.iloc[[6,7,8,12,13,14]]
1349+
result = s.loc[2:4:2, 'a':'c']
1350+
assert_series_equal(result, expected)
13401351

13411352
def test_series_getitem_multiindex(self):
13421353

0 commit comments

Comments
 (0)