CLN: clarify TypeError for IndexSlice argument to pd.xs (#35411) · pandas-dev/pandas@9843926 (original) (raw)

1

1

`import numpy as np

`

2

2

`import pytest

`

3

3

``

4

``

`-

from pandas import DataFrame, Index, MultiIndex, Series, concat, date_range

`

``

4

`+

from pandas import DataFrame, Index, IndexSlice, MultiIndex, Series, concat, date_range

`

5

5

`import pandas._testing as tm

`

6

6

`import pandas.core.common as com

`

7

7

``

`@@ -220,6 +220,27 @@ def test_xs_level_series_slice_not_implemented(

`

220

220

`s[2000, 3:4]

`

221

221

``

222

222

``

``

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

+

223

244

`def test_series_getitem_multiindex_xs():

`

224

245

`# GH6258

`

225

246

`dt = list(date_range("20130903", periods=3))

`