Use shared WEEKS_IN_YEAR and local RNG in consumption imputation#353
Merged
Use shared WEEKS_IN_YEAR and local RNG in consumption imputation#353
Conversation
Contributor
Author
|
Self-review: APPROVE. See |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
datasets/imputations/consumption.pyhad two sub-bugs (finding U6):* 52while the sibling FRS loader usesWEEKS_IN_YEAR = 365.25 / 7 ≈ 52.1786. That ~0.34% gap systematically underestimated annualised LCFS consumption relative to FRS income and skewed VAT/energy imputation targets.np.random.seed(42)calls mutated the process-wide RNG state, so any unrelated numpy random consumer that ran after consumption imputation silently changed behaviour.This PR:
WEEKS_IN_YEARto module scope indatasets/frs.py(with a docstring) so siblings can import one canonical value, and swapsconsumption.pyto use it for both the household and person annualisation passes.np.random.seed(42)calls withrng = np.random.default_rng(42)and routes the draws through the local RNG, keeping the seed at 42 for bit-for-bit fingerprint compatibility.test_consumption_weeks_rng.pyasserting the imported constant matches, the module source no longer containsnp.random.seed(, and re-importing consumption does not perturb the global RNG state.Test plan
uv run pytest policyengine_uk_data/tests/test_consumption_weeks_rng.py -qpasses.Finding U6 from the bug hunt.