Skip to content

Commit f692c4d

Browse files
committed
TST: move test_multiindex_loc_order to tests/test_multilevel.py
1 parent 650d41c commit f692c4d

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

pandas/tests/indexes/multi/test_indexing.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ def test_timestamp_multiindex_indexer():
438438
)
439439
should_be = pd.Series(data=np.arange(24, len(qidx) + 24), index=qidx, name="foo")
440440
tm.assert_series_equal(result, should_be)
441-
<<<<<<< HEAD
442441

443442

444443
def test_get_loc_with_values_including_missing_values():
@@ -527,37 +526,3 @@ def test_slice_locs_with_missing_value(index_arr, expected, start_idx, end_idx):
527526
idx = MultiIndex.from_arrays(index_arr)
528527
result = idx.slice_locs(start=start_idx, end=end_idx)
529528
assert result == expected
530-
531-
532-
def test_multiindex_loc_order():
533-
# GH 22797
534-
# Try to respect order of keys given for MultiIndex.loc
535-
df = pd.DataFrame(
536-
np.arange(12).reshape((4, 3)),
537-
index=[["a", "a", "b", "b"], [1, 2, 1, 2]],
538-
columns=[["Ohio", "Ohio", "Colorado"], ["Green", "Red", "Green"]],
539-
)
540-
541-
res = df.loc[["b", "a"], :]
542-
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
543-
tm.assert_index_equal(res.index, exp_index)
544-
545-
res = df.loc[["a", "b"], :]
546-
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [1, 2, 1, 2]])
547-
tm.assert_index_equal(res.index, exp_index)
548-
549-
res = df.loc[(["a", "b"], [1, 2]), :]
550-
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [1, 2, 1, 2]])
551-
tm.assert_index_equal(res.index, exp_index)
552-
553-
res = df.loc[(["a", "b"], [2, 1]), :]
554-
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [2, 1, 2, 1]])
555-
tm.assert_index_equal(res.index, exp_index)
556-
557-
res = df.loc[(["b", "a"], [2, 1]), :]
558-
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [2, 1, 2, 1]])
559-
tm.assert_index_equal(res.index, exp_index)
560-
561-
res = df.loc[(["b", "a"], [1, 2]), :]
562-
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
563-
tm.assert_index_equal(res.index, exp_index)

pandas/tests/test_multilevel.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,3 +2534,37 @@ def test_sort_ascending_list(self):
25342534
result = s.sort_index(level=["third", "first"], ascending=[False, True])
25352535
expected = s.iloc[[0, 4, 1, 5, 2, 6, 3, 7]]
25362536
tm.assert_series_equal(result, expected)
2537+
2538+
2539+
def test_multiindex_loc_order():
2540+
# GH 22797
2541+
# Try to respect order of keys given for MultiIndex.loc
2542+
df = pd.DataFrame(
2543+
np.arange(12).reshape((4, 3)),
2544+
index=[["a", "a", "b", "b"], [1, 2, 1, 2]],
2545+
columns=[["Ohio", "Ohio", "Colorado"], ["Green", "Red", "Green"]],
2546+
)
2547+
2548+
res = df.loc[["b", "a"], :]
2549+
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
2550+
tm.assert_index_equal(res.index, exp_index)
2551+
2552+
res = df.loc[["a", "b"], :]
2553+
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [1, 2, 1, 2]])
2554+
tm.assert_index_equal(res.index, exp_index)
2555+
2556+
res = df.loc[(["a", "b"], [1, 2]), :]
2557+
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [1, 2, 1, 2]])
2558+
tm.assert_index_equal(res.index, exp_index)
2559+
2560+
res = df.loc[(["a", "b"], [2, 1]), :]
2561+
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [2, 1, 2, 1]])
2562+
tm.assert_index_equal(res.index, exp_index)
2563+
2564+
res = df.loc[(["b", "a"], [2, 1]), :]
2565+
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [2, 1, 2, 1]])
2566+
tm.assert_index_equal(res.index, exp_index)
2567+
2568+
res = df.loc[(["b", "a"], [1, 2]), :]
2569+
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
2570+
tm.assert_index_equal(res.index, exp_index)

0 commit comments

Comments
 (0)