@@ -69,11 +69,6 @@ def on_cols_multi():
6969 return ["Origin" , "Destination" , "Period" ]
7070
7171
72- @pytest .fixture
73- def idx_cols_multi ():
74- return ["Origin" , "Destination" , "Period" , "TripPurp" , "LinkType" ]
75-
76-
7772class TestMergeMulti :
7873 def test_merge_on_multikey (self , left , right , join_type ):
7974 on_cols = ["key1" , "key2" ]
@@ -815,9 +810,13 @@ def test_join_multi_levels2(self):
815810
816811
817812class TestJoinMultiMulti :
818- def test_join_multi_multi (
819- self , left_multi , right_multi , join_type , on_cols_multi , idx_cols_multi
820- ):
813+ def test_join_multi_multi (self , left_multi , right_multi , join_type , on_cols_multi ):
814+ left_names = left_multi .index .names
815+ right_names = right_multi .index .names
816+ if join_type == "right" :
817+ level_order = right_names + left_names .difference (right_names )
818+ else :
819+ level_order = left_names + right_names .difference (left_names )
821820 # Multi-index join tests
822821 expected = (
823822 merge (
@@ -826,27 +825,34 @@ def test_join_multi_multi(
826825 how = join_type ,
827826 on = on_cols_multi ,
828827 )
829- .set_index (idx_cols_multi )
828+ .set_index (level_order )
830829 .sort_index ()
831830 )
832831
833832 result = left_multi .join (right_multi , how = join_type ).sort_index ()
834833 tm .assert_frame_equal (result , expected )
835834
836835 def test_join_multi_empty_frames (
837- self , left_multi , right_multi , join_type , on_cols_multi , idx_cols_multi
836+ self , left_multi , right_multi , join_type , on_cols_multi
838837 ):
839838 left_multi = left_multi .drop (columns = left_multi .columns )
840839 right_multi = right_multi .drop (columns = right_multi .columns )
841840
841+ left_names = left_multi .index .names
842+ right_names = right_multi .index .names
843+ if join_type == "right" :
844+ level_order = right_names + left_names .difference (right_names )
845+ else :
846+ level_order = left_names + right_names .difference (left_names )
847+
842848 expected = (
843849 merge (
844850 left_multi .reset_index (),
845851 right_multi .reset_index (),
846852 how = join_type ,
847853 on = on_cols_multi ,
848854 )
849- .set_index (idx_cols_multi )
855+ .set_index (level_order )
850856 .sort_index ()
851857 )
852858
0 commit comments