-
Notifications
You must be signed in to change notification settings - Fork 190
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
Fix fromdicts generator support lazy #626
Fix fromdicts generator support lazy #626
Conversation
Pull Request Test Coverage Report for Build 2880829446
💛 - Coveralls |
# reverse order | ||
second_row3 = next(it2) | ||
first_row3 = next(it1) | ||
assert second_row3 == first_row3 |
Check notice
Code scanning
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert second_row3 == first_row3 | ||
ieq(actual, actual) | ||
assert actual.header() == ('n', 'foo', 'bar') | ||
assert len(actual) == 6 |
Check notice
Code scanning
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
@@ -175,9 +205,58 @@ | |||
|
|||
class DictsGeneratorView(DictsView): | |||
|
|||
def __init__(self, dicts, header=None, sample=1000, missing=None): | |||
super(DictsGeneratorView, self).__init__(dicts, header, sample, missing) |
Check notice
Code scanning
Consider using Python 3 style super() without arguments (super-with-arguments)
|
||
def _determine_header(self): | ||
it = iter(self.dicts) | ||
header = list() |
Check notice
Code scanning
Consider using [] instead of list() (use-list-literal)
if PY2: | ||
self._filecache = NamedTemporaryFile(delete=False, mode='wb+', bufsize=0) | ||
else: | ||
self._filecache = NamedTemporaryFile(delete=False, mode='wb+', buffering=0) |
Check notice
Code scanning
Consider using 'with' for resource-allocating operations (consider-using-with)
|
||
if not self._filecache: | ||
if PY2: | ||
self._filecache = NamedTemporaryFile(delete=False, mode='wb+', bufsize=0) |
Check notice
Code scanning
Unexpected keyword argument 'bufsize' in function call (unexpected-keyword-arg)
self._filecache = NamedTemporaryFile(delete=False, mode='wb+', buffering=0) | ||
|
||
position = 0 | ||
it = iter(self.dicts) |
Check notice
Code scanning
Variable name "it" doesn't conform to snake_case naming style
yield row | ||
|
||
def _determine_header(self): | ||
it = iter(self.dicts) |
Check notice
Code scanning
Variable name "it" doesn't conform to snake_case naming style
self.dicts = it | ||
if isinstance(peek, dict): | ||
peek = [peek] | ||
for o in peek: |
Check notice
Code scanning
Variable name "o" doesn't conform to snake_case naming style
def _determine_header(self): | ||
it = iter(self.dicts) | ||
header = list() | ||
peek, it = iterpeek(it, self.sample) |
Check notice
Code scanning
Variable name "it" doesn't conform to snake_case naming style
@@ -175,9 +205,58 @@ | |||
|
|||
class DictsGeneratorView(DictsView): | |||
|
|||
def __init__(self, dicts, header=None, sample=1000, missing=None): | |||
super(DictsGeneratorView, self).__init__(dicts, header, sample, missing) |
Check notice
Code scanning
Consider using Python 3 style super() without arguments
@@ -213,3 +231,29 @@ | |||
('c', 2)) | |||
ieq(expect, actual) | |||
ieq(expect, actual) | |||
|
|||
|
|||
def test_fromdicts_generator_random_access(): |
Check notice
Code scanning
Missing function or method docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 13 potential problems in the proposed changes. Check the Files changed tab for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 16 potential problems in the proposed changes. Check the Files changed tab for more details.
This PR has the objective of improving the support of generators in fromdicts.
The current implementation uses itertools.tee which according to docs and production deployments uses large amounts of memory, leading to out of memory kills of processes.
This PR aims to keep the improved support of generators by using a filecache, similar to sorting, to allow multiple iterations.
Closes #618
Changes
Moved _iterchunk from sorts to petl.util.base. Imported to sorts as _iterchunk for BC
Changes
Checklist
Use this checklist for assuring the quality of pull requests that include new code and or make changes to existing code.
tox
/pytest