Skip to content

Commit

Permalink
BUG: raise more helpful exception when passing empty list to MultiInd…
Browse files Browse the repository at this point in the history
…ex.from_tuples
  • Loading branch information
wesm committed Oct 21, 2011
1 parent 20ae0ed commit b82a93f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,8 @@ def from_tuples(cls, tuples, sortorder=None, names=None):
-------
index : MultiIndex
"""
if len(tuples) == 0:
raise Exception('Cannot infer number of levels from empty list')
arrays = zip(*tuples)
return MultiIndex.from_arrays(arrays, sortorder=sortorder,
names=names)
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@ def test_diff(self):
result = self.index - self.index.sortlevel(1)[0]
self.assert_(len(result) == 0)

def test_from_tuples(self):
self.assertRaises(Exception, MultiIndex.from_tuples, [])

def test_argsort(self):
result = self.index.argsort()
expected = self.index.get_tuple_index().argsort()
Expand Down

0 comments on commit b82a93f

Please sign in to comment.