Skip to content

BUG?: namedtuples fields not checked on DataFrame constructor #27329

Open
@jorisvandenbossche

Description

@jorisvandenbossche

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugConstructorsSeries/DataFrame/Index/pd.array Constructors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions