From 23e48c232fa3c7ae893acc300280a0a7be33888d Mon Sep 17 00:00:00 2001 From: Ryan Nazareth Date: Sat, 16 Nov 2019 22:04:44 +0000 Subject: [PATCH] TST: Merge multiple cols with mixed columns/index (#29522) --- pandas/tests/reshape/merge/test_multi.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pandas/tests/reshape/merge/test_multi.py b/pandas/tests/reshape/merge/test_multi.py index 1d8d2add3840c1..bce62571d55ec7 100644 --- a/pandas/tests/reshape/merge/test_multi.py +++ b/pandas/tests/reshape/merge/test_multi.py @@ -195,6 +195,27 @@ def test_merge_right_vs_left(self, left, right, sort): tm.assert_frame_equal(merged_left_right, merge_right_left) + def test_merge_multiple_cols_with_mixed_cols_index(self): + # GH29522 + s = pd.Series( + range(6), + pd.MultiIndex.from_product([["A", "B"], [1, 2, 3]], names=["lev1", "lev2"]), + name="Amount", + ) + df = pd.DataFrame( + {"lev1": list("AAABBB"), "lev2": [1, 2, 3, 1, 2, 3], "col": 0} + ) + result = pd.merge(df, s.reset_index(), on=["lev1", "lev2"]) + expected = pd.DataFrame( + { + "lev1": list("AAABBB"), + "lev2": [1, 2, 3, 1, 2, 3], + "col": [0] * 6, + "Amount": range(6), + } + ) + tm.assert_frame_equal(result, expected) + def test_compress_group_combinations(self): # ~ 40000000 possible unique groups