@@ -2082,3 +2082,29 @@ def test_merge_equal_cat_dtypes2():
2082
2082
2083
2083
# Categorical is unordered, so don't check ordering.
2084
2084
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