Skip to content

Commit 8bcb1bf

Browse files
committed
created separate test
1 parent 1e04454 commit 8bcb1bf

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

pandas/tests/test_multilevel.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -1258,16 +1258,6 @@ def test_level_with_tuples(self):
12581258
tm.assert_frame_equal(result, expected)
12591259
tm.assert_frame_equal(result2, expected)
12601260

1261-
# GH 35301
1262-
msg = (
1263-
"Expected label or tuple of labels, got "
1264-
r"\(\('foo', 'qux', 0\), slice\(None, None, None\)\)"
1265-
)
1266-
with pytest.raises(TypeError, match=msg):
1267-
frame.xs(pd.IndexSlice[("foo", "qux", 0), :])
1268-
with pytest.raises(TypeError, match=msg):
1269-
series.xs(pd.IndexSlice[("foo", "qux", 0), :])
1270-
12711261
index = MultiIndex(
12721262
levels=[[("foo", "bar"), ("foo", "baz"), ("foo", "qux")], [0, 1]],
12731263
codes=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],
@@ -1290,6 +1280,26 @@ def test_level_with_tuples(self):
12901280
tm.assert_frame_equal(result, expected)
12911281
tm.assert_frame_equal(result2, expected)
12921282

1283+
def test_xs_with_IndexSlice(self):
1284+
# GH 35301
1285+
1286+
index = MultiIndex(
1287+
levels=[[("foo", "bar", 0), ("foo", "baz", 0), ("foo", "qux", 0)], [0, 1]],
1288+
codes=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],
1289+
)
1290+
1291+
series = Series(np.random.randn(6), index=index)
1292+
frame = DataFrame(np.random.randn(6, 4), index=index)
1293+
1294+
msg = (
1295+
"Expected label or tuple of labels, got "
1296+
r"\(\('foo', 'qux', 0\), slice\(None, None, None\)\)"
1297+
)
1298+
with pytest.raises(TypeError, match=msg):
1299+
frame.xs(pd.IndexSlice[("foo", "qux", 0), :])
1300+
with pytest.raises(TypeError, match=msg):
1301+
series.xs(pd.IndexSlice[("foo", "qux", 0), :])
1302+
12931303
def test_mixed_depth_pop(self):
12941304
arrays = [
12951305
["a", "top", "top", "routine1", "routine1", "routine2"],

0 commit comments

Comments
 (0)