Skip to content

Fix ZeroDivisionError in wikipedia_report.py on empty data#302

Merged
TimidRobot merged 1 commit into
creativecommons:mainfrom
pranjal2004838:fix/wikipedia-zerodivisionerror
Jul 15, 2026
Merged

Fix ZeroDivisionError in wikipedia_report.py on empty data#302
TimidRobot merged 1 commit into
creativecommons:mainfrom
pranjal2004838:fix/wikipedia-zerodivisionerror

Conversation

@pranjal2004838

Copy link
Copy Markdown
Contributor

Fixes

Description

Prevents ZeroDivisionError in wikipedia_report.py when the Wikipedia dataset contains headers but has no data rows (empty data). In this case, len(data) evaluates to 0, leading to division by zero. This PR adds a guard check to default the average number of articles to 0 when there is no data.

Technical details

Adds a ternary operator check:
average_articles = total_articles / len(data) if len(data) > 0 else 0

Tests

  1. Run python scripts/3-report/wikipedia_report.py with an empty or headers-only CSV file in the active quarters data directory.
  2. Verify the script runs successfully without raising a ZeroDivisionError.

Screenshots

Checklist

  • I have read and understood the Developer Certificate of Origin (DCO), below, which covers the contents of this pull request (PR).
  • My pull request doesn't include code or content generated with AI (also see Avoiding generative AI development tools — Creative Commons Open Source).
  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main or master).
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated unit tests and/or test scripts for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

@pranjal2004838 pranjal2004838 requested review from a team as code owners July 14, 2026 03:27
@pranjal2004838 pranjal2004838 requested review from TimidRobot, Copilot and possumbilities and removed request for a team July 14, 2026 03:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cc-open-source-bot cc-open-source-bot moved this to In review in TimidRobot Jul 14, 2026
@TimidRobot TimidRobot self-assigned this Jul 15, 2026

@TimidRobot TimidRobot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@TimidRobot TimidRobot merged commit ceada78 into creativecommons:main Jul 15, 2026
@github-project-automation github-project-automation Bot moved this from In review to Done in TimidRobot Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Unhandled ZeroDivisionError Risk in wikipedia_report.py on Empty Data

4 participants