Skip to content

fix: predict with a regressor_predictor fails when training rows have a missing y - #2763

Open
sumedhekaru wants to merge 1 commit into
meta:mainfrom
sumedhekaru:upstream/regressor-predictor-nan
Open

sumedhekaru wants to merge 1 commit into
meta:mainfrom
sumedhekaru:upstream/regressor-predictor-nan

Conversation

@sumedhekaru

Copy link
Copy Markdown

Bug. Take a regressor added with regressor_predictor=True, and a training frame with some NaN y values (rows
where the regressor is known). Then predict() on a future frame without the regressor column, for example
make_future_dataframe(), raises ValueError: Found NaN in column '<name>':

import numpy as np
import pandas as pd
from prophet import Prophet

rng = np.random.default_rng(0)
n = 200
t = np.arange(n)
df = pd.DataFrame({"ds": pd.date_range("2024-01-01", periods=n),
                   "x": 5 + 0.01 * t + np.sin(2 * np.pi * t / 7)})
df["y"] = 10 + 0.8 * df["x"] + rng.normal(0, 0.3, n)
df.loc[[20, 21, 100], "y"] = np.nan

m = Prophet()
m.add_regressor("x", regressor_predictor=True)
m.fit(df)
m.predict(m.make_future_dataframe(periods=10))  # ValueError: Found NaN in column 'x'

Cause. In _prepare_regressors_for_predict, missing regressor values on history dates are looked up in
self.history. Rows with a NaN y are dropped from self.history, so those dates stay NaN. The regressor model,
however, is fit on every date where the regressor is known (_fit_regressor_models), including those rows.

Fix. After the existing lookup, fill any history dates that are still missing from the regressor model's own
history. The existing lookup is unchanged, so every case that worked before gives bit-identical output. Dates where the
regressor itself was unknown in training still raise, as before.

Tests. A new test in TestProphetRegressors: training data with three NaN y rows; predict on
make_future_dataframe succeeds, and the history rows get the known regressor values. The test fails on main with the
error above. The full suite passes (138 passed, 6 skipped). On 10 fit/predict scenarios (536 arrays), fitted parameters
and predict output are bit-identical to main. regressor_predictor is Python-only, so there is no R change.

It also passes this repository's Build workflow on my fork (Linux x86/ARM, macOS Intel/ARM, Windows, type check, R): https://github.com/sumedhekaru/prophet/actions/runs/39704535238

@meta-cla

meta-cla Bot commented Oct 22, 2026

Copy link
Copy Markdown

Hi @sumedhekaru!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Oct 22, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Oct 22, 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.

1 participant