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 df construction from dict with tuples #29497

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,20 @@ def test_from_dict_columns_parameter(self):
dict([("A", [1, 2]), ("B", [4, 5])]), columns=["one", "two"]
)

@pytest.mark.parametrize(
"keys, values",
[([("a",), ("a",)], [1, 2]), ([("a",), ("b",)], [1, 2]), ([("a", "b")], [1])],
)
def test_constructor_from_dict_tuples(self, keys, values):
data_dict = {key: value for key, value in zip(keys, values)}
Copy link
Member

Choose a reason for hiding this comment

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

Can you just parametrize dictionaries directly instead of doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @WillAyd - incorporated the change.

df = DataFrame.from_dict([data_dict])

result = df.columns
keys = list(OrderedDict.fromkeys(keys))
expected = Index(keys, dtype="object", tupleize_cols=False)

tm.assert_index_equal(result, expected)

def test_constructor_Series_named(self):
a = Series([1, 2, 3], index=["a", "b", "c"], name="x")
df = DataFrame(a)
Expand Down