Skip to content

Commit 404e6ba

Browse files
ganevgvmroeschke
authored andcommitted
TST: add test for df construction from dict with tuples (#29497)
* add test for frame construction from dict with tuples * parametrize full data_dict * refactor parametrize
1 parent 3150962 commit 404e6ba

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/frame/test_constructors.py

+17
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,23 @@ def test_from_dict_columns_parameter(self):
14241424
dict([("A", [1, 2]), ("B", [4, 5])]), columns=["one", "two"]
14251425
)
14261426

1427+
@pytest.mark.parametrize(
1428+
"data_dict, keys",
1429+
[
1430+
([{("a",): 1}, {("a",): 2}], [("a",)]),
1431+
([OrderedDict([(("a",), 1), (("b",), 2)])], [("a",), ("b",)]),
1432+
([{("a", "b"): 1}], [("a", "b")]),
1433+
],
1434+
)
1435+
def test_constructor_from_dict_tuples(self, data_dict, keys):
1436+
# GH 16769
1437+
df = DataFrame.from_dict(data_dict)
1438+
1439+
result = df.columns
1440+
expected = Index(keys, dtype="object", tupleize_cols=False)
1441+
1442+
tm.assert_index_equal(result, expected)
1443+
14271444
def test_constructor_Series_named(self):
14281445
a = Series([1, 2, 3], index=["a", "b", "c"], name="x")
14291446
df = DataFrame(a)

0 commit comments

Comments
 (0)