@@ -1258,16 +1258,6 @@ def test_level_with_tuples(self):
1258
1258
tm .assert_frame_equal (result , expected )
1259
1259
tm .assert_frame_equal (result2 , expected )
1260
1260
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
-
1271
1261
index = MultiIndex (
1272
1262
levels = [[("foo" , "bar" ), ("foo" , "baz" ), ("foo" , "qux" )], [0 , 1 ]],
1273
1263
codes = [[0 , 0 , 1 , 1 , 2 , 2 ], [0 , 1 , 0 , 1 , 0 , 1 ]],
@@ -1290,6 +1280,26 @@ def test_level_with_tuples(self):
1290
1280
tm .assert_frame_equal (result , expected )
1291
1281
tm .assert_frame_equal (result2 , expected )
1292
1282
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
+
1293
1303
def test_mixed_depth_pop (self ):
1294
1304
arrays = [
1295
1305
["a" , "top" , "top" , "routine1" , "routine1" , "routine2" ],
0 commit comments