Skip to content

Why data in DataFrame(data) can be a generator but not an iterator? #21783

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

Closed
holymonson opened this issue Jul 7, 2018 · 1 comment
Closed
Labels
Duplicate Report Duplicate issue or pull request

Comments

@holymonson
Copy link
Contributor

Generator inherits from Iterator, Iterator inherits from Iterable. And list([iterable]) takes an Iterable as argument.

So, why data in DataFrame(data) can't be an Iterable?

pandas/pandas/core/frame.py

Lines 381 to 383 in 620abc4

elif isinstance(data, (list, types.GeneratorType)):
if isinstance(data, types.GeneratorType):
data = list(data)

pandas/pandas/core/frame.py

Lines 407 to 408 in 620abc4

elif isinstance(data, collections.Iterator):
raise TypeError("data argument can't be an iterator")

@TomAugspurger
Copy link
Contributor

Duplicate of #2193

I think we'd be open to making this work (by consuming the Iterable into a list).

@TomAugspurger TomAugspurger added the Duplicate Report Duplicate issue or pull request label Jul 7, 2018
@TomAugspurger TomAugspurger added this to the No action milestone Jul 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants