Skip to content

Commit 43df881

Browse files
committed
TST: Move test to test_multilevel.py
1 parent 0c9c37a commit 43df881

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

pandas/tests/indexes/multi/test_indexing.py

-30
Original file line numberDiff line numberDiff line change
@@ -525,33 +525,3 @@ def test_slice_locs_with_missing_value(index_arr, expected, start_idx, end_idx):
525525
idx = MultiIndex.from_arrays(index_arr)
526526
result = idx.slice_locs(start=start_idx, end=end_idx)
527527
assert result == expected
528-
529-
530-
def test_multiindex_loc_order():
531-
# GH 22797
532-
# Try to respect order of keys given for MultiIndex.loc
533-
df = pd.DataFrame(
534-
np.arange(12).reshape((4, 3)),
535-
index=[["a", "a", "b", "b"], [1, 2, 1, 2]],
536-
columns=[["Ohio", "Ohio", "Colorado"], ["Green", "Red", "Green"]],
537-
)
538-
539-
res = df.loc[["b", "a"], :]
540-
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
541-
tm.assert_index_equal(res.index, exp_index)
542-
543-
res = df.loc[(["b", "a"], [2, 1]), :]
544-
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [2, 1, 2, 1]])
545-
tm.assert_index_equal(res.index, exp_index)
546-
547-
res = df.loc[:, ["Colorado", "Ohio"]]
548-
exp_columns = pd.MultiIndex.from_arrays(
549-
[["Colorado", "Ohio", "Ohio"], ["Green", "Green", "Red"]]
550-
)
551-
tm.assert_index_equal(res.columns, exp_columns)
552-
553-
res = df.loc[:, (["Colorado", "Ohio"], ["Red", "Green"])]
554-
exp_columns = pd.MultiIndex.from_arrays(
555-
[["Colorado", "Ohio", "Ohio"], ["Green", "Red", "Green"]]
556-
)
557-
tm.assert_index_equal(res.columns, exp_columns)

pandas/tests/test_multilevel.py

+45
Original file line numberDiff line numberDiff line change
@@ -2471,3 +2471,48 @@ def test_sort_ascending_list(self):
24712471
result = s.sort_index(level=["third", "first"], ascending=[False, True])
24722472
expected = s.iloc[[0, 4, 1, 5, 2, 6, 3, 7]]
24732473
tm.assert_series_equal(result, expected)
2474+
2475+
def test_multiindex_loc_order(self):
2476+
# GH 22797
2477+
# Try to respect order of keys given for MultiIndex.loc
2478+
df = pd.DataFrame(
2479+
np.arange(12).reshape((4, 3)),
2480+
index=[["a", "a", "b", "b"], [1, 2, 1, 2]],
2481+
columns=[["Ohio", "Ohio", "Colorado"], ["Green", "Red", "Green"]],
2482+
)
2483+
2484+
res = df.loc[["b", "a"], :]
2485+
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
2486+
tm.assert_index_equal(res.index, exp_index)
2487+
2488+
res = df.loc[["a", "b"], :]
2489+
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [1, 2, 1, 2]])
2490+
tm.assert_index_equal(res.index, exp_index)
2491+
2492+
res = df.loc[(["a", "b"], [1, 2]), :]
2493+
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [1, 2, 1, 2]])
2494+
tm.assert_index_equal(res.index, exp_index)
2495+
2496+
res = df.loc[(["a", "b"], [2, 1]), :]
2497+
exp_index = pd.MultiIndex.from_arrays([["a", "a", "b", "b"], [2, 1, 2, 1]])
2498+
tm.assert_index_equal(res.index, exp_index)
2499+
2500+
res = df.loc[(["b", "a"], [2, 1]), :]
2501+
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [2, 1, 2, 1]])
2502+
tm.assert_index_equal(res.index, exp_index)
2503+
2504+
res = df.loc[(["b", "a"], [1, 2]), :]
2505+
exp_index = pd.MultiIndex.from_arrays([["b", "b", "a", "a"], [1, 2, 1, 2]])
2506+
tm.assert_index_equal(res.index, exp_index)
2507+
2508+
res = df.loc[:, ["Colorado", "Ohio"]]
2509+
exp_columns = pd.MultiIndex.from_arrays(
2510+
[["Colorado", "Ohio", "Ohio"], ["Green", "Green", "Red"]]
2511+
)
2512+
tm.assert_index_equal(res.columns, exp_columns)
2513+
2514+
res = df.loc[:, (["Colorado", "Ohio"], ["Red", "Green"])]
2515+
exp_columns = pd.MultiIndex.from_arrays(
2516+
[["Colorado", "Ohio", "Ohio"], ["Green", "Red", "Green"]]
2517+
)
2518+
tm.assert_index_equal(res.columns, exp_columns)

0 commit comments

Comments
 (0)