From 8f4b86dea774043cbeee3b3f6d5f79c2e32ec4f8 Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Wed, 14 Dec 2011 23:02:13 -0500 Subject: [PATCH] BUG: accept empty list to DataFrame constructor, regression from 0.6.0, GH #491 --- pandas/core/frame.py | 2 +- pandas/tests/test_frame.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index cecd65bb4aba3..3a3ffddd9789f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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: diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 529c91114919a..962878c777674 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -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']]