1616import collections
1717import itertools
1818import sys
19- import types
2019import warnings
2120from textwrap import dedent
2221
7574from pandas .core .arrays import Categorical , ExtensionArray
7675import pandas .core .algorithms as algorithms
7776from pandas .compat import (range , map , zip , lrange , lmap , lzip , StringIO , u ,
78- OrderedDict , raise_with_traceback )
77+ OrderedDict , raise_with_traceback ,
78+ string_and_binary_types )
7979from pandas import compat
8080from pandas .compat import PY36
8181from pandas .compat .numpy import function as nv
@@ -267,7 +267,7 @@ class DataFrame(NDFrame):
267267
268268 Parameters
269269 ----------
270- data : numpy ndarray (structured or homogeneous), dict, or DataFrame
270+ data : ndarray (structured or homogeneous), Iterable , dict, or DataFrame
271271 Dict can contain Series, arrays, constants, or list-like objects
272272
273273 .. versionchanged :: 0.23.0
@@ -391,8 +391,11 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
391391 else :
392392 mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
393393 copy = copy )
394- elif isinstance (data , (list , types .GeneratorType )):
395- if isinstance (data , types .GeneratorType ):
394+
395+ # For data is list-like, or Iterable (will consume into list)
396+ elif (isinstance (data , collections .Iterable )
397+ and not isinstance (data , string_and_binary_types )):
398+ if not isinstance (data , collections .Sequence ):
396399 data = list (data )
397400 if len (data ) > 0 :
398401 if is_list_like (data [0 ]) and getattr (data [0 ], 'ndim' , 1 ) == 1 :
@@ -417,8 +420,6 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
417420 copy = copy )
418421 else :
419422 mgr = self ._init_dict ({}, index , columns , dtype = dtype )
420- elif isinstance (data , collections .Iterator ):
421- raise TypeError ("data argument can't be an iterator" )
422423 else :
423424 try :
424425 arr = np .array (data , dtype = dtype , copy = copy )
0 commit comments