Repository: statsmodels/statsmodels

Issue:
ValueError: Buffer dtype mismatch, expected 'double' but got 'long'
Issue Description

I'm using models from statsmodels.tsa to do time series analysis and I ran into issue of : ValueError: Buffer dtype mismatch, expected 'double' but got 'long'.

Environment:
MacOS 10.14.5
Anaconda
Syper 3.3.5
Python 3.7.2
statsmodels 0.10.0

Code:

```
import pandas as pd
import numpy as np
from sklearn.metrics import mean_squared_error
from math import sqrt
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
import matplotlib.pylab as plt
import matplotlib.dates as mdates

df = pd.read_csv('data.csv')

dateparse = lambda dates: pd.datetime.strptime(dates, '%Y-%m-%d')
df = pd.read_csv('data.csv', 
                   parse_dates=['Month'], 
                   index_col='Month',
                   date_parser=dateparse)

df = df.sort_index(axis = 0, ascending=True)

train_rev = df['Revenue'].values[:33]
train_index = pd.date_range('2016-07-01', periods = 33, freq = 'MS')
train = pd.Series(train_rev, train_index)

test_rev = df['Revenue'].values[33:]
test_index = pd.date_range('2019-04-01', periods = 3, freq = 'MS')
test = pd.Series(test_rev, test_index)

ses = SimpleExpSmoothing(train)
ses = ses.fit()

```

Its giving me this ValueError every time I run the code. To test, I have copied codes from time series analysis tutorials of statsmodels (link: https://www.statsmodels.org/dev/examples/notebooks/generated/exponential_smoothing.html). I can successfully get the final result without any errors. But when I run my code. Its giving me the error.

Would love to know how to fix the issue?
Thanks for your time and help.


Discussion:
You should explicitly cast your data to `double`, as in `train = train.astype('double`)`

Resolving patch:
diff --git a/statsmodels/tsa/holtwinters.py b/statsmodels/tsa/holtwinters.py
--- a/statsmodels/tsa/holtwinters.py
+++ b/statsmodels/tsa/holtwinters.py
@@ -484,6 +484,7 @@ def __init__(self, endog, trend=None, damped=False, seasonal=None,
                  seasonal_periods=None, dates=None, freq=None, missing='none'):
         super(ExponentialSmoothing, self).__init__(endog, None, dates,
                                                    freq, missing=missing)
+        self.endog = self.endog.astype(np.double)
         if trend in ['additive', 'multiplicative']:
             trend = {'additive': 'add', 'multiplicative': 'mul'}[trend]
         self.trend = trend
@@ -633,7 +634,7 @@ def fit(self, smoothing_level=None, smoothing_slope=None, smoothing_seasonal=Non
             y = data.squeeze()
         if np.ndim(y) != 1:
             raise ValueError('Only 1 dimensional data supported')
-        self._y = y
+        self._y = y = np.ascontiguousarray(y, dtype=np.double)
         lvls = np.zeros(self.nobs)
         b = np.zeros(self.nobs)
         s = np.zeros(self.nobs + m - 1)


Test patch:
diff --git a/statsmodels/tsa/tests/test_holtwinters.py b/statsmodels/tsa/tests/test_holtwinters.py
--- a/statsmodels/tsa/tests/test_holtwinters.py
+++ b/statsmodels/tsa/tests/test_holtwinters.py
@@ -505,3 +505,13 @@ def test_direct_holt_add():
     assert_allclose(b, res.slope)
     assert_allclose(f, res.level.iloc[-1] + res.slope.iloc[-1] * np.array([1, 2, 3, 4, 5]))
     assert_allclose(f, res.forecast(5))
+
+
+def test_integer_array(reset_randomstate):
+    rs = np.random.RandomState(12345)
+    e = 10*rs.standard_normal((1000,2))
+    y_star = np.cumsum(e[:,0])
+    y = y_star + e[:,1]
+    y = y.astype(np.long)
+    res = ExponentialSmoothing(y,trend='add').fit()
+    assert res.params['smoothing_level'] != 0.0