Skip to content

fix: align regressor_predictor forecasts with unsorted predict frames - #2786

Open
0z5a wants to merge 1 commit into
meta:mainfrom
0z5a:fix/regressor-predictor-unsorted-dates
Open

0z5a wants to merge 1 commit into
meta:mainfrom
0z5a:fix/regressor-predictor-unsorted-dates

Conversation

@0z5a

@0z5a 0z5a commented Nov 13, 2026

Copy link
Copy Markdown

Fixes #2785

Root cause

_prepare_regressors_for_predict runs before setup_dataframe sorts df by ds. The regressor models return their forecasts sorted by ds, which were written back into df by position. The regressor sample draws kept the caller's row order, while df was re-sorted later. For a frame not sorted by ds, the regressor forecasts and their uncertainty therefore landed on the wrong dates.

Fix

When any regressor has a predictor, sort df by ds (stable) before preparing the regressors. A ds index name is cleared the same way setup_dataframe does 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 with regressor_predictor=True, then predict 10 history and 20 future dates, once sorted and once shuffled. yhat, yhat_lower and yhat_upper must match.

  • main: fails, with 19 of 30 elements mismatched.
  • with this change: passes. pytest prophet/tests gives 144 passed and 2 skipped. pyrefly 0.50.0 reports 0 errors.

Note: #2769 also edits _prepare_regressors_for_predict (it parses string ds). The two patches apply cleanly together. Whichever lands second should parse ds before 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.

_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.
@meta-cla meta-cla Bot added the CLA Signed label Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

regressor_predictor: predict() on a frame not sorted by ds puts regressor forecasts on the wrong dates

1 participant