This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Ability to skip last rows. #225
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ language: | |
|
||
python: | ||
- 2.7 | ||
- 3.3 | ||
# - 3.3 # pytest does not support 3.3 any more | ||
# - 3.4 | ||
- 3.5 | ||
- 3.6 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -416,10 +416,17 @@ def __detect_html(self): | |
raise exceptions.FormatError(message) | ||
|
||
def __apply_processors(self, iterator): | ||
# last row counter will be incremented in builtin_processor() | ||
# and used in skip_negative_rows() to count rows from the end | ||
last_row_number = 0 | ||
rows_to_skip_from_end = [n for n in self.__skip_rows_by_numbers if n < 0] | ||
|
||
# Builtin processor | ||
def builtin_processor(extended_rows): | ||
global last_row_number | ||
|
||
for row_number, headers, row in extended_rows: | ||
last_row_number = row_number | ||
|
||
# Sync headers/row | ||
if headers != self.__headers: | ||
|
@@ -452,30 +459,34 @@ def skip_negative_rows(extended_rows): | |
Rows to skip are taken from Stream.__skip_rows_by_numbers | ||
""" | ||
rows_to_skip = [n for n in self.__skip_rows_by_numbers if n < 0] | ||
if not rows_to_skip: | ||
for row in extended_rows: | ||
buffer_size = abs(min(rows_to_skip)) | ||
# collections.deque - takes O[1] time to push/pop values from any side. | ||
buffer = deque() | ||
|
||
# use buffer to save last rows | ||
for row in extended_rows: | ||
buffer.append(row) | ||
if len(buffer) > buffer_size: | ||
yield buffer.popleft() | ||
|
||
# Now squeeze out the buffer | ||
global last_row_number | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why use the global? usually it's a sign of bad design. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh my stupid head :) that's so obvious ))) |
||
# with last_row_number, we could transform negative row numbers to positive | ||
rows_to_skip_positive = [last_row_number + 1 + n for n in rows_to_skip] | ||
for row in buffer: | ||
if row[0] not in rows_to_skip_positive: | ||
yield row | ||
else: | ||
buffer_size = abs(min(rows_to_skip)) + 1 | ||
# collections.deque - takes O[1] time to push/pop values from any side. | ||
buffer = deque() | ||
|
||
# use buffer to save last rows | ||
for row in extended_rows: | ||
buffer.append(row) | ||
if len(buffer) == buffer_size: | ||
yield buffer.popleft() | ||
|
||
# Now squeeze out the buffer | ||
last_row_number = buffer[len(buffer)-1][0] | ||
# with last_row_number, we could transform negative row numbers to positive | ||
rows_to_skip_positive = [last_row_number + 1 + n for n in rows_to_skip] | ||
for row in buffer: | ||
if row[0] not in rows_to_skip_positive: | ||
yield row | ||
|
||
# form a processors list | ||
processors = [builtin_processor] | ||
|
||
if rows_to_skip_from_end: | ||
processors.append(skip_negative_rows) | ||
|
||
if self.__post_parse: | ||
processors += self.__post_parse | ||
|
||
# Apply processors to iterator | ||
processors = [builtin_processor, skip_negative_rows] + self.__post_parse | ||
for processor in processors: | ||
iterator = processor(iterator) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ package=tabulator | |
skip_missing_interpreters=true | ||
envlist= | ||
py27 | ||
py33 | ||
py34 | ||
py35 | ||
py36 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why create a list here if you're not using it?