Skip to content

BUG: Preserve key order when using loc on MultiIndex DataFrame #28933

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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
TST: Add more test cases to test_multiindex_loc_order
  • Loading branch information
nrebena committed Feb 2, 2020
commit 81edea5705fad93f8f6339f1cc642c44d75de92b
16 changes: 16 additions & 0 deletions pandas/tests/indexes/multi/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,22 @@ def test_multiindex_loc_order():
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
tm.assert_index_equal(res.index, exp_index)

res = df.loc[["a", "b"], :]
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [1, 2, 1, 2]])
tm.assert_index_equal(res.index, exp_index)

res = df.loc[(["a", "b"], [1, 2]), :]
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [1, 2, 1, 2]])
tm.assert_index_equal(res.index, exp_index)

res = df.loc[(["a", "b"], [2, 1]), :]
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [2, 1, 2, 1]])
tm.assert_index_equal(res.index, exp_index)

res = df.loc[(["b", "a"], [2, 1]), :]
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [2, 1, 2, 1]])
tm.assert_index_equal(res.index, exp_index)

res = df.loc[(["b", "a"], [1, 2]), :]
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
tm.assert_index_equal(res.index, exp_index)