Debugging research code#
Fig. 11 Debugging the tool used for debugging. “Debugger” by Randall Munroe, licensed CC BY-NC 2.5.#
Debugging is an investigation, not a sign that you are bad at programming.
Read tracebacks from the bottom#
Traceback (most recent call last):
...
ValueError: operands could not be broadcast together with shapes (32,500) (32,)
Start with:
Error type:
ValueErrorError message: incompatible shapes
Your line nearest the bottom
Inspect the smallest useful facts#
print(type(value))
print(array.shape)
print(frame.columns.tolist())
print(frame.dtypes)
print(path.resolve())
print(path.exists())
Common error patterns#
Error |
First question |
|---|---|
|
Was the variable created in this execution? |
|
Which dictionary keys or DataFrame columns exist? |
|
What is the size of that axis? |
|
What is the object’s actual type? |
|
Which interpreter/environment is running? |
broadcasting |
What are both shapes? |
file not found |
What does the resolved path say? |
Reduce the example#
Replace a large pipeline with a tiny object that reproduces the error:
small = epochs[:2, :3, :10]
print(small.shape)
Ask a high-quality question#
Include:
what you expected;
what happened;
the complete error;
relevant types and shapes;
a minimal code example;
what you already tried.