@@ -44,7 +44,7 @@ def test_join_with_index(
4444 right_on = right_on ,
4545 left_index = left_index ,
4646 right_index = right_index ,
47- how = how
47+ how = how ,
4848 ).to_pandas ()
4949 pd_result = pd .merge (
5050 df1 ,
@@ -53,14 +53,42 @@ def test_join_with_index(
5353 right_on = right_on ,
5454 left_index = left_index ,
5555 right_index = right_index ,
56- how = how
56+ how = how ,
5757 )
5858
5959 pandas .testing .assert_frame_equal (
6060 bf_result , pd_result , check_dtype = False , check_index_type = False
6161 )
6262
6363
64+ @pytest .mark .parametrize (
65+ ("on" , "left_on" , "right_on" , "left_index" , "right_index" ),
66+ [
67+ (None , "col_a" , None , True , False ),
68+ (None , None , "col_c" , None , True ),
69+ ("col_a" , None , None , True , True ),
70+ ],
71+ )
72+ def test_join_with_index_invalid_index_arg_raise_error (
73+ session : session .Session , on , left_on , right_on , left_index , right_index
74+ ):
75+ df1 = pd .DataFrame ({"col_a" : [1 , 2 , 3 ], "col_b" : [2 , 3 , 4 ]}, index = [1 , 2 , 3 ])
76+ bf1 = session .read_pandas (df1 )
77+ df2 = pd .DataFrame ({"col_c" : [1 , 2 , 3 ], "col_d" : [2 , 3 , 4 ]}, index = [2 , 3 , 4 ])
78+ bf2 = session .read_pandas (df2 )
79+
80+ with pytest .raises (ValueError ):
81+ merge .merge (
82+ bf1 ,
83+ bf2 ,
84+ on = on ,
85+ left_on = left_on ,
86+ right_on = right_on ,
87+ left_index = left_index ,
88+ right_index = right_index ,
89+ ).to_pandas ()
90+
91+
6492@pytest .mark .parametrize (
6593 ("left_on" , "right_on" , "left_index" , "right_index" ),
6694 [
@@ -70,7 +98,7 @@ def test_join_with_index(
7098 ],
7199)
72100@pytest .mark .parametrize ("how" , ["inner" , "left" , "right" , "outer" ])
73- def test_join_with_multiindex (
101+ def test_join_with_multiindex_raises_error (
74102 session : session .Session , left_on , right_on , left_index , right_index , how
75103):
76104 multi_idx1 = pd .MultiIndex .from_tuples ([(1 , 2 ), (2 , 3 ), (3 , 5 )])
@@ -80,25 +108,13 @@ def test_join_with_multiindex(
80108 df2 = pd .DataFrame ({"col_c" : [1 , 2 , 3 ], "col_d" : [2 , 3 , 4 ]}, index = multi_idx2 )
81109 bf2 = session .read_pandas (df2 )
82110
83- bf_result = merge .merge (
84- bf1 ,
85- bf2 ,
86- left_on = left_on ,
87- right_on = right_on ,
88- left_index = left_index ,
89- right_index = right_index ,
90- how = how
91- ).to_pandas ()
92- pd_result = pd .merge (
93- df1 ,
94- df2 ,
95- left_on = left_on ,
96- right_on = right_on ,
97- left_index = left_index ,
98- right_index = right_index ,
99- how = how
100- )
101-
102- pandas .testing .assert_frame_equal (
103- bf_result .sort_index (), pd_result .sort_index (), check_dtype = False , check_index_type = False ,
104- )
111+ with pytest .raises (ValueError ):
112+ merge .merge (
113+ bf1 ,
114+ bf2 ,
115+ left_on = left_on ,
116+ right_on = right_on ,
117+ left_index = left_index ,
118+ right_index = right_index ,
119+ how = how ,
120+ )
0 commit comments