diff --git a/doc/source/whatsnew/v0.15.1.txt b/doc/source/whatsnew/v0.15.1.txt index ab1be57934ce7..5ba41b3bd62d4 100644 --- a/doc/source/whatsnew/v0.15.1.txt +++ b/doc/source/whatsnew/v0.15.1.txt @@ -246,7 +246,7 @@ Bug Fixes - Bug in ``Categorical`` reflected comparison operator raising if the first argument was a numpy array scalar (e.g. np.int64) (:issue:`8658`) - Bug in Panel indexing with a list-like (:issue:`8710`) - Compat issue is ``DataFrame.dtypes`` when ``options.mode.use_inf_as_null`` is True (:issue:`8722`) - +- Bug in slicing a multi-index level with an empty-list (:issue:`8737`) diff --git a/pandas/core/index.py b/pandas/core/index.py index 154410bbebf01..a6907c3f8b5f2 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -4147,8 +4147,10 @@ def _convert_indexer(r): # ignore not founds continue - - ranges.append(reduce(np.logical_or,indexers)) + if len(k): + ranges.append(reduce(np.logical_or,indexers)) + else: + ranges.append(tuple([])) elif _is_null_slice(k): # empty slice diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index 32b27e139cc21..f41e1ac03f993 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -2133,6 +2133,16 @@ def f(): result = s.loc[idx[:,['foo','bah']]] assert_series_equal(result,expected) + # GH 8737 + # empty indexer + multi_index = pd.MultiIndex.from_product((['foo', 'bar', 'baz'], ['alpha', 'beta'])) + df = DataFrame(np.random.randn(5, 6), index=range(5), columns=multi_index) + df = df.sortlevel(0, axis=1) + + result = df.loc[:, ([], slice(None))] + expected = DataFrame(index=range(5),columns=multi_index.reindex([])[0]) + assert_frame_equal(result, expected) + # regression from < 0.14.0 # GH 7914 df = DataFrame([[np.mean, np.median],['mean','median']],