Skip to content

Commit

Permalink
BUG: accept empty list to DataFrame constructor, regression from 0.6.…
Browse files Browse the repository at this point in the history
…0, GH #491
  • Loading branch information
wesm committed Dec 15, 2011
1 parent 11d08f7 commit 8f4b86d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
mgr = self._init_ndarray(data, index, columns, dtype=dtype,
copy=copy)
elif isinstance(data, list):
if isinstance(data[0], (list, tuple)):
if len(data) > 0 and isinstance(data[0], (list, tuple)):
data, columns = _list_to_sdict(data, columns)
mgr = self._init_dict(data, index, columns, dtype=dtype)
else:
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,11 @@ def test_constructor_more(self):
self.assertEqual(len(dm.columns), 2)
self.assert_(dm.values.dtype == np.float64)

def test_constructor_empty_list(self):
df = DataFrame([], index=[])
expected = DataFrame(index=[])
assert_frame_equal(df, expected)

def test_constructor_list_of_lists(self):
# GH #484
l = [[1, 'a'], [2, 'b']]
Expand Down

0 comments on commit 8f4b86d

Please sign in to comment.