Skip to content
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

BUG: Instantiating DataFrames using dicts with iterators/generators as values causes errors #26349

Closed
topper-123 opened this issue May 11, 2019 · 0 comments

Comments

@topper-123
Copy link
Contributor

commented May 11, 2019

Working on removing compat.lrange, I've found that Series will accept iterators and generators as input:

>>> pd.Series(reversed(range(3)))  # Iterator work for Series
0    0
1    1
2    2
dtype: int64
>>>  pd.Series((i for i in range(3)))  # Generators work for Series
0    0
1    1
2    2
dtype: int64

If iterators and generators work when instantiating Series, I'd expect that they'd work as dict-values for DataFrames also, but they don't:

>>> pd.DataFrame({'A': reversed(range(3))})  # iterator do not work
TypeError: object of type 'range_iterator' has no len()
>>> pd.DataFrame({'A': (i for i in range(3))})  # generator do not work
TypeError: object of type 'generator' has no len()
>>> pd.DataFrame({'A': range(3)})  # ranges work
   A
0  0
1  1
2  2

The docs say that list-likes will work as dict values, and because iterators and generators are iterables and list-like, they should work.

This issue is different than #26342, but the fix is still relatively straight forward.

I can can put up a PR one of the coming days,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.