Skip to content

Commit e7dbb76

Browse files
simonjayhawkinsjreback
authored andcommitted
move test_non_reducing_slice_on_multiindex (#24545)
1 parent e76c90e commit e7dbb76

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

pandas/tests/indexing/multiindex/test_slice.py

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pandas as pd
99
from pandas import DataFrame, Index, MultiIndex, Series, Timestamp
10+
from pandas.core.indexing import _non_reducing_slice
1011
from pandas.tests.indexing.common import _mklbl
1112
from pandas.util import testing as tm
1213

@@ -556,3 +557,20 @@ def test_int_series_slicing(
556557
result = ymd[5:]
557558
expected = ymd.reindex(s.index[5:])
558559
tm.assert_frame_equal(result, expected)
560+
561+
def test_non_reducing_slice_on_multiindex(self):
562+
# GH 19861
563+
dic = {
564+
('a', 'd'): [1, 4],
565+
('a', 'c'): [2, 3],
566+
('b', 'c'): [3, 2],
567+
('b', 'd'): [4, 1]
568+
}
569+
df = pd.DataFrame(dic, index=[0, 1])
570+
idx = pd.IndexSlice
571+
slice_ = idx[:, idx['b', 'd']]
572+
tslice_ = _non_reducing_slice(slice_)
573+
574+
result = df.loc[tslice_]
575+
expected = pd.DataFrame({('b', 'd'): [4, 1]})
576+
tm.assert_frame_equal(result, expected)

pandas/tests/indexing/test_indexing.py

-17
Original file line numberDiff line numberDiff line change
@@ -812,23 +812,6 @@ def test_non_reducing_slice(self):
812812
tslice_ = _non_reducing_slice(slice_)
813813
assert isinstance(df.loc[tslice_], DataFrame)
814814

815-
def test_non_reducing_slice_on_multiindex(self):
816-
# GH 19861
817-
dic = {
818-
('a', 'd'): [1, 4],
819-
('a', 'c'): [2, 3],
820-
('b', 'c'): [3, 2],
821-
('b', 'd'): [4, 1]
822-
}
823-
df = pd.DataFrame(dic, index=[0, 1])
824-
idx = pd.IndexSlice
825-
slice_ = idx[:, idx['b', 'd']]
826-
tslice_ = _non_reducing_slice(slice_)
827-
828-
result = df.loc[tslice_]
829-
expected = pd.DataFrame({('b', 'd'): [4, 1]})
830-
tm.assert_frame_equal(result, expected)
831-
832815
def test_list_slice(self):
833816
# like dataframe getitem
834817
slices = [['A'], Series(['A']), np.array(['A'])]

0 commit comments

Comments
 (0)