the below post comment has 3 solution linked post, go through them, to debug your codes. A feedback like series_valid is not defined, is usually indicative, you probably not using the right function or right way to get a return function. For example if it was told you use a range, you need to use the right variable recall instead of using len function to the designated time period range.
Regards
DP