Skip to content

Conversation

@MaxGhenis
Copy link
Contributor

@MaxGhenis MaxGhenis commented Jul 23, 2025

This PR adds comprehensive test coverage for the NumPy random seed overflow fix that was already merged in commit 7dfc74f.

What this PR does

Adds tests to verify the random seed fix handles:

  • Very large entity IDs that would cause integer overflow
  • Negative entity IDs
  • Seed calculation consistency
  • Proper call count incrementing
  • The specific overflow scenario that would have caused ValueError without the fix

Context

The actual fix for the NumPy 2.1.0 random seed overflow issue was already merged to master. This PR improves code coverage by adding tests that verify the fix works correctly.

Tests

All new tests pass locally and verify that:

  • Large IDs (near int64 max) do not cause negative seed errors
  • The abs() wrapper properly handles overflow cases
  • Random values remain deterministic for the same inputs

Ensure random seeds are always non-negative by wrapping with abs() and int().
This prevents ValueError when large entity IDs cause integer overflow in
seed calculation with NumPy 2.1.0's stricter validation.

The issue occurs in policyengine-uk tests where the random() function
calculates seeds as id * 100 + count, which can overflow for large IDs.
@codecov
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.14%. Comparing base (bec3554) to head (58c2fca).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #382      +/-   ##
==========================================
+ Coverage   80.67%   81.14%   +0.46%     
==========================================
  Files         194      197       +3     
  Lines       10036    10228     +192     
  Branches     1057     1057              
==========================================
+ Hits         8097     8299     +202     
+ Misses       1651     1640      -11     
- Partials      288      289       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Test handling of large entity IDs that would cause overflow
- Test consistency of random values for same inputs
- Test proper call count incrementing
- Test handling of negative IDs
- Test specific overflow scenario that would cause ValueError without fix
@MaxGhenis MaxGhenis changed the title Fix NumPy 2.1.0 random seed overflow issue Add tests for NumPy random seed overflow fix Jul 24, 2025
- Uses the built-in GITHUB_TOKEN secret to authenticate API requests
- Increases rate limit from 60/hour (unauthenticated) to 5000/hour
- Prevents intermittent CI failures due to 403 errors when downloading data
- Test between() with various inclusive options
- Test is_in() with different data types and edge cases
- Improve overall code coverage to pass codecov checks
@MaxGhenis MaxGhenis marked this pull request as ready for review July 24, 2025 17:02
@MaxGhenis MaxGhenis merged commit 35f47d3 into PolicyEngine:master Jul 24, 2025
16 checks passed
@MaxGhenis MaxGhenis deleted the fix-numpy-random-seed branch July 24, 2025 17:03
@MaxGhenis MaxGhenis mentioned this pull request Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant