Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jorisvandenbossche opened this issue Jul 10, 2019 · 2 comments
Open
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors

Comments

@jorisvandenbossche
Copy link
Member

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.

@jorisvandenbossche jorisvandenbossche changed the title BUG: namedtuples fields not checked on DataFrame constructor BUG?: namedtuples fields not checked on DataFrame constructor Jul 10, 2019
@ghost
Copy link

ghost commented Jul 11, 2019

#11416 (comment)

@jorisvandenbossche
Copy link
Member Author

Thanks for digging that up. Now, we do this "expensive" check for Series and dicts, though, so I think we should also do it for namedtuples. Also, I suppose the cythonized fast_unique_multiple_list_gen that is used to union the dict keys will be faster than what was tested there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants