Skip to content

Commit ea513d5

Browse files
author
y-p
committed
TST: Panel ctor and from_dict should respect ordering when given OrderedDict GH3303
1 parent 26ca139 commit ea513d5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pandas/core/panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pandas.core.index import (Index, MultiIndex, _ensure_index,
1414
_get_combined_index)
1515
from pandas.core.indexing import _maybe_droplevels, _is_list_like
16-
from pandas.core.internals import (BlockManager,
16+
from pandas.core.internals import (BlockManager,
1717
create_block_manager_from_arrays,
1818
create_block_manager_from_blocks)
1919
from pandas.core.series import Series

pandas/tests/test_panel.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
assert_frame_equal,
2020
assert_series_equal,
2121
assert_almost_equal,
22-
ensure_clean)
22+
ensure_clean,
23+
makeCustomDataframe as mkdf
24+
)
2325
import pandas.core.panel as panelm
2426
import pandas.util.testing as tm
2527

@@ -904,6 +906,16 @@ def test_constructor_dict_mixed(self):
904906
data['ItemB'] = self.panel['ItemB'].values[:, :-1]
905907
self.assertRaises(Exception, Panel, data)
906908

909+
def test_ctor_orderedDict(self):
910+
from pandas.util.compat import OrderedDict
911+
keys = list(set(np.random.randint(0,5000,100)))[:50] # unique random int keys
912+
d = OrderedDict([(k,mkdf(10,5)) for k in keys])
913+
p = Panel(d)
914+
self.assertTrue(list(p.items) == keys)
915+
916+
p = Panel.from_dict(d)
917+
self.assertTrue(list(p.items) == keys)
918+
907919
def test_constructor_resize(self):
908920
data = self.panel._data
909921
items = self.panel.items[:-1]

0 commit comments

Comments
 (0)