From a6239215767b4178e96218887812d29b1a5b24a7 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 2 Jan 2019 09:20:48 +0000 Subject: [PATCH] move test_non_reducing_slice_on_multiindex --- pandas/tests/indexing/multiindex/test_slice.py | 18 ++++++++++++++++++ pandas/tests/indexing/test_indexing.py | 17 ----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pandas/tests/indexing/multiindex/test_slice.py b/pandas/tests/indexing/multiindex/test_slice.py index 596fe5d564a40..fcecb2b454eb6 100644 --- a/pandas/tests/indexing/multiindex/test_slice.py +++ b/pandas/tests/indexing/multiindex/test_slice.py @@ -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 @@ -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) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 2224c3ab9935a..03f1975c50d2a 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -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'])]