Description
wikipedia_report.py has a potential crash due to ZeroDivisionError when processing empty language datasets. Specifically, if the CSV data file was successfully fetched but contained only headers (0 data rows)—which is a common edge case during API outages or schema changes—len(data) will evaluate to 0, causing the script to crash on division.:
Reproduction
- Run
wikipedia_report.py where the corresponding Wikipedia CSV data file under data/ is empty or contains only headers (0 data rows).
- The script executes:
|
average_articles = total_articles / len(data) |
- Since
len(data) is 0, a ZeroDivisionError is thrown.
- The reporting phase crashes entirely.
Expectation
The script should handle the case where the data rows are empty by defaulting the average to 0 and continuing to generate the report.
Environment
| Software |
Version |
| Python |
3.11 |
| OS |
Windows / Linux / macOS |
Description
wikipedia_report.pyhas a potential crash due toZeroDivisionErrorwhen processing empty language datasets. Specifically, if the CSV data file was successfully fetched but contained only headers (0 data rows)—which is a common edge case during API outages or schema changes—len(data)will evaluate to 0, causing the script to crash on division.:Reproduction
wikipedia_report.pywhere the corresponding Wikipedia CSV data file underdata/is empty or contains only headers (0 data rows).quantifying/scripts/3-report/wikipedia_report.py
Line 106 in 33577d9
len(data)is0, aZeroDivisionErroris thrown.Expectation
The script should handle the case where the data rows are empty by defaulting the average to
0and continuing to generate the report.Environment