Warn instead of silently mislabelling a dataset's fiscal year - #1846
Warn instead of silently mislabelling a dataset's fiscal year#1846vahid-ahmadi wants to merge 1 commit into
Conversation
`UKSingleYearDataset` took `fiscal_year=2025` as a default but used it only when building from DataFrames: with a file path the period is read from the file and the argument was ignored without comment. Both halves failed quietly. Passing a conflicting year alongside a file had no effect, and omitting it when assembling frames by hand labelled the data 2025 — already a year ahead of the newest release, and wrong differently every year. The default now warns on use and the conflicting-argument case warns too, so neither can mislabel a dataset unnoticed. Removing the default outright would break callers, so it is deprecated rather than dropped. Closes #1845 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Program ReviewSource Documents
Critical (Must Fix)
Should AddressNone. SuggestionsNone. PDF Audit Summary
Validation Summary
Review Severity: REQUEST_CHANGESNext StepsResolve C1 and C2, then rerun the fresh-process warning regression, the focused tests, Ruff, Towncrier draft, and the repository test suite. To auto-fix issues: run the fix-pr workflow for this PR. |
Closes #1845.
UKSingleYearDataset.__init__declaredfiscal_year: int = 2025but used it on only one of its two branches, so both halves failed quietly.Ignored alongside a file path. With
file_path, the period comes from the file and the argument was discarded without comment:A hardcoded default that drifts. Building from DataFrames without it labelled the data 2025 — already a year ahead of the newest release, since FRS 2024/25 is label 2024 on our convention, and wrong differently every year:
This came up with an external collaborator who was labelling 2024/25 data as 2025 and reasonably assumed the argument did something.
This PR
fiscal_yearnow defaults toNone, and both silent paths warn:file_pathraises aUserWarningsaying it cannot take effect, and points atuprate_datasetfor changing the period;DeprecationWarningnaming the label it fell back to and restating the convention.Behaviour is otherwise unchanged: the fallback still yields 2025, kept as
DEFAULT_FISCAL_YEAR. Nothing we ship is affected —create_frspassesfiscal_yearat all three construction sites.Why deprecate rather than require
Making
fiscal_yearmandatory is the better end state, but it breaks any caller relying on the default, so I have not done it here. If you would rather take the break now, say and I will switch theDeprecationWarningto aValueError— it is a two-line change and the tests already cover both paths.Tests
test_dataset_fiscal_year.py: the argument sets the period; omitting it warns and falls back; passing it with a file path warns and the file's period still wins; loading normally warns about nothing.Full suite: 1,140 yaml policy tests and 181 pytest (44 skipped), ruff clean.