I am facing the same error in Tableau.Did you find any solution for this?
If so, please let me know what I need to change in my code.
I think the easiest solution here is to replace the missing values with some value like a moving average of the previous values or a 0. The error you are hitting at the end is due to the number of results being lower than that passed, so simply dropping the nulls won't work.
This is something you could do with calculations in Tableau, or with code in Python.