Skip to content

Commit 9ed2654

Browse files
committed
move test to test_xs.py
1 parent fc9c4cd commit 9ed2654

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

pandas/tests/indexing/multiindex/test_xs.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from pandas import DataFrame, Index, MultiIndex, Series, concat, date_range
4+
from pandas import DataFrame, Index, IndexSlice, MultiIndex, Series, concat, date_range
55
import pandas._testing as tm
66
import pandas.core.common as com
77

@@ -220,6 +220,27 @@ def test_xs_level_series_slice_not_implemented(
220220
s[2000, 3:4]
221221

222222

223+
def test_xs_IndexSlice_argument_not_implemented():
224+
# GH 35301
225+
226+
index = MultiIndex(
227+
levels=[[("foo", "bar", 0), ("foo", "baz", 0), ("foo", "qux", 0)], [0, 1]],
228+
codes=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],
229+
)
230+
231+
series = Series(np.random.randn(6), index=index)
232+
frame = DataFrame(np.random.randn(6, 4), index=index)
233+
234+
msg = (
235+
"Expected label or tuple of labels, got "
236+
r"\(\('foo', 'qux', 0\), slice\(None, None, None\)\)"
237+
)
238+
with pytest.raises(TypeError, match=msg):
239+
frame.xs(IndexSlice[("foo", "qux", 0), :])
240+
with pytest.raises(TypeError, match=msg):
241+
series.xs(IndexSlice[("foo", "qux", 0), :])
242+
243+
223244
def test_series_getitem_multiindex_xs():
224245
# GH6258
225246
dt = list(date_range("20130903", periods=3))

pandas/tests/test_multilevel.py

-20
Original file line numberDiff line numberDiff line change
@@ -1280,26 +1280,6 @@ def test_level_with_tuples(self):
12801280
tm.assert_frame_equal(result, expected)
12811281
tm.assert_frame_equal(result2, expected)
12821282

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-
13031283
def test_mixed_depth_pop(self):
13041284
arrays = [
13051285
["a", "top", "top", "routine1", "routine1", "routine2"],

0 commit comments

Comments
 (0)