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

FutureWarning of DatetimeProperties.to_pydatetime is depircated for plot_plotly and m.plot() #2492

Open
RoshanAli339 opened this issue Sep 14, 2023 · 4 comments

Comments

@RoshanAli339
Copy link

RoshanAli339 commented Sep 14, 2023

The m.plot(forecast) or the plot_plotly(m, forecast) functions when executed result in a FutureError the reads as follows

\Lib\site-packages\prophet\plot.py:71: FutureWarning: The behavior of DatetimeProperties.to_pydatetime is deprecated, in a future version this will return a Series containing python datetime objects instead of an ndarray. To retain the old behavior, call np.array on the result
fcst_t = fcst['ds'].dt.to_pydatetime()

venv\Lib\site-packages\prophet\plot.py:72: FutureWarning: The behavior of DatetimeProperties.to_pydatetime is deprecated, in a future version this will return a Series containing python datetime objects instead of an ndarray. To retain the old behavior, call np.array on the result
ax.plot(m.history['ds'].dt.to_pydatetime(), m.history['y'], 'k.',

If there is any way to get through this, please help me or please make necessary changes to resolve this error.

@suhaanibatra
Copy link

Facing the same issue, even if I haven't used the to_pydatetime function.

@kmezhoud
Copy link

kmezhoud commented Nov 2, 2023

Here a prophet example that returns this error message.

/home/.local/lib/python3.10/site-packages/prophet/plot.py:72: FutureWarning: The behavior of DatetimeProperties.to_pydatetime is deprecated, in a future version this will return a Series containing python datetime objects instead of an ndarray. To retain the old behavior, call `np.array` on the result
  fcst_t = fcst['ds'].dt.to_pydatetime()
/home/.local/lib/python3.10/site-packages/prophet/plot.py:73: FutureWarning: The behavior of DatetimeProperties.to_pydatetime is deprecated, in a future version this will return a Series containing python datetime objects instead of an ndarray. To retain the old behavior, call `np.array` on the result
  ax.plot(m.history['ds'].dt.to_pydatetime(), m.history['y'], 'k.',
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')

# Python
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=365)
forecast = m.predict(future)
fig1 = m.plot(forecast)


@kmezhoud
Copy link

kmezhoud commented Nov 2, 2023

You can reproduce the plot with something like this.

plt.scatter(fcast['ds'], fcast['yhat'], color='black', alpha=0.5, s =1)

# Plot the confidence intervals
plt.fill_between(fcast['ds'], 
                            fcast['yhat_lower'],
                             fcast['yhat_upper'],
                               color='blue',
                                alpha=0.05) #, label='Confidence Interval'

# Add labels and legend
plt.xlabel('Date')
plt.ylabel('Value')
#plt.legend()
# Show the plot
plt.show()

@datager
Copy link

datager commented Jan 23, 2024

Facing this issue same:

import pandas as pd
from prophet import Prophet
df = pd.read_csv('example_wp_log_peyton_manning.csv') # https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv'
# df = pd.read_csv('a.csv')
# h = df.head()
# print(h)

m = Prophet()
m.fit(df)

future = m.make_future_dataframe(periods=365)
t = future.tail()
print(t)

forecast = m.predict(future)
r = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
print(r)
fig1 = m.plot(forecast)
# fig2 = m.plot_components(forecast)
fig1.show()
# fig2.show()
/opt/homebrew/lib/python3.11/site-packages/prophet/plot.py:72: FutureWarning: The behavior of DatetimeProperties.to_pydatetime is deprecated, in a future version this will return a Series containing python datetime objects instead of an ndarray. To retain the old behavior, call `np.array` on the result
  fcst_t = fcst['ds'].dt.to_pydatetime()
/opt/homebrew/lib/python3.11/site-packages/prophet/plot.py:73: FutureWarning: The behavior of DatetimeProperties.to_pydatetime is deprecated, in a future version this will return a Series containing python datetime objects instead of an ndarray. To retain the old behavior, call `np.array` on the result
  ax.plot(m.history['ds'].dt.to_pydatetime(), m.history['y'], 'k.',

YuyuZhou1228 added a commit to YuyuZhou1228/prophet that referenced this issue Jul 13, 2024
an extension of facebook#2523, removed remaining instances of the depreciated and unnecessary use of .dt.to_pydatetime()
WardBrian added a commit that referenced this issue Sep 23, 2024
Removed remaining depreciated datetime conversions (#2492)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants