Implement worksheet methods to delete non-contiguous blocks of rows/columns in one API call (implements issue 1589) - #1598
Merged
Conversation
…ocks (issue burnash#1589) New Worksheet methods that delete multiple non-contiguous blocks of rows or columns with a single batchUpdate API call and keep the cached row/column count in sync, unlike calling Spreadsheet.batch_update() directly. Tests added (cassettes to be recorded in a follow-up commit)
Collaborator
|
@Ev2geny: merged :) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This implements #1589
What this PR does
Adds new
Worksheetmethods that delete multiple non-contiguous blocks of rows orcolumns with a single
batchUpdateAPI call, while keeping the locally cachedrow_count/col_countin sync (the stale-cache problem described in the issue):Note: slightly expanded scope vs. what was agreed in the issue
The issue discussion agreed on
delete_rows_blocksonly. While implementing it Ifollowed the existing structure of the module, where
delete_rowsanddelete_columnsare thin wrappers around a genericdelete_dimension. Mirroringthat pattern gave the column variant essentially for free, so this PR adds:
delete_dimension_blocks(dimension, blocks)— generic implementationdelete_rows_blocks(blocks)— what was agreed in the issuedelete_columns_blocks(blocks)— the symmetric column variantDesign
(start, end)pairs, consistent withdelete_rows(start, end). They may be tuples or lists(
Sequence[Sequence[int]]), in any order; they are sorted internally and thedeleteDimensionrequests are emitted bottom-up, so earlier deletions in thebatch don't shift the indexes of later ones.
ValueErrorbefore any API call: empty blockslist, a block without exactly 2 elements,
start < 1,end < start, a blockexceeding the current sheet size, and overlapping blocks (adjacent blocks are
allowed).
rowCount/columnCountis decremented by the totalnumber of deleted rows/columns, so subsequent
add_rows()/resize()calls workwith correct values.
Note on
.. versionadded:: 6.3.0The docstrings mark the new methods as
versionadded:: 6.3.0. That version is aguess (current release is 6.2.1 and this is a new feature, so the next minor
seemed likely). If the actual release number ends up different, these three
directives will need updating.
Testing
test_delete_rows_blocks,test_delete_columns_blocks(both pass blocks unsorted and mixing lists/tuples) and
test_delete_dimension_blocks_validation(allValueErrorcases).tox -e py).--disable-vcr.tox -e doc