test: cover FinancialForecastModel linear-only predict and short-history AR padding - #144
Merged
shivamlalakiya merged 2 commits intoAug 24, 2026
Conversation
…ory AR padding Closes PhilanthroPy-Project#59. Two named tests: single-sample fit leaves nonlinear_model_ as None so predict must return the bare linear prediction; a context shorter than ar_order must pad the seed window with y_mean_ instead of crashing, pinned by reproducing the roll-forward from the frozen fitted statistics. _forecast.py goes 97% (Missing: 288->290, 341) to 100% line and branch.
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.
Closes #59. Test-only, no source change.
What
Two named tests in
tests/test_forecast_model.py, exactly as specced:test_predict_without_nonlinear_model_uses_linear_only: fits on a single training sample, which leaves the residual network unfitted (nonlinear_model_ is None), then assertspredict(X)matcheslinear_model_.predicton the same NaN-free input exactly. The probe is NaN-free on purpose, so imputation is the identity and the comparison against the linear sub-model is direct.test_predict_revenue_forecast_pads_short_history_with_training_mean: fits withar_order=5, callspredict_revenue_forecastwith 2 context rows (fewer thanp), asserts a finite(horizon,)array, and then reproduces the documented roll-forward by hand from the frozen fitted statistics (predicthistory reversed most-recent-first, padded topwithy_mean_), so the test pins the pad value rather than just finiteness.Evidence
Coverage of
philanthropy/models/_forecast.pyfrom this file, before and after (branch coverage):341is thewindow = list(history[::-1]) + [self.y_mean_] * (p - history.size)padding line and288->290theif self.nonlinear_model_ is not Noneguard, the two branches named in the issue. Unrelated partial branches elsewhere in the module: none left in this file, nothing else touched.Local verification
python -m pytest tests/ -q: 1910 passed, 25 skipped.python -m pytest tests/test_forecast_model.py -q: 78 passed, 1 skipped.flake8 tests/test_forecast_model.py: clean.Test-only PR, so no CHANGELOG entry per the precedent noted in #139.