simplify complete model runs#620
Conversation
the logic for the step counts and aggregations is identical, it makes sense to combine into one single step. fixes #288 - at least, this doesn't appear to be an issue anymore. rather than just deleting the groupby/sum, added in a check to ensure there are no duplicated rows in the series. if there are then we will raise an assertion error. this also simplifies the model iteration, instead of returning a tuple of the aggregated results and the step counts, the step counts are added to the results dictionary
✅ A new build is available.You can use the following to use pull the image into your local environment: docker pull ghcr.io/the-strategy-unit/nhp_model:pr-620 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #620 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 20 20
Lines 1130 1134 +4
Branches 56 58 +2
=========================================
+ Hits 1130 1134 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Simplifies result aggregation by merging step counts handling into the standard model results combination flow. Previously, get_aggregate_results returned a tuple of (aggregated_results, step_counts) requiring a separate _combine_step_counts function; now step counts are an entry in the same dictionary, eliminating duplicate logic. As part of this, the historical "duplicate rows" workaround (issue #288) is replaced with a defensive _check_for_duplicates assertion.
Changes:
- Replace
ModelRunResulttuple type with a plaindict[str, pd.Series]and placestep_countsinto the aggregations dict. - Remove
_combine_step_countsand route step counts through_combine_model_results, adding a_check_for_duplicatesguard. - Update unit/integration tests to match the new return shape and add coverage for the duplicate check.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/nhp/model/model_iteration.py | Change ModelRunResult to a dict and add step counts into the aggregations dict. |
| src/nhp/model/results.py | Remove _combine_step_counts; add _check_for_duplicates; reroute step counts through unified combine path. |
| src/nhp/model/run.py | Adjust unpacking of get_aggregate_results and read step counts from results dict. |
| tests/unit/nhp/model/test_results.py | Replace _combine_step_counts tests with _check_for_duplicates tests and update combine tests. |
| tests/unit/nhp/model/test_model_iteration.py | Update assertions; add test for None step counts. |
| tests/unit/nhp/model/test_run.py | Update mock side effects to new return shape. |
| tests/integration/nhp/model/test_single_model_run.py | Stop unpacking tuple; remove redundant step_counts assignment. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
the logic for the step counts and aggregations is identical, it makes sense to combine into one single step.
fixes #288 - at least, this doesn't appear to be an issue anymore. rather than just deleting the groupby/sum, added in a check to ensure there are no duplicated rows in the series. if there are then we will raise an assertion error.
this also simplifies the model iteration, instead of returning a tuple of the aggregated results and the step counts, the step counts are added to the results dictionary