Skip to content

TST: Seed the weights of test_formula_equivalence_weights - #894

Closed
bycorekci wants to merge 1 commit into
bashtage:mainfrom
bycorekci:fix/flaky-gmm-formula-weights-892
Closed

bycorekci wants to merge 1 commit into
bashtage:mainfrom
bycorekci:fix/flaky-gmm-formula-weights-892

Conversation

@bycorekci

Copy link
Copy Markdown

What

Make test_formula_equivalence_weights in linearmodels/tests/system/test_gmm.py deterministic: draw the weights from a seeded np.random.default_rng and compare the array and formula estimates with rtol=1e-6.

Why

The test drew its weights from the global NumPy state, which pytest-randomly reseeds on every run, so the weights changed from run to run. For a rare, badly conditioned draw the two paths differ by rounding error slightly above the default rtol=1e-7, e.g. pytest linearmodels/tests/system/test_gmm.py --randomly-seed=480777500 fails with a maximum relative difference of 2.15e-07.

How to test

pytest linearmodels/tests/system/test_gmm.py --randomly-seed=480777500
pytest linearmodels/tests/system/test_gmm.py

Closes #892

The weights came from the global NumPy state, which pytest-randomly
reseeds on each run, and a rare badly conditioned draw made the array
and formula estimates differ by more than the default rtol of 1e-7. Draw
the weights from a seeded generator and compare with rtol=1e-6.

Closes bashtage#892
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.69%. Comparing base (1e04074) to head (0b411ed).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #894   +/-   ##
=======================================
  Coverage   99.69%   99.69%           
=======================================
  Files         206      206           
  Lines       39413    39414    +1     
  Branches     2537     2537           
=======================================
+ Hits        39291    39292    +1     
  Misses         52       52           
  Partials       70       70           
Flag Coverage Δ
adder 99.68% <100.00%> (ø)
subtractor 99.68% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@bycorekci

Copy link
Copy Markdown
Author

Closing: this is superseded by #897, which seeds the same test (and fixes the weight_type handling too). Thanks!

@bycorekci bycorekci closed this Dec 3, 2026
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.

Flaky test: test_formula_equivalence_weights in system/test_gmm.py

1 participant