perf(forecaster): scale PD training fetch and window features#48
Merged
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
tder311
marked this pull request as ready for review
July 9, 2026 23:52
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.
Why
predispatch_pricenow holds 519k+ rows (#46) and grows ~8k/week. The training path pulled every stored run-row into pandas and computed window features via per-group Python lambdas — flagged as a scaling time bomb in #45's review (this path also runs inside the API via /api/forecast/retrain).What
_fetch_predispatch_history: stage 1 selects run_datetimes with ≥1 interval inside the LEAD_BUCKETS lead envelope (computed from the buckets, not hardcoded); stage 2 fetches those runs' full row sets — unbounded by the window edge so boundary-day window aggregates are complete (an improvement over the old single query, which silently truncated the boundary day).predispatch_window_features: indicator-sum groupby + block-id longest-run; no Python-level per-group lambdas. Locked pd_window tests pass unchanged; outputs verified identical on a 500k synthetic frame.Evidence
🤖 Generated with Claude Code