Skip to content

Commit e0cbc37

Browse files
toobazjorisvandenbossche
authored andcommitted
TST: partial indexing with __getitem__ and integer labels (pandas-dev#16029)
closes pandas-dev#12416
1 parent 1a09437 commit e0cbc37

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/tests/indexing/test_multiindex.py

+24
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,30 @@ def test_loc_multiindex(self):
275275
xp = mi_int.ix[4]
276276
tm.assert_frame_equal(rs, xp)
277277

278+
def test_getitem_partial_int(self):
279+
# GH 12416
280+
# with single item
281+
l1 = [10, 20]
282+
l2 = ['a', 'b']
283+
df = DataFrame(index=range(2),
284+
columns=pd.MultiIndex.from_product([l1, l2]))
285+
expected = DataFrame(index=range(2),
286+
columns=l2)
287+
result = df[20]
288+
tm.assert_frame_equal(result, expected)
289+
290+
# with list
291+
expected = DataFrame(index=range(2),
292+
columns=pd.MultiIndex.from_product([l1[1:], l2]))
293+
result = df[[20]]
294+
tm.assert_frame_equal(result, expected)
295+
296+
# missing item:
297+
with tm.assertRaisesRegexp(KeyError, '1'):
298+
df[1]
299+
with tm.assertRaisesRegexp(KeyError, "'\[1\] not in index'"):
300+
df[[1]]
301+
278302
def test_loc_multiindex_indexer_none(self):
279303

280304
# GH6788

0 commit comments

Comments
 (0)