Skip to content

TST add corner cases in test_constructors #35216

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

Merged
merged 12 commits into from
Jul 11, 2020
19 changes: 13 additions & 6 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,12 @@ def test_constructor_list_of_odicts(self):
OrderedDict([["b", 3], ["c", 4], ["d", 6]]),
]

# single row dataframe
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 create this as a separate test?

result = DataFrame([data[0]])
expected = DataFrame.from_dict(
dict(zip([0], [data[0]])), orient="index")
tm.assert_frame_equal(result, expected.reindex(result.index))

result = DataFrame(data)
expected = DataFrame.from_dict(
dict(zip(range(len(data)), data)), orient="index"
Expand Down Expand Up @@ -1493,16 +1499,17 @@ def test_from_dict_columns_parameter(self):
)

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

result = df.columns
expected = Index(keys, dtype="object", tupleize_cols=False)
Expand Down