@@ -25,3 +25,47 @@ def test_memtable_join(con):
2525 left = result .sort_values ("x" ).reset_index (drop = True )
2626 right = expected .sort_values ("x" ).reset_index (drop = True )
2727 tm .assert_frame_equal (left , right )
28+
29+
30+ def test_memtable_join_left (con ):
31+ t1 = ibis .memtable ({"x" : [1 , 2 , 3 ], "y" : [4 , 5 , 6 ], "z" : ["a" , "b" , "c" ]})
32+ t2 = ibis .memtable ({"x" : [3 , 2 , 1 ], "y" : [7 , 8 , 9 ], "z" : ["d" , "e" , "f" ]})
33+ expr = t1 .join (t2 , "x" , how = "left" )
34+
35+ result = con .execute (expr )
36+ expected = pd .DataFrame (
37+ {
38+ "x" : [1 , 2 , 3 ],
39+ "y" : [4 , 5 , 6 ],
40+ "z" : ["a" , "b" , "c" ],
41+ "x_right" : [1 , 2 , 3 ],
42+ "y_right" : [9 , 8 , 7 ],
43+ "z_right" : ["f" , "e" , "d" ],
44+ }
45+ )
46+
47+ left = result .sort_values ("x" ).reset_index (drop = True )
48+ right = expected .sort_values ("x" ).reset_index (drop = True )
49+ tm .assert_frame_equal (left , right )
50+
51+
52+ def test_memtable_join_cross (con ):
53+ t1 = ibis .memtable ({"x" : [1 , 2 , 3 ], "y" : [4 , 5 , 6 ], "z" : ["a" , "b" , "c" ]})
54+ t2 = ibis .memtable ({"x" : [3 , 2 , 1 ], "y" : [7 , 8 , 9 ], "z" : ["d" , "e" , "f" ]})
55+ expr = t1 .join (t2 , how = "cross" )
56+
57+ result = con .execute (expr )
58+ expected = pd .DataFrame (
59+ {
60+ "x" : [1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 ],
61+ "y" : [4 , 4 , 4 , 5 , 5 , 5 , 6 , 6 , 6 ],
62+ "z" : ["a" , "a" , "a" , "b" , "b" , "b" , "c" , "c" , "c" ],
63+ "x_right" : [1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 ],
64+ "y_right" : [9 , 8 , 7 , 9 , 8 , 7 , 9 , 8 , 7 ],
65+ "z_right" : ["f" , "e" , "d" , "f" , "e" , "d" , "f" , "e" , "d" ],
66+ }
67+ )
68+
69+ left = result .sort_values (["x" , "x_right" ]).reset_index (drop = True )
70+ right = expected .sort_values (["x" , "x_right" ]).reset_index (drop = True )
71+ tm .assert_frame_equal (left , right )
0 commit comments