Repository: statsmodels/statsmodels

Issue:
BUG: pandas Series in cov_kwds raises exception
There seems to be a `np.asarray` missing in the cov_kwds handling for `hac-panel`

example from #3604

```
>>> print(smf.ols('y ~ x + C(id)*x', data).fit(cov_type='hac-panel', cov_kwds={'groups':data['id'], 'maxlags':10}).summary())

    tt = (np.nonzero(groups[:-1] != groups[1:])[0] + 1).tolist()
  File "...\WinPython-64bit-3.4.4.5Qt5\python-3.4.4.amd64\lib\site-packages\pandas\core\ops.py", line 812, in wrapper
  File "...\statsmodels\regression\linear_model.py", line 228, in fit
    cov_type=cov_type, cov_kwds=cov_kwds, use_t=use_t)
  File "...\statsmodels\regression\linear_model.py", line 1398, in __init__
    use_t=use_t, **cov_kwds)
  File "...\statsmodels\regression\linear_model.py", line 2181, in get_robustcov_results
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    raise ValueError(msg)
ValueError: Can only compare identically-labeled Series objects
```

using ndarray `.values` works:
```
>>> print(smf.ols('y ~ x + C(id)*x', data).fit(cov_type='hac-panel', cov_kwds={'groups':data['id'].values, 'maxlags':10}).summary())
```




Discussion:

Resolving patch:
diff --git a/statsmodels/base/covtype.py b/statsmodels/base/covtype.py
--- a/statsmodels/base/covtype.py
+++ b/statsmodels/base/covtype.py
@@ -248,10 +248,12 @@ def get_robustcov_results(self, cov_type='HC1', use_t=None, **kwds):
         res.cov_kwds['weights_func'] = weights_func
         # TODO: clumsy time index in cov_nw_panel
         if groups is not None:
+            groups = np.asarray(groups)
             tt = (np.nonzero(groups[:-1] != groups[1:])[0] + 1).tolist()
             nobs_ = len(groups)
         elif time is not None:
             # TODO: clumsy time index in cov_nw_panel
+            time = np.asarray(time)
             tt = (np.nonzero(time[1:] < time[:-1])[0] + 1).tolist()
             nobs_ = len(time)
         else:
diff --git a/statsmodels/regression/linear_model.py b/statsmodels/regression/linear_model.py
--- a/statsmodels/regression/linear_model.py
+++ b/statsmodels/regression/linear_model.py
@@ -2240,9 +2240,11 @@ def get_robustcov_results(self, cov_type='HC1', use_t=None, **kwds):
             weights_func = kwds.get('weights_func', sw.weights_bartlett)
             res.cov_kwds['weights_func'] = weights_func
             if groups is not None:
+                groups = np.asarray(groups)
                 tt = (np.nonzero(groups[:-1] != groups[1:])[0] + 1).tolist()
                 nobs_ = len(groups)
             elif time is not None:
+                time = np.asarray(time)
                 # TODO: clumsy time index in cov_nw_panel
                 tt = (np.nonzero(time[1:] < time[:-1])[0] + 1).tolist()
                 nobs_ = len(time)


Test patch:
diff --git a/statsmodels/discrete/tests/test_sandwich_cov.py b/statsmodels/discrete/tests/test_sandwich_cov.py
--- a/statsmodels/discrete/tests/test_sandwich_cov.py
+++ b/statsmodels/discrete/tests/test_sandwich_cov.py
@@ -647,7 +647,7 @@ def setup_class(cls):
         # time index is just made up to have a test case
         groups = np.repeat(np.arange(5), 7)[:-1]
         mod1 = GLM(endog.copy(), exog.copy(), family=families.Gaussian())
-        kwds = dict(groups=groups,
+        kwds = dict(groups=pd.Series(groups),  # check for #3606
                     maxlags=2,
                     kernel=sw.weights_uniform,
                     use_correction='hac',
@@ -666,7 +666,7 @@ def setup_class(cls):
         # time index is just made up to have a test case
         time = np.tile(np.arange(7), 5)[:-1]
         mod1 = GLM(endog, exog, family=families.Gaussian())
-        kwds = dict(time=time,
+        kwds = dict(time=pd.Series(time),  # check for #3606
                     maxlags=2,
                     use_correction='hac',
                     df_correction=False)