Repository navigation
Conversation
_prepare_regressors_for_predict runs before setup_dataframe sorts df by ds. The regressor models return forecasts sorted by ds, which were written back by position, and the regressor sample draws kept the caller's row order while df was re-sorted later. For a frame not sorted by ds this put regressor forecasts and uncertainty on the wrong dates. Sort df by ds first when any regressor has a predictor.
This branch has not been deployed
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.
Fixes #2785
Root cause
_prepare_regressors_for_predictruns beforesetup_dataframesortsdfbyds. The regressor models return their forecasts sorted byds, which were written back intodfby position. The regressor sample draws kept the caller's row order, whiledfwas re-sorted later. For a frame not sorted byds, the regressor forecasts and their uncertainty therefore landed on the wrong dates.Fix
When any regressor has a predictor, sort
dfbyds(stable) before preparing the regressors. Adsindex name is cleared the same waysetup_dataframedoes it. Models without a regressor predictor don't go through this path. Output for already sorted frames is unchanged.Tests
test_regressor_predictor_unsorted_dates: fit withregressor_predictor=True, then predict 10 history and 20 future dates, once sorted and once shuffled.yhat,yhat_lowerandyhat_uppermust match.pytest prophet/testsgives 144 passed and 2 skipped. pyrefly 0.50.0 reports 0 errors.Note: #2769 also edits
_prepare_regressors_for_predict(it parses stringds). The two patches apply cleanly together. Whichever lands second should parsedsbefore this sort, so that string dates are sorted chronologically.This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.