Skip to content

Commit 8f4b86d

Browse files
committed
BUG: accept empty list to DataFrame constructor, regression from 0.6.0, GH #491
1 parent 11d08f7 commit 8f4b86d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
207207
mgr = self._init_ndarray(data, index, columns, dtype=dtype,
208208
copy=copy)
209209
elif isinstance(data, list):
210-
if isinstance(data[0], (list, tuple)):
210+
if len(data) > 0 and isinstance(data[0], (list, tuple)):
211211
data, columns = _list_to_sdict(data, columns)
212212
mgr = self._init_dict(data, index, columns, dtype=dtype)
213213
else:

pandas/tests/test_frame.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,11 @@ def test_constructor_more(self):
12221222
self.assertEqual(len(dm.columns), 2)
12231223
self.assert_(dm.values.dtype == np.float64)
12241224

1225+
def test_constructor_empty_list(self):
1226+
df = DataFrame([], index=[])
1227+
expected = DataFrame(index=[])
1228+
assert_frame_equal(df, expected)
1229+
12251230
def test_constructor_list_of_lists(self):
12261231
# GH #484
12271232
l = [[1, 'a'], [2, 'b']]

0 commit comments

Comments
 (0)