From f791ff68d3a9baedd703f60af1b078f1cd62d575 Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Mon, 10 Nov 2014 20:55:15 +0000 Subject: [PATCH] Allowing empty slice in multi-indices. --- doc/source/whatsnew/v0.15.2.txt | 3 ++- pandas/core/index.py | 4 ++-- pandas/tests/test_indexing.py | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v0.15.2.txt b/doc/source/whatsnew/v0.15.2.txt index 4bcbcb82e7c83..b1fa6dbed442d 100644 --- a/doc/source/whatsnew/v0.15.2.txt +++ b/doc/source/whatsnew/v0.15.2.txt @@ -44,4 +44,5 @@ Experimental Bug Fixes ~~~~~~~~~ - Bug in ``groupby`` signatures that didn't include *args or **kwargs (:issue:`8733`). -- ``io.data.Options`` now raises ``RemoteDataError`` when no expiry dates are available from Yahoo (:issue:`8761`). \ No newline at end of file +- ``io.data.Options`` now raises ``RemoteDataError`` when no expiry dates are available from Yahoo (:issue:`8761`). +- Bug in slicing a multi-index with an empty list and at least one boolean indexer (:issue:`8781`) diff --git a/pandas/core/index.py b/pandas/core/index.py index a6907c3f8b5f2..40c0fdaf91fab 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -4148,9 +4148,9 @@ def _convert_indexer(r): # ignore not founds continue if len(k): - ranges.append(reduce(np.logical_or,indexers)) + ranges.append(reduce(np.logical_or, indexers)) else: - ranges.append(tuple([])) + ranges.append(np.zeros(self.labels[i].shape, dtype=bool)) elif _is_null_slice(k): # empty slice diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py index f41e1ac03f993..66307d58b2f27 100644 --- a/pandas/tests/test_indexing.py +++ b/pandas/tests/test_indexing.py @@ -2139,9 +2139,11 @@ def f(): df = DataFrame(np.random.randn(5, 6), index=range(5), columns=multi_index) df = df.sortlevel(0, axis=1) - result = df.loc[:, ([], slice(None))] + result1 = df.loc[:, ([], slice(None))] + result2 = df.loc[:, (['foo'], [])] expected = DataFrame(index=range(5),columns=multi_index.reindex([])[0]) - assert_frame_equal(result, expected) + assert_frame_equal(result1, expected) + assert_frame_equal(result2, expected) # regression from < 0.14.0 # GH 7914