Add tree-shaped parameter loader mirroring Python (#50)#84
Open
vahid-ahmadi wants to merge 1 commit into
Open
Conversation
Add `ParamTree`, a directory-tree parameter loader that mirrors the Python policyengine-uk parameter system, landing additively alongside the existing hand-coded `Parameters` struct and flat year-files. - Walks a directory tree of YAML files into a typed node tree. - Supports the three Python node types: `values:` (date-keyed scalars), `brackets:`, and `scales:` (handled as brackets). - Path resolution by dot-separated path with Python step-function date semantics (latest value on or before the requested date; `null` clears a window). - Forward auto-uprating: values beyond the last declared year are projected by an index from `metadata.uprating`, scaling the last known value by index(now)/index(base); holds flat without an index. - Adds a small fixture parameter tree under tests/fixtures/parameters/ and tests covering value-by-date resolution, bracket/scale parsing, path lookup, and uprating projection. Migrating compute_* consumers off the hand-coded struct is the remaining follow-up for #50. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Addresses #50.
Scope
Lands a tree-shaped parameter loader (
ParamTree) that mirrors the Pythonpolicyengine-ukdirectory-tree parameter system. This is additive: it does not delete the existing flat year-files (parameters/YYYY_YY.yaml) or the hand-codedParametersstruct, and it does not change any existing consumer. The new loader coexists with the existing system so nothing breaks and everything still compiles.New module
src/parameters/param_tree.rs:ParamTree::from_dirwalks a directory tree of YAML parameter files and parses each leaf into a typedNodetree. Directories become interiorSubtreenodes;.yaml/.ymlfiles become leaves keyed by file stem.values:— date-keyed scalarsbrackets:— list of{ rate, threshold }, each date-keyedscales:— synonym forbrackets:, handled identicallytree.get_at("gov.hmrc.income_tax.rates.basic_rate", 2025)returns the value in force at that date, using step-function semantics (latest entry on or before the requested date).nullentries clear a value within a window.metadata.uprating(e.g.gov.indices.cpi), scaling the last-known value byindex(requested) / index(base). With no index the series is held flat.tests/fixtures/parameters/gov/(income tax rates/personal allowance, UC standard allowance, Scottish LBTT brackets, CPI index) gives the loader real YAML to parse.Tests
8 unit tests covering: value-by-date resolution (including before-first-entry →
None), the step-function picking the latest on-or-before entry, directory path lookup, bracket/scale parsing and resolution, forward uprating projection beyond the last declared year, holding flat without an index, thescales:synonym, andnull-within-window clearing.cargo buildandcargo testboth pass (198 existing tests + 8 new, 0 failures).Remaining
This PR lands the loader infrastructure only. Migrating the
compute_*consumers insrc/variables/off the hand-codedParametersstruct onto path-keyedParamTreelookups (and copying the authoritativegov/...tree frompolicyengine-uk) is the follow-up for #50 — out of scope here because it would touch every consumer at once.🤖 Generated with Claude Code