Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stable sort when sorting values in forecaster #2568

Merged
merged 1 commit into from
May 18, 2024
Merged

Commits on Apr 4, 2024

  1. Use stable sort when sorting values in forecaster

    When Prophet prepares a dataframe for fitting or predicting,
    it runs a sort on the `ds` column.
    
    This changes the sort algorithm from the pandas default sort
    to mergesort, which is a stable sort.
    
    This is important in situations where multiple regressors
    are present and so the fitted dataframe is not unique by date.
    
    Users may do something like the following:
    
    ```.py
    df = <some dataframe>
    
    m = Prophet()
    m.add_regressor('x')
    m.fit(df)
    
    predict_df = m.predict(df)
    df['prediction'] = predict_df['yhat']
    ```
    
    In `m.predict(df)`, there is a call to `df.sort_values('ds')`.
    As this is not a stable sort, sometimes the `x` column above
    can get switched around, even if `df` is sorted. A stable sort
    addresses this.
    natl committed Apr 4, 2024
    Configuration menu
    Copy the full SHA
    a8a760d View commit details
    Browse the repository at this point in the history