Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/prophet/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def plot_plotly(

data = []
# Add actual
assert m.history
assert m.history is not None
data.append(go.Scatter(
name='Actual',
x=m.history['ds'],
Expand Down Expand Up @@ -826,7 +826,7 @@ def plot_plotly(
line=dict(color=trend_color, width=line_width),
))
# Add changepoints
assert m.changepoints
assert m.changepoints is not None
if changepoints and len(m.changepoints) > 0:
signif_changepoints = m.changepoints[
np.abs(np.nanmean(m.params['delta'], axis=0)) >= changepoints_threshold
Expand Down
22 changes: 22 additions & 0 deletions python/prophet/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get_forecast_component_plotly_props,
get_seasonality_plotly_props,
plot_forecast_component,
plot_plotly,
plot_seasonality,
plot_weekly,
plot_yearly,
Expand Down Expand Up @@ -201,3 +202,24 @@ def test_plotly_draws_data(self, model_and_forecast):
traces = get_seasonality_plotly_props(m, "weekly")["traces"]
np.testing.assert_array_equal(pd.to_datetime(traces[0].x), data["ds"])
np.testing.assert_array_equal(traces[0].y, data["weekly"])


class TestPlotPlotly:
def test_draws_forecast(self, model_and_forecast):
pytest.importorskip("plotly")
m, fcst = model_and_forecast
fig = plot_plotly(m, fcst)
traces = {trace.name: trace for trace in fig.data if trace.name}
np.testing.assert_array_equal(pd.to_datetime(traces["Actual"].x), m.history["ds"])
np.testing.assert_array_equal(traces["Actual"].y, m.history["y"])
np.testing.assert_array_equal(pd.to_datetime(traces["Predicted"].x), fcst["ds"])
np.testing.assert_array_equal(traces["Predicted"].y, fcst["yhat"])

def test_draws_trend_and_changepoints(self, model_and_forecast):
pytest.importorskip("plotly")
m, fcst = model_and_forecast
fig = plot_plotly(m, fcst, trend=True, changepoints=True, changepoints_threshold=0)
traces = {trace.name: trace for trace in fig.data if trace.name}
np.testing.assert_array_equal(traces["Trend"].y, fcst["trend"])
# With a zero threshold every changepoint is marked.
np.testing.assert_array_equal(pd.to_datetime(fig.data[-1].x), m.changepoints)