Fix SPI __main__ crash, parameterise marriage allowance, seed age RNG#349
Merged
Fix SPI __main__ crash, parameterise marriage allowance, seed age RNG#349
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
policyengine_uk_data/datasets/spi.pyhad four small but load-bearing bugs (bug-hunt finding U2):__main__block calledcreate_spi(path, year)with two positional args, but the signature required three — running the module directly crashed withTypeError: create_spi() missing 1 required positional argument.1_250(2020-21), so builds for later fiscal years produced the wrong cap for every row whereMAIND == 1.np.random.randwas used unseeded, so age imputation drifted non-deterministically across builds.GORCODEvalues silently fell through toSOUTH_EAST, quietly distorting regional income totals.This PR:
output_file_pathoptional so two-arg calls and the existing__main__entry point both work.personal_allowance × marriage_allowance.max, rounded up byrounding_increment— the same formula used in policyengine-uk'smarriage_allowancevariable) keyed on the fiscal year.np.random.default_rng(seed)withseed=0by default."UNKNOWN"; legacy"SOUTH_EAST"behaviour is still accessible viaunknown_region=....Adds
policyengine_uk_data/tests/test_spi_build.pycovering each of the four fixes with a lightweight fake SPI.tabfile.Test plan
uv run pytest policyengine_uk_data/tests/test_spi_build.pypasses.__main__-friendly default onoutput_file_path.np.randomstate.Finding U2 from the bug hunt.