Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TST]: Add test for duplicate keys in concat #36556

Merged
merged 5 commits into from Nov 26, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions pandas/tests/reshape/test_concat.py
Expand Up @@ -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),
],
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a plan to follow the same exact parametrization as in the referenced github issue?
I would suggest to have these tests with verify_integrity=True/False for all keys.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not mentioned as a problem, so I think that was the reason I did not add it. But was more than 4 weeks ago, so I am not quite sure. Added it now.

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"])]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could be simplified.

tuples = list(zip(keys, ["a", "b", "c"]))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thank you very much

expected = pd.Series([1, 2, 3], index=pd.MultiIndex.from_tuples(tuples))
tm.assert_series_equal(result, expected)