[Feature Suggestion] Multi-row delete function (w/working implementation)
- Dominant language
- Python
- Stars
- 7.5k
- Forks
- 979
- PR merge metrics
- No merged PRs in 30d
Description
Realized that deleting multiple rows one-by-one can take an extremely long time, especially when working with sheets with 1000+ rows, or have e.g. 500+ rows to delete.
I created a function to delete multiple rows by breaking list of row indexes into contiguous ranges and sending a single batchUpdate API call with multiple requests.
see delete_rows() function: https://github.com/eavalenzuela/gspread/blob/master/gspread/models.py
e.g.
[1,2,3,4,6,7,9,11,13,14,15]
becomes
[(1:4), (6:7), 9, 11, (13:15)]
i.e. 5 deleteDimension requests instead of 11, and all in 1 function call instead of doing a loop of delete_row(). It has **very** significantly reduced the time to remove large numbers of rows from sheets in my testing.
It does currently rely on the more_itertools package for the "consecutive_groups()" function, but that functionality could be added internally here if desired, to eliminate the dependency.
Contributor guide
Research direction
Start with gspread/models.py and the linked delete_rows() implementation. Review how consecutive row indexes are grouped and how one Google Sheets batchUpdate call can carry multiple deleteDimension requests; done means supporting the requested multi-row deletion without repeatedly calling delete_row().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100