Skip to content

Fix plot_plotly raising ValueError on every call - #2796

Open
omkarbandikatte wants to merge 1 commit into
meta:mainfrom
omkarbandikatte:fix/plot-plotly-assert
Open

omkarbandikatte wants to merge 1 commit into
meta:mainfrom
omkarbandikatte:fix/plot-plotly-assert

Conversation

@omkarbandikatte

Copy link
Copy Markdown

plot_plotly raises a ValueError for any fitted model, before it draws anything:

import numpy as np, pandas as pd
from prophet import Prophet
from prophet.plot import plot_plotly

df = pd.DataFrame({"ds": pd.date_range("2020-01-01", periods=100),
                   "y": np.sin(np.arange(100) / 5) + np.arange(100) / 50})
m = Prophet().fit(df)
fcst = m.predict(m.make_future_dataframe(10))
plot_plotly(m, fcst)
  File ".../prophet/plot.py", line 764, in plot_plotly
    assert m.history
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.item(), a.any() or a.all().

m.history is a DataFrame, and pandas refuses to turn a DataFrame into a bool. The same applies further down to assert m.changepoints, which is a Series, so fixing only the first line moves the error to line 829. Both asserts came in with the type annotations in #2720, so this affects 1.4.0 and later; I reproduced it with 1.5.0 from PyPI and on main. plot_components_plotly is not affected.

This changes both asserts to is not None, the form the other asserts in plot.py already use (for example assert m.changepoints is not None in add_changepoints_to_plot).

Testing

The existing plotly tests only call the get_*_plotly_props helpers, so nothing called plot_plotly itself. I added TestPlotPlotly.test_draws_forecast to python/prophet/tests/test_plot.py. It uses the existing model_and_forecast fixture, calls plot_plotly with trend=True, changepoints=True, and checks that the actual, predicted, trend and changepoint traces match the model and the forecast.

  • Without the fix: both fixture cases (additive, multiplicative_logistic) fail with the error above.
  • With the fix: test_plot.py passes (22 tests), and so does the rest of python/prophet/tests (144 passed, 2 skipped).

assert m.history and assert m.changepoints call bool() on a DataFrame and
a Series, which pandas rejects. Check for None instead, as the other
asserts in plot.py do, and add a test that calls plot_plotly.
@meta-cla

meta-cla Bot commented Nov 26, 2026

Copy link
Copy Markdown

Hi @omkarbandikatte!

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 Nov 26, 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 Nov 26, 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