Give the financial-year boundary one home in translator.helpers - #141
Open
nick-gorman wants to merge 2 commits into
Open
Give the financial-year boundary one home in translator.helpers#141nick-gorman wants to merge 2 commits into
nick-gorman wants to merge 2 commits into
Conversation
…raint docstrings _keep_rows_for_enabled_elements is shared by the network and constraints translators, but "enabled elements" only described the network caller — the constraints side passes constraint_ids. Renamed to _keep_rows_for_expansion_ids and reworded the docstrings so each caller's selection is described where the decision is made. The constraint helpers' I/O examples now show full tables, including the blank-cell wildcard forms the options and costs accept. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The start of a model year under FY nomenclature (1 July of the year before the label) was encoded three times: forward as a triple in _get_iteration_start_and_end_time, forward again as Timestamps in constraints._investment_period_start_dates, and in reverse in snapshots._add_investment_periods. A change to any one would silently leave the custom-constraint date_from resolution and the snapshots disagreeing about where a period begins. _period_start and its inverse _period_of now own the convention; the triple helper and the two other sites derive from them, with the triple's shape pinned by a test so the snapshot builders are unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XRWFpjCqEbjKuYNv7mVsUk
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
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.
Follow-up to #139, stacked on
translate-custom-constraints— retarget tomainonce that merges.#139's review noted that
_investment_period_start_datesintranslator/constraints.pyre-encodes the financial-year boundary — "FY 2030 starts on 1 July 2029" — that_get_iteration_start_and_end_timeintranslator/helpers.pyalready owns for the snapshots. Going looking, there is a third copy:snapshots._add_investment_periodsencodes the same boundary in reverse (month >= 7→year + 1). Three independent encodings of one convention means a change to any of them would silently leave the custom-constraintdate_fromresolution and the snapshots disagreeing about where a period begins, with nothing failing.This change gives the convention one home.
helpers.pygains two small primitives —_period_start(year_type, year)for the forward mapping and_period_of(year_type, timestamps)for the inverse — and the three existing sites derive from them.A few choices worth flagging:
_get_iteration_start_and_end_timekeeps its(start_year, end_year, month)shape sosnapshots.pyandtemporal_filters.pydon't change; it now computes its two boundaries via_period_start, with the exclusive end being the start of the year afterend_year(which is where its calendar branch'send_year + 1came from). A new test pins the triple for both year types, so parity with the old branches is checked rather than assumed. Retiring the triple in favour of the callers using_period_startdirectly would be the natural next step, but it's a larger diff and is left out here.year_type == "fy"branches in the translator (helpers._get_financial_year_int_from_stringand the cost-column parsing inlinks.py) turn"2025_26"strings into ints — a different concern from the period boundary, and both are old-format code._investment_period_start_dateskeeps its name inconstraints.py, since it reads well in the orchestrator; only its body changes.🤖 Generated with Claude Code
https://claude.ai/code/session_01XRWFpjCqEbjKuYNv7mVsUk