From d70e5b281a0e579d7872613e73288b0671fbc13a Mon Sep 17 00:00:00 2001 From: phofl Date: Tue, 22 Sep 2020 22:03:42 +0200 Subject: [PATCH 1/3] Add test for 20816 --- pandas/tests/reshape/test_concat.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py index 7d6611722d8b5..6d156e7753944 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -2927,3 +2927,20 @@ def test_concat_preserves_extension_int64_dtype(): result = pd.concat([df_a, df_b], ignore_index=True) expected = pd.DataFrame({"a": [-1, None], "b": [None, 1]}, dtype="Int64") tm.assert_frame_equal(result, expected) + + +@pytest.mark.parametrize( + ("keys", "integrity"), + [ + (["red"] * 3, False), + (["red", "blue", "red"], False), + (["red", "blue", "red"], True), + ], +) +def test_concat_repeated_keys(keys, integrity): + # GH: 20816 + series_list = [pd.Series({"a": 1}), pd.Series({"b": 2}), pd.Series({"c": 3})] + result = pd.concat(series_list, keys=keys, verify_integrity=integrity) + tuples = [(first, second) for first, second in zip(keys, ["a", "b", "c"])] + expected = pd.Series([1, 2, 3], index=pd.MultiIndex.from_tuples(tuples)) + tm.assert_series_equal(result, expected) From d5cab807b7695f6962c579cc5e20d29f99c5e1fb Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 28 Oct 2020 19:14:03 +0100 Subject: [PATCH 2/3] Modify test --- pandas/tests/reshape/test_concat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py index 6d156e7753944..cbc6d28e878e8 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -2932,6 +2932,7 @@ def test_concat_preserves_extension_int64_dtype(): @pytest.mark.parametrize( ("keys", "integrity"), [ + (["red"] * 3, True), (["red"] * 3, False), (["red", "blue", "red"], False), (["red", "blue", "red"], True), @@ -2941,6 +2942,6 @@ def test_concat_repeated_keys(keys, integrity): # GH: 20816 series_list = [pd.Series({"a": 1}), pd.Series({"b": 2}), pd.Series({"c": 3})] result = pd.concat(series_list, keys=keys, verify_integrity=integrity) - tuples = [(first, second) for first, second in zip(keys, ["a", "b", "c"])] + tuples = list(zip(keys, ["a", "b", "c"])) expected = pd.Series([1, 2, 3], index=pd.MultiIndex.from_tuples(tuples)) tm.assert_series_equal(result, expected) From 7c2e4f9edd42c5522f5471460b6d38f72061f513 Mon Sep 17 00:00:00 2001 From: phofl Date: Wed, 28 Oct 2020 19:17:54 +0100 Subject: [PATCH 3/3] Move test --- pandas/tests/reshape/concat/test_concat.py | 18 ++++++++++++++++++ pandas/tests/reshape/test_concat.py | 0 2 files changed, 18 insertions(+) delete mode 100644 pandas/tests/reshape/test_concat.py diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index 90172abefb8c4..4a1ea74da1ac2 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -556,3 +556,21 @@ def test_concat_preserves_extension_int64_dtype(): result = pd.concat([df_a, df_b], ignore_index=True) expected = DataFrame({"a": [-1, None], "b": [None, 1]}, dtype="Int64") tm.assert_frame_equal(result, expected) + + +@pytest.mark.parametrize( + ("keys", "integrity"), + [ + (["red"] * 3, True), + (["red"] * 3, False), + (["red", "blue", "red"], False), + (["red", "blue", "red"], True), + ], +) +def test_concat_repeated_keys(keys, integrity): + # GH: 20816 + series_list = [Series({"a": 1}), Series({"b": 2}), Series({"c": 3})] + result = concat(series_list, keys=keys, verify_integrity=integrity) + tuples = list(zip(keys, ["a", "b", "c"])) + expected = Series([1, 2, 3], index=MultiIndex.from_tuples(tuples)) + tm.assert_series_equal(result, expected) diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py deleted file mode 100644 index e69de29bb2d1d..0000000000000