Skip to content
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

[Feature Suggestion] Multi-row delete function (w/working implementation) #589

Open
eavalenzuela opened this issue Aug 29, 2018 · 1 comment

Comments

@eavalenzuela
Copy link

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.

@eavalenzuela eavalenzuela changed the title Feature Suggestion: Multi-row delete function Feature Suggestion: Multi-row delete function (w/Working implementation) Aug 30, 2018
@eavalenzuela eavalenzuela changed the title Feature Suggestion: Multi-row delete function (w/Working implementation) Feature Suggestion: Multi-row delete function (w/working implementation) Aug 30, 2018
@jvaldivia-te
Copy link

This has the potential to reduce the 429 errors.

gspread.exceptions.RequestError: (429, '429: <title>Too Many Requests</title

@eavalenzuela eavalenzuela changed the title Feature Suggestion: Multi-row delete function (w/working implementation) [Feature Suggestion] Multi-row delete function (w/working implementation) Oct 2, 2018
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

No branches or pull requests

2 participants