Skip to content

Commit 8d92f8a

Browse files
author
Nico Cernek
committed
add test for left merge
1 parent 45640f2 commit 8d92f8a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/tests/reshape/merge/test_merge.py

+26
Original file line numberDiff line numberDiff line change
@@ -2108,3 +2108,29 @@ def test_right_merge_preserves_row_order():
21082108
result = pop.merge(ppl, on=("name", "country"), how="right")
21092109

21102110
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

Comments
 (0)