16
16
import collections
17
17
import itertools
18
18
import sys
19
- import types
20
19
import warnings
21
20
from textwrap import dedent
22
21
75
74
from pandas .core .arrays import Categorical , ExtensionArray
76
75
import pandas .core .algorithms as algorithms
77
76
from 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 )
79
79
from pandas import compat
80
80
from pandas .compat import PY36
81
81
from pandas .compat .numpy import function as nv
@@ -267,7 +267,7 @@ class DataFrame(NDFrame):
267
267
268
268
Parameters
269
269
----------
270
- data : numpy ndarray (structured or homogeneous), dict, or DataFrame
270
+ data : ndarray (structured or homogeneous), Iterable , dict, or DataFrame
271
271
Dict can contain Series, arrays, constants, or list-like objects
272
272
273
273
.. versionchanged :: 0.23.0
@@ -391,8 +391,11 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
391
391
else :
392
392
mgr = self ._init_ndarray (data , index , columns , dtype = dtype ,
393
393
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 ):
396
399
data = list (data )
397
400
if len (data ) > 0 :
398
401
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,
417
420
copy = copy )
418
421
else :
419
422
mgr = self ._init_dict ({}, index , columns , dtype = dtype )
420
- elif isinstance (data , collections .Iterator ):
421
- raise TypeError ("data argument can't be an iterator" )
422
423
else :
423
424
try :
424
425
arr = np .array (data , dtype = dtype , copy = copy )
0 commit comments