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
20 changes: 14 additions & 6 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,13 @@ def test_constructor_list_of_odicts(self):
expected = DataFrame(index=[0])
tm.assert_frame_equal(result, expected)

def test_constructor_single_row(self):
data = [OrderedDict([["a", 1.5], ["b", 3], ["c", 4], ["d", 6]])]

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

def test_constructor_ordered_dict_preserve_order(self):
# see gh-13304
expected = DataFrame([[2, 1]], columns=["b", "a"])
Expand Down Expand Up @@ -1493,16 +1500,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