Skip to content

fix: plot_plotly fails with "truth value of a DataFrame is ambiguous" - #2788

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

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

Conversation

@0z5a

@0z5a 0z5a commented Nov 17, 2026

Copy link
Copy Markdown

Since #2720, plot_plotly raises on every call, including the plot_plotly(m, forecast) call from the quick start docs:

from prophet.plot import plot_plotly
m = Prophet().fit(df)
forecast = m.predict(m.make_future_dataframe(periods=10))
plot_plotly(m, forecast)
# ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.item(), a.any() or a.all().

The static typing change added assert m.history and assert m.changepoints to narrow the optional types. m.history is a DataFrame and m.changepoints is a Series, and pandas refuses to convert either to a bool, so the asserts raise instead of passing. The second one runs even with the default changepoints=False, so fixing only the first is not enough. Both asserts are in v1.4.0 and v1.5.0. add_changepoints_to_plot and plot_components_plotly already use is not None / a dict and are not affected.

This changes both asserts to is not None, as the rest of plot.py does. pyrefly check still reports no errors.

Tests: no test called plot_plotly itself, which is why CI did not catch it even though the dev extras install plotly. TestPlotPlotly in test_plot.py reuses the model_and_forecast fixture: it checks that the actual and predicted traces carry m.history and yhat, and that with trend=True, changepoints=True, changepoints_threshold=0 the trend trace is drawn and every changepoint is marked. The 4 new cases fail on main with the error above and pass with the change. The full prophet/tests suite passes (147 passed, 2 skipped) with pandas 3.1.1, numpy 2.5.4 and plotly 7.1.0.

This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

The static typing change added `assert m.history` and
`assert m.changepoints` to plot_plotly. Both are pandas objects, whose
truth value raises, so plot_plotly failed on every call. Use
`is not None` as the rest of plot.py does, and add tests that call
plot_plotly.
@meta-cla meta-cla Bot added the CLA Signed label Nov 17, 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