Do the tolist on data array inside the if

Prevent 'NoneType' object has no attribute 'tolist'