Skip to content

TST: move test_non_reducing_slice_on_multiindex #24545

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 1 commit into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pandas/tests/indexing/multiindex/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pandas as pd
from pandas import DataFrame, Index, MultiIndex, Series, Timestamp
from pandas.core.indexing import _non_reducing_slice
from pandas.tests.indexing.common import _mklbl
from pandas.util import testing as tm

Expand Down Expand Up @@ -556,3 +557,20 @@ def test_int_series_slicing(
result = ymd[5:]
expected = ymd.reindex(s.index[5:])
tm.assert_frame_equal(result, expected)

def test_non_reducing_slice_on_multiindex(self):
# GH 19861
dic = {
('a', 'd'): [1, 4],
('a', 'c'): [2, 3],
('b', 'c'): [3, 2],
('b', 'd'): [4, 1]
}
df = pd.DataFrame(dic, index=[0, 1])
idx = pd.IndexSlice
slice_ = idx[:, idx['b', 'd']]
tslice_ = _non_reducing_slice(slice_)

result = df.loc[tslice_]
expected = pd.DataFrame({('b', 'd'): [4, 1]})
tm.assert_frame_equal(result, expected)
17 changes: 0 additions & 17 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,23 +812,6 @@ def test_non_reducing_slice(self):
tslice_ = _non_reducing_slice(slice_)
assert isinstance(df.loc[tslice_], DataFrame)

def test_non_reducing_slice_on_multiindex(self):
# GH 19861
dic = {
('a', 'd'): [1, 4],
('a', 'c'): [2, 3],
('b', 'c'): [3, 2],
('b', 'd'): [4, 1]
}
df = pd.DataFrame(dic, index=[0, 1])
idx = pd.IndexSlice
slice_ = idx[:, idx['b', 'd']]
tslice_ = _non_reducing_slice(slice_)

result = df.loc[tslice_]
expected = pd.DataFrame({('b', 'd'): [4, 1]})
tm.assert_frame_equal(result, expected)

def test_list_slice(self):
# like dataframe getitem
slices = [['A'], Series(['A']), np.array(['A'])]
Expand Down