When running fbprophet in combination with Pandas > 20.1.0 , the fit method fails with the error message 'tuple' object has no attribute 'lower'. I've included an example piece of code below to replicate the error, as well as a stack trace. Any help or solution to this issue would be appreciated.
Stack Trace:
fbprophet version: 0.3
pandas version: 0.23.4
Traceback (most recent call last):
File "failfbprophet.py", line 21, in <module>
m.fit(df)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fbprophet/forecaster.py", line 936, in fit
self.history_dates = pd.to_datetime(df['ds']).sort_values()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/tools/datetimes.py", line 454, in to_datetime
result = _assemble_from_unit_mappings(arg, errors=errors)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/tools/datetimes.py", line 533, in _assemble_from_unit_mappings
unit = {k: f(k) for k in arg.keys()}
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/tools/datetimes.py", line 533, in <dictcomp>
unit = {k: f(k) for k in arg.keys()}
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/core/tools/datetimes.py", line 528, in f
if value.lower() in _unit_map:
AttributeError: 'tuple' object has no attribute 'lower'
Code:
````
import pandas as pd
from fbprophet import Prophet
import fbprophet
import numpy.random as rand
rand.seed(0)
print("fbprophet version: ",fbprophet.__version__)
print("pandas version: ",pd.__version__)
datelist = pd.date_range(end=pd.datetime.today(), periods=365, normalize=True).tolist()
basedf = pd.DataFrame(datelist)
basedf.columns= ['DataDate']
basedf['DataDate'] = basedf['DataDate'].dt.strftime('%m/%d/%Y')
basedf['randNumCol'] = rand.randint(0, 2000, basedf.shape[0])
df = basedf.copy(deep = True)
df.columns = [['ds','y']]
m = Prophet() #This is where the code breaks
m.fit(df)
future = m.make_future_dataframe(periods = 90)
fbforecast = m.predict(future)
fbforecast = fbforecast.iloc[-90:]
fb_preds = fbforecast[['ds','yhat']]
fb_preds.columns = [['DataDate', 'Predicted_Value']]
fb_preds = fb_preds.reset_index(drop = True)
````
Just replicated this one on OS X, same versions of the packages. Looks like we'll have to ship another Python release.
It's happening in pd.to_datetime but it's in a pretty in-the-weeds part of the implementation.
Ok upon further review, this is not a bug. You've changed the columns here:
df.columns = [['ds','y']]
>>> df.columns
MultiIndex(levels=[['ds', 'y']],
labels=[[0, 1]])
Should be:
>>> df.columns = ['ds','y']
>>> df.columns
Index(['ds', 'y'], dtype='object')
Most helpful comment
Ok upon further review, this is not a bug. You've changed the columns here:
Should be: