3.4 KiB
Common Errors and Troubleshooting
Quick reference for fixing common issues. For error handling patterns when writing code, see error_handling.md.
Data Loading Errors
Error: "Data file not found"
Cause: DATA_FILE path in config.py is incorrect Fix:
- Check that your CSV file exists
- Update
DATA_FILEin config.py with correct filename - If file is in a subdirectory, set
DATA_DIRin config.py
Error: "Required column 'USD' not found"
Cause: Column name in data doesn't match config Fix:
- Check your CSV column names
- Update
REVENUE_COLUMNin config.py to match your data - Update other column mappings (DATE_COLUMN, CUSTOMER_COLUMN, etc.)
Error: "All InvoiceDate values are NaN"
Cause: Date column parsing failed Fix:
- Check date format in your CSV
- Add fallback date columns to
DATE_FALLBACK_COLUMNSin config.py - Ensure at least one date column exists (Month, Year, etc.)
Analysis Errors
Error: "DataFrame is empty" after filtering
Cause: Date range or year filters too restrictive Fix:
- Check
MIN_YEARandMAX_DATEin config.py - Check
ANALYSIS_YEARSincludes years in your data - Verify date parsing worked (check data_loader output)
Error: Charts show scientific notation (1e8)
Cause: Forgot to divide by 1e6 before plotting Fix:
# WRONG:
ax.plot(revenue, ...)
# CORRECT:
ax.plot(revenue / 1e6, ...)
setup_revenue_chart(ax)
Error: "Year column has mixed types"
Cause: LTM year is string "2025 (LTM 9/2025)" while others are int Fix:
from analysis_utils import sort_mixed_years
df_sorted = sort_mixed_years(df, year_col='Year')
Configuration Errors
Error: LTM not working correctly
Cause: LTM configuration incorrect Fix:
- Check
LTM_ENABLED = Truein config.py - Verify
LTM_START_MONTH,LTM_START_YEAR,LTM_END_MONTH,LTM_END_YEAR - Ensure dates are within your data range
Error: Exclusion filters not working
Cause: Filter configuration incorrect Fix:
- Check
EXCLUSION_FILTERS['enabled'] = True - Verify
exclude_by_columnmatches a column in your data - Check
exclude_valueslist is correct
Import Errors
Error: "No module named 'config'"
Cause: Running script from wrong directory Fix:
- Run scripts from template root directory
- Or add template directory to Python path
Error: "No module named 'data_loader'"
Cause: Missing import or wrong directory Fix:
- Ensure all template files are in the same directory
- Check import statements match file names
Best Practices to Avoid Errors
- Always use utilities: Use
analysis_utils.pyfunctions instead of manual code - Validate data: Run
validate_data_structure()after loading - Check config: Verify all column names match your data (use
config_validator.py) - Test incrementally: Test data loading before running full analysis
- Read error messages: They usually tell you exactly what's wrong
- Use Cursor AI: Ask AI to fix errors - it knows template patterns
Using Cursor AI to Fix Errors
When you encounter an error, ask Cursor AI:
"Fix this error: [paste error message]"
The AI will:
- ✅ Understand the error context
- ✅ Reference template patterns
- ✅ Suggest specific fixes
- ✅ Use template utilities correctly
See also: .cursor/rules/error_handling.md for how to write error messages that help AI fix issues.