Skip to content

Implement worksheet methods to delete non-contiguous blocks of rows/columns in one API call (implements issue 1589) - #1598

Merged
antoineeripret merged 2 commits into
burnash:masterfrom
Ev2geny:issue_1589
Jul 23, 2026
Merged

Implement worksheet methods to delete non-contiguous blocks of rows/columns in one API call (implements issue 1589)#1598
antoineeripret merged 2 commits into
burnash:masterfrom
Ev2geny:issue_1589

Conversation

@Ev2geny

@Ev2geny Ev2geny commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

This implements #1589

What this PR does

Adds new Worksheet methods that delete multiple non-contiguous blocks of rows or
columns with a single batchUpdate API call, while keeping the locally cached
row_count / col_count in sync (the stale-cache problem described in the issue):

# Delete rows 3–5 and rows 8–9 in one API call
worksheet.delete_rows_blocks([(3, 5), (8, 9)])

Note: slightly expanded scope vs. what was agreed in the issue

The issue discussion agreed on delete_rows_blocks only. While implementing it I
followed the existing structure of the module, where delete_rows and
delete_columns are thin wrappers around a generic delete_dimension. Mirroring
that pattern gave the column variant essentially for free, so this PR adds:

  • delete_dimension_blocks(dimension, blocks) — generic implementation
  • delete_rows_blocks(blocks) — what was agreed in the issue
  • delete_columns_blocks(blocks) — the symmetric column variant

Design

  • Blocks are 1-based inclusive (start, end) pairs, consistent with
    delete_rows(start, end). They may be tuples or lists
    (Sequence[Sequence[int]]), in any order; they are sorted internally and the
    deleteDimension requests are emitted bottom-up, so earlier deletions in the
    batch don't shift the indexes of later ones.
  • Strict validation raises ValueError before any API call: empty blocks
    list, a block without exactly 2 elements, start < 1, end < start, a block
    exceeding the current sheet size, and overlapping blocks (adjacent blocks are
    allowed).
  • After the call, the cached rowCount/columnCount is decremented by the total
    number of deleted rows/columns, so subsequent add_rows()/resize() calls work
    with correct values.

Note on .. versionadded:: 6.3.0

The docstrings mark the new methods as versionadded:: 6.3.0. That version is a
guess (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

  • Three new tests: test_delete_rows_blocks, test_delete_columns_blocks
    (both pass blocks unsorted and mixing lists/tuples) and
    test_delete_dimension_blocks_validation (all ValueError cases).
  • Cassettes recorded; the full suite passes offline (tox -e py).
  • The new tests were additionally verified against the live API with
    --disable-vcr.
  • new API is correctly documented in HTML files after running tox -e doc

Ev2geny added 2 commits July 16, 2026 20:17
…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)
@antoineeripret
antoineeripret merged commit 5bc4559 into burnash:master Jul 23, 2026
5 checks passed
@antoineeripret

Copy link
Copy Markdown
Collaborator

@Ev2geny: merged :)

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 this pull request may close these issues.

2 participants