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

Generator support for petl.fromdicts() #569

Closed
arturponinski opened this issue Oct 7, 2021 · 0 comments · Fixed by #570
Closed

Generator support for petl.fromdicts() #569

arturponinski opened this issue Oct 7, 2021 · 0 comments · Fixed by #570

Comments

@arturponinski
Copy link
Collaborator

Minimal, reproducible code sample, a copy-pastable example if possible

import petl

data = [
    {"foo":"baz"},
    {"foo":"bar"}
]

table = petl.fromdicts(data)
print(petl.header(table))
print(petl.look(table))

def foo():
    yield {"foo": "baz"}
    yield {"foo": "bar"}

table = petl.fromdicts(foo())
print(petl.header(table))
print(petl.look(table))

Output:

('foo',)
+-------+
| foo   |
+=======+
| 'baz' |
+-------+
| 'bar' |
+-------+

('foo',)
+
|
+

Problem description

When passing a generator to petl.fromdicts() the generator is iterated only once, hence calling header(), previewing in debug or trying to iterate the table second time, returns empty result

Version and installation information

  • Value of petl.__version__ 1.7.5.dev6+dirty
  • Version of Python interpreter, tests on all supported versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant