Fix the Python code to deal with all-null input gracefully