@@ -2108,3 +2108,29 @@ def test_right_merge_preserves_row_order():
2108
2108
result = pop .merge (ppl , on = ("name" , "country" ), how = "right" )
2109
2109
2110
2110
assert_frame_equal (expected , result )
2111
+
2112
+
2113
+ def test_left_merge_preserves_row_order ():
2114
+ population = [
2115
+ ("Jenn" , "Jamaica" , 3 ),
2116
+ ("Beth" , "Bulgaria" , 7 ),
2117
+ ("Carl" , "Canada" , 30 ),
2118
+ ]
2119
+ columns = ["name" , "country" , "population" ]
2120
+ pop = DataFrame .from_records (population , columns = columns )
2121
+
2122
+ people = [("Abe" , "America" ), ("Beth" , "Bulgaria" ), ("Carl" , "Canada" )]
2123
+ columns = ["name" , "country" ]
2124
+ ppl = DataFrame .from_records (people , columns = columns )
2125
+
2126
+ expected_data = [
2127
+ ("Abe" , "America" , np .nan ),
2128
+ ("Beth" , "Bulgaria" , 7 ),
2129
+ ("Carl" , "Canada" , 30 ),
2130
+ ]
2131
+ expected_cols = ["name" , "country" , "population" ]
2132
+ expected = DataFrame .from_records (expected_data , columns = expected_cols )
2133
+
2134
+ result = ppl .merge (pop , on = ("name" , "country" ), how = "left" )
2135
+
2136
+ assert_frame_equal (expected , result )
0 commit comments