Prophet: python fit throws error

Created on 2 Mar 2017  路  9Comments  路  Source: facebook/prophet

When performing Prophet.fit(df), i get following error

AttributeError: 'numpy.timedelta64' object has no attribute 'days'

error can be attributed to below given operation present in fbprophet/forecaster.py in method fourier_series()

t = np.array((dates - pd.datetime(1970, 1, 1)) .apply(lambda x: x.days) .astype(np.float))

as per my understanding we are trying to get the number of days since 1st Jan 1970 to current date. In this case it's apply(lambda x: x.days) which is causing this problem as numpy.timedelta64 class has no days attribute. Changing above operation to below and using pandas inbuilt function solves the problem

t = np.array((dates - pd.datetime(1970, 1, 1)) .dt.days .astype(np.float))

I wanted to report a bug fix but did not know how to do it.

Platform information
Linux - 2.6.32-431.23.3.el6.x86_64 (ab obtained by uname -r)
python=2.7.1
anaconda=2.7.1
since, fbprophet has been installed in a conda environment, all its dependencies has been statisfied

bug py

All 9 comments

Hi @datafool ,
I met the same problem with you, environment python 2.7 and anaconda 2.2. I solved it by upgrading pandas from version 0.17.1 to 0.19.2.
I think you can upgrade pandas to the newest version by python -m pip install --upgrade pandas and the original code should work.

Hi @abuccts thanks! yes upgrade to newest version works fine. I think requirement of latest version of pandas should go in setup.py so that pandas is upgraded automatically, rather than we facing the problem and then updating it

I agree with you. Either changing pandas.Series.apply to pandas.Series.dt.days or adding a minimum pandas version will fix this issue.

I can make a PR for this. But which solution will be better?

I will go with pandas.Series.dt.days, as this is pandas inbuilt so all the heavy lifting will happen at the same place, unlike apply, and as per my understanding apply would be slower than internal pandas functions

That's right. pandas.Series.dt.days is more efficient, but is unavailable in some old versions of pandas, I have no idea about the minimum version.

I checked the pandas documentation back till 0.15, pandas.Series.dt.days is available from 0.16 onward. Also, 0.16 came back in June 2015, chances are everyone might have shifted to a higher version.

Thanks for diagnosing and fixing this! Will merge the PR soon.

Nice ! I met same problem today.

The problem is still there. Using pandas 0.20.1 (also tested on pandas 0.19.2) and fbprphet 0.1.1.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xiaoyaoyang picture xiaoyaoyang  路  3Comments

andmib picture andmib  路  3Comments

germayneng picture germayneng  路  3Comments

GretaShi3084 picture GretaShi3084  路  3Comments

andrew-pollock picture andrew-pollock  路  3Comments