8000 REF/TST: Add more pytest idiom to indexing/multiindex/test_getitem.py by simonjayhawkins · Pull Request #24053 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REF/TST: Add more pytest idiom to indexing/multiindex/test_getitem.py #24053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 11, 2018
Prev Previous commit
Next Next commit
split and parametrize test_series_getitem_multiindex
  • Loading branch information
simonjayhawkins committed Dec 10, 2018
commit 24d1a8dc940f15709fbb993e1ae5d564f97b417b
28 changes: 12 additions & 16 deletions pandas/tests/indexing/multiindex/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,25 @@
from pandas.util import testing as tm


def test_series_getitem_multiindex():
@pytest.mark.parametrize('access_method', [lambda s, x: s[:, x],
lambda s, x: s.loc[:, x],
lambda s, x: s.xs(x, level=1)])
@pytest.mark.parametrize('level1_value, expected', [
(0, Series([1], index=[0])),
(1, Series([2, 3], index=[1, 2]))
])
def test_series_getitem_multiindex(access_method, level1_value, expected):

# GH 6018
# series regression getitem with a multi-index

s = Series([1, 2, 3])
s.index = MultiIndex.from_tuples([(0, 0), (1, 1), (2, 1)])

result = s[:, 0]
expected = Series([1], index=[0])
tm.assert_series_equal(result, expected)

result = s.loc[:, 1]
expected = Series([2, 3], index=[1, 2])
result = access_method(s, level1_value)
tm.assert_series_equal(result, expected)

# xs
result = s.xs(0, level=0)
expected = Series([1], index=[0])
tm.assert_series_equal(result, expected)

result = s.xs(1, level=1)
expected = Series([2, 3], index=[1, 2])
tm.assert_series_equal(result, expected)

def test_series_getitem_multiindex_xs():
# GH6258
dt = list(date_range('20130903', periods=3))
idx = MultiIndex.from_product([list('AB'), dt])
Expand All @@ -43,6 +37,8 @@ 54C0 def test_series_getitem_multiindex():
expected = Series([1, 1], index=list('AB'))
tm.assert_series_equal(result, expected)


def test_series_getitem_multiindex_xs_by_label():
# GH5684
idx = MultiIndex.from_tuples([('a', 'one'), ('a', 'two'), ('b', 'one'),
('b', 'two')])
Expand Down
0