Skip to content

Commit 24133e8

Browse files
committed
BUG: don't allow to_panel to succeed if index is not unique. close #2441
1 parent 7859063 commit 24133e8

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

RELEASE.rst

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pandas 0.10.0
140140
- Fix GroupBy.apply issue when using BinGrouper to do ts binning (#2300)
141141
- Fix issues resulting from datetime.datetime columns being converted to
142142
datetime64 when calling DataFrame.apply. (#2374)
143+
- Raise exception when calling to_panel on non uniquely-indexed frame (#2441)
143144

144145

145146
pandas 0.9.1

pandas/core/frame.py

+4
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,10 @@ def to_panel(self):
12001200
len(self.index.levels) != 2):
12011201
raise AssertionError('Must have 2-level MultiIndex')
12021202

1203+
if not self.index.is_unique:
1204+
raise Exception("Can't convert non-uniquely indexed "
1205+
"DataFrame to Panel")
1206+
12031207
self._consolidate_inplace()
12041208

12051209
# minor axis must be sorted

pandas/tests/test_panel.py

+6
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,12 @@ def test_to_panel_na_handling(self):
11281128
panel = df.to_panel()
11291129
self.assert_(isnull(panel[0].ix[1, [0, 1]]).all())
11301130

1131+
def test_to_panel_duplicates(self):
1132+
# #2441
1133+
df = DataFrame({'a': [0, 0, 1], 'b': [1, 1, 1], 'c': [1, 2, 3]})
1134+
idf = df.set_index(['a', 'b'])
1135+
self.assertRaises(Exception, idf.to_panel)
1136+
11311137
def test_filter(self):
11321138
pass
11331139

0 commit comments

Comments
 (0)