Skip to content

Commit

Permalink
TST: add test for nested OrderedDict in constructor (#50060)
Browse files Browse the repository at this point in the history
* add test for nested OrderedDict to make sure sort is maintained

* docs: add gh reference
  • Loading branch information
codamuse authored Dec 6, 2022
1 parent 1b23a7d commit 2d185e1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,16 @@ def test_constructor_list_of_dicts(self):
expected = DataFrame(index=[0])
tm.assert_frame_equal(result, expected)

def test_constructor_ordered_dict_nested_preserve_order(self):
# see gh-18166
nested1 = OrderedDict([("b", 1), ("a", 2)])
nested2 = OrderedDict([("b", 2), ("a", 5)])
data = OrderedDict([("col2", nested1), ("col1", nested2)])
result = DataFrame(data)
data = {"col2": [1, 2], "col1": [2, 5]}
expected = DataFrame(data=data, index=["b", "a"])
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("dict_type", [dict, OrderedDict])
def test_constructor_ordered_dict_preserve_order(self, dict_type):
# see gh-13304
Expand Down

0 comments on commit 2d185e1

Please sign in to comment.