Skip to content

Commit f69ff12

Browse files
committed
Merge pull request #7404 from jreback/mi_indexing
BUG: mi indexing bugs (GH7399,GH7400)
2 parents a25ff6e + c578893 commit f69ff12

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

doc/source/v0.14.1.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ Bug Fixes
164164

165165

166166

167-
- Bug in ``.ix`` getitem should always return a Series (:issue:`7150`)
168-
169-
170-
171-
172167

173168

174169

@@ -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

+3-3
Original file line numberDiff line numberDiff line change
@@ -3526,11 +3526,11 @@ def _get_level_indexer(self, key, level=0):
35263526
# handle a slice, returnig a slice if we can
35273527
# otherwise a boolean indexer
35283528

3529-
start = level_index.get_loc(key.start)
3530-
stop = level_index.get_loc(key.stop)
3529+
start = level_index.get_loc(key.start or 0)
3530+
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

+23
Original file line numberDiff line numberDiff line change
@@ -1325,6 +1325,29 @@ def test_loc_multiindex(self):
13251325
result = df.loc[[1,2]]
13261326
assert_frame_equal(result, expected)
13271327

1328+
# GH 7399
1329+
# incomplete indexers
1330+
s = pd.Series(np.arange(15,dtype='int64'),MultiIndex.from_product([range(5), ['a', 'b', 'c']]))
1331+
expected = s.loc[:, 'a':'c']
1332+
1333+
result = s.loc[0:4, 'a':'c']
1334+
assert_series_equal(result, expected)
1335+
assert_series_equal(result, expected)
1336+
1337+
result = s.loc[:4, 'a':'c']
1338+
assert_series_equal(result, expected)
1339+
assert_series_equal(result, expected)
1340+
1341+
result = s.loc[0:, 'a':'c']
1342+
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)
13281351

13291352
def test_series_getitem_multiindex(self):
13301353

0 commit comments

Comments
 (0)