BUG?: namedtuples fields not checked on DataFrame constructor · Issue #27329 · pandas-dev/pandas (original) (raw)

I personally find it very surprising that we assume that if the first element is a NamedTuple, that all elements of the list will be exactly the same NamedTuples:

In [29]: Record1 = namedtuple('Record1', ('b','a'))                                                                                                           

In [30]: Record2 = namedtuple('Record2', ('a','c'))                                                                                                           

In [31]: records = [Record1(1, 2), Record2(3, 4)]                                                                                                             

In [32]: pd.DataFrame(records)                                                                                                                                
Out[32]: 
   b  a
0  1  2
1  3  4

So the field names of the subsequent namedtuples are simply ignored.

The case of all the same tuples might be the most typical case, but it doesn't seem very safe for a default behaviour to not check this.