plotly / plotly_express

Plotly Express - Simple syntax for complex charts. Now integrated into plotly.py!
https://plot.ly/python/plotly-express/
MIT License
4 stars 0 forks source link

FutureWarning: Method .ptp is deprecated and will be removed in a future version. Use numpy.ptp instead. #95

Closed huaji1992 closed 4 years ago

nicolaskruchten commented 5 years ago

Can you provide any context on when this warning appears?

huaji1992 commented 5 years ago

iris = px.data.iris() import plotly_express as px tips = px.data.tips() gapminder = px.data.gapminder() election = px.data.election() wind = px.data.wind() carshare = px.data.carshare() px.scatter(tips, x="total_bill", y="tip", facet_row="time", facet_col="day", color="smoker", trendline="ols", category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})

nicolaskruchten commented 5 years ago

Hmm ok. can you tell me which versions of Python, pandas and numpy you're using?

MLDERES commented 5 years ago

I'm getting the error using version 1.16.4 of numpy and 3.7.3 of python In [78]: sys.version Out[78]: '3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 22:01:29) [MSC v.1900 64 bit (AMD64)]'

mrazam110 commented 4 years ago

Any help?

nicolaskruchten commented 4 years ago

@emmanuelle can you take a look at this one please? We see this warning sometimes depending on the version of statsmodels and numpy... it would be good to just figure out which recent versions of these dependencies avoid these issues...

harupy commented 4 years ago

FYI https://github.com/statsmodels/statsmodels/commit/18dcceefbfed61b0d11ae5884a9f4cea82c2edb5

harupy commented 4 years ago

pandas (>= 0.24.0) raises this warning. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.ptp.html

harupy commented 4 years ago

I think using pandas (>= 0.24.0) and statsmodels (<= 0.9.0) causes this warning.

EDIT: I was able to reproduce this warning with pandas 0.24.0 and statsmodels 0.9.0.

EDIT: It turns out I was wrong. statsmodels version doesn't matter.

harupy commented 4 years ago

We can also reproduce the warning like this:

import numpy as np
import pandas as pd

s = pd.Series([0])
np.ptp(s)

This is because np.ptp(s) calls s.ptp. https://github.com/numpy/numpy/blob/v1.17.0/numpy/core/fromnumeric.py#L2430-L2496

harupy commented 4 years ago

It seems this line causes the warning. https://github.com/statsmodels/statsmodels/blob/e2d768ae8da848dc46f63fae3059c5c4139007e0/statsmodels/tsa/tsatools.py#L103

harupy commented 4 years ago

One way to avoid the warning is convert a pandas series to a numpy array like below (I haven't tested yet but it should work):

- fit_results = sm.OLS(y, sm.add_constant(x)).fit()
+ fit_results = sm.OLS(y, sm.add_constant(x.values)).fit()

https://github.com/plotly/plotly.py/blob/4a30dc66230269aad008650544dd1045a40b1896/packages/python/plotly/plotly/express/_core.py#L236

nicolaskruchten commented 4 years ago

Ah, thanks for all the detective work @harupy ! Indeed just adding .values there makes the warning go away :) I'll patch it tonight.

harupy commented 4 years ago

@nicolaskruchten You're welcome!

trishattah commented 4 years ago

thanks so much @harupy yes this works much appreciated. thank you @nicolaskruchten for asking this question

avichaljha commented 4 years ago

This was bothering me to no end on a variable assignment. As someone new to Python, it was quite discouraging as I though I was doing something wrong. @harupy , thanks for your help - you just saved me from despair! hontou ni arigatou gozaimashita!