Skip to content

Commit 81c8a5f

Browse files
committed
Merge pull request pandas-dev#8781 from SylvainCorlay/empty_slice
Allowing empty slice in multi-indices
2 parents b4cc087 + f791ff6 commit 81c8a5f

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

doc/source/whatsnew/v0.15.2.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ Experimental
4444
Bug Fixes
4545
~~~~~~~~~
4646
- Bug in ``groupby`` signatures that didn't include *args or **kwargs (:issue:`8733`).
47-
- ``io.data.Options`` now raises ``RemoteDataError`` when no expiry dates are available from Yahoo (:issue:`8761`).
47+
- ``io.data.Options`` now raises ``RemoteDataError`` when no expiry dates are available from Yahoo (:issue:`8761`).
48+
- Bug in slicing a multi-index with an empty list and at least one boolean indexer (:issue:`8781`)

pandas/core/index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4148,9 +4148,9 @@ def _convert_indexer(r):
41484148
# ignore not founds
41494149
continue
41504150
if len(k):
4151-
ranges.append(reduce(np.logical_or,indexers))
4151+
ranges.append(reduce(np.logical_or, indexers))
41524152
else:
4153-
ranges.append(tuple([]))
4153+
ranges.append(np.zeros(self.labels[i].shape, dtype=bool))
41544154

41554155
elif _is_null_slice(k):
41564156
# empty slice

pandas/tests/test_indexing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2139,9 +2139,11 @@ def f():
21392139
df = DataFrame(np.random.randn(5, 6), index=range(5), columns=multi_index)
21402140
df = df.sortlevel(0, axis=1)
21412141

2142-
result = df.loc[:, ([], slice(None))]
2142+
result1 = df.loc[:, ([], slice(None))]
2143+
result2 = df.loc[:, (['foo'], [])]
21432144
expected = DataFrame(index=range(5),columns=multi_index.reindex([])[0])
2144-
assert_frame_equal(result, expected)
2145+
assert_frame_equal(result1, expected)
2146+
assert_frame_equal(result2, expected)
21452147

21462148
# regression from < 0.14.0
21472149
# GH 7914

0 commit comments

Comments
 (0)