Skip to content

Commit 1b4899d

Browse files
author
Nico Cernek
committed
combine tests into one
1 parent fbeb206 commit 1b4899d

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

pandas/tests/reshape/merge/test_merge.py

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,19 +2096,20 @@ def test_merge_equal_cat_dtypes2():
20962096
tm.assert_frame_equal(result, expected, check_categorical=False)
20972097

20982098

2099-
def test_right_merge_preserves_row_order():
2099+
@pytest.mark.parametrize("how", ["left", "right"])
2100+
def test_merge_preserves_row_order(how):
21002101
# GH 27453
21012102
population = [
21022103
("Jenn", "Jamaica", 3),
21032104
("Beth", "Bulgaria", 7),
21042105
("Carl", "Canada", 30),
21052106
]
21062107
columns = ["name", "country", "population"]
2107-
pop = DataFrame(population, columns=columns)
2108+
population_df = DataFrame(population, columns=columns)
21082109

21092110
people = [("Abe", "America"), ("Beth", "Bulgaria"), ("Carl", "Canada")]
21102111
columns = ["name", "country"]
2111-
ppl = DataFrame(people, columns=columns)
2112+
people_df = DataFrame(people, columns=columns)
21122113

21132114
expected_data = [
21142115
("Abe", "America", np.nan),
@@ -2118,33 +2119,10 @@ def test_right_merge_preserves_row_order():
21182119
expected_cols = ["name", "country", "population"]
21192120
expected = DataFrame(expected_data, columns=expected_cols)
21202121

2121-
result = pop.merge(ppl, on=("name", "country"), how="right")
2122-
2123-
assert_frame_equal(expected, result)
2124-
2125-
2126-
def test_left_merge_preserves_row_order():
2127-
# GH 27453
2128-
population = [
2129-
("Jenn", "Jamaica", 3),
2130-
("Beth", "Bulgaria", 7),
2131-
("Carl", "Canada", 30),
2132-
]
2133-
columns = ["name", "country", "population"]
2134-
pop = DataFrame(population, columns=columns)
2135-
2136-
people = [("Abe", "America"), ("Beth", "Bulgaria"), ("Carl", "Canada")]
2137-
columns = ["name", "country"]
2138-
ppl = DataFrame(people, columns=columns)
2139-
2140-
expected_data = [
2141-
("Abe", "America", np.nan),
2142-
("Beth", "Bulgaria", 7),
2143-
("Carl", "Canada", 30),
2144-
]
2145-
expected_cols = ["name", "country", "population"]
2146-
expected = DataFrame(expected_data, columns=expected_cols)
2147-
2148-
result = ppl.merge(pop, on=("name", "country"), how="left")
2122+
if how == "right":
2123+
left_df, right_df = population_df, people_df
2124+
elif how == "left":
2125+
left_df, right_df = people_df, population_df
21492126

2127+
result = left_df.merge(right_df, on=("name", "country"), how=how)
21502128
assert_frame_equal(expected, result)

0 commit comments

Comments
 (0)