25  Debugging Checklist

25.1 Reduce the problem

Create the smallest input that still produces the error.

values = ["10", "20", "missing"]

for value in values:
    try:
        number = float(value)
        print(number)
    except ValueError as error:
        print(f"Could not convert {value!r}: {error}")
10.0
20.0
Could not convert 'missing': could not convert string to float: 'missing'

25.2 Checklist

  1. Read the last line of the traceback.
  2. Confirm the variable and column names.
  3. Inspect data types.
  4. Print a small sample.
  5. Check missing values.
  6. Confirm file paths and the working directory.
  7. Test one operation at a time.
  8. Verify assumptions with assertions.
records = [{"id": 1}, {"id": 2}]
assert all("id" in record for record in records)