Skip to content

Commit 30d8d6a

Browse files
committed
BUG: closes #719, sortedness check in to_panel, fixed
1 parent 263b15c commit 30d8d6a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pandas/core/frame.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,8 @@ def to_panel(self):
815815

816816
self._consolidate_inplace()
817817

818-
# outermost level of labels must be sorted
819-
if self.index.lexsort_depth < 1:
818+
# minor axis must be sorted
819+
if self.index.lexsort_depth < 2:
820820
selfsorted = self.sortlevel(0)
821821
else:
822822
selfsorted = self

pandas/tests/test_panel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -965,13 +965,13 @@ def test_group_agg(self):
965965
f2 = lambda x: np.zeros((2,2))
966966
self.assertRaises(Exception, group_agg, values, bounds, f2)
967967

968-
def test_from_frame_unsorted(self):
969-
tuples = [('MSFT', 3), ('AAPL', 3), ('MSFT', 1),
970-
('AAPL', 1), ('MSFT', 2)]
968+
def test_from_frame_level1_unsorted(self):
969+
tuples = [('MSFT', 3), ('MSFT', 2), ('AAPL', 2),
970+
('AAPL', 1), ('MSFT', 1)]
971971
midx = MultiIndex.from_tuples(tuples)
972972
df = DataFrame(np.random.rand(5,4), index=midx)
973973
p = df.to_panel()
974-
assert_frame_equal(p.major_xs('MSFT'), df.sort().ix['MSFT',:])
974+
assert_frame_equal(p.minor_xs(2), df.ix[:,2].sort_index())
975975

976976
class TestLongPanel(unittest.TestCase):
977977
"""

0 commit comments

Comments
 (0)