python file io and nan fixes