Skip to content

Commit 307ff39

Browse files
author
Nico Cernek
committed
add failing test to check row order preservation
1 parent 35821a5 commit 307ff39

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/tests/reshape/merge/test_merge.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,3 +2082,29 @@ def test_merge_equal_cat_dtypes2():
20822082

20832083
# Categorical is unordered, so don't check ordering.
20842084
tm.assert_frame_equal(result, expected, check_categorical=False)
2085+
2086+
2087+
def test_right_merge_preserves_row_order():
2088+
population = [
2089+
("Jenn", "Jamaica", 3),
2090+
("Beth", "Bulgaria", 7),
2091+
("Carl", "Canada", 30),
2092+
]
2093+
columns = ["name", "country", "population"]
2094+
pop = pd.DataFrame.from_records(population, columns=columns)
2095+
2096+
people = [("Abe", "America"), ("Beth", "Bulgaria"), ("Carl", "Canada")]
2097+
columns = ["name", "country"]
2098+
ppl = pd.DataFrame.from_records(people, columns=columns)
2099+
2100+
expected_data = [
2101+
("Abe", "America", np.nan),
2102+
("Beth", "Bulgaria", 7),
2103+
("Carl", "Canada", 30),
2104+
]
2105+
expected_cols = ["name", "country", "population"]
2106+
expected = DataFrame.from_records(expected_data, columns=expected_cols)
2107+
2108+
result = pop.merge(ppl, on=("name", "country"), how="right")
2109+
2110+
assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)