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 2 commits
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
19 changes: 19 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,25 @@ def test_from_dict_columns_parameter(self):
dict([("A", [1, 2]), ("B", [4, 5])]), columns=["one", "two"]
)

@pytest.mark.parametrize(
"data_dict",
[
[{("a",): 1}, {("a",): 2}],
[OrderedDict([(("a",), 1), (("b",), 2)])],
[{("a", "b"): 1}],
],
)
def test_constructor_from_dict_tuples(self, data_dict):
# GH 16769
df = DataFrame.from_dict(data_dict)

result = df.columns
all_columns = [key for sub_dict in data_dict for key in sub_dict.keys()]
Copy link
Member

Choose a reason for hiding this comment

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

You can just parametrize the expected column values alongside the data 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.

got you - done

columns = list(OrderedDict.fromkeys(all_columns))
expected = Index(columns, 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