Skip to content

BUG: bug in taking all on a multi-index when only level 0 is specified (GH6788) #6790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,10 @@ def _convert_to_indexer(self, obj, axis=0, is_setter=False):
level = 0
_, indexer = labels.reindex(objarr, level=level)

# take all
if indexer is None:
indexer = np.arange(len(labels))

check = labels.levels[0].get_indexer(objarr)
else:
level = None
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,17 @@ def test_loc_multiindex(self):
xp = mi_int.ix[4]
assert_frame_equal(rs,xp)

# GH6788
# multi-index indexer is None (meaning take all)
attributes = ['Attribute' + str(i) for i in range(1)]
attribute_values = ['Value' + str(i) for i in range(5)]

index = MultiIndex.from_product([attributes,attribute_values])
df = 0.1 * np.random.randn(10, 1 * 5) + 0.5
df = DataFrame(df, columns=index)
result = df[attributes]
assert_frame_equal(result, df)

def test_series_getitem_multiindex(self):

# GH 6018
Expand Down