internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: statsmodels/statsmodels

Issue:
broken example, pandas
sphinx build creates this warning, 

> > > import pandas
> > > pandas.**version**
> > > '0.8.0.dev-3cd1b05'
> > > np.**version**
> > > '1.5.1'

```
Not generating reST from E:\...\statsmodels\examples\example_interactions.py. An error occurred.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "E:\...\statsmodels\examples\example_interactions.py", line 129, in <module>
    idx = salary_table.index.drop(drop_idx)
  File "e:\...\pandas\pandas\core\index.py", line 878,
in drop
    labels = np.asarray(list(labels), dtype=object)
TypeError: 'numpy.int32' object is not iterable
```



Discussion:

Resolving patch:
diff --git a/examples/example_interactions.py b/examples/example_interactions.py
--- a/examples/example_interactions.py
+++ b/examples/example_interactions.py
@@ -126,7 +126,7 @@
 
 drop_idx = abs(resid).argmax()
 print drop_idx # zero-based index
-idx = salary_table.index.drop(drop_idx)
+idx = salary_table.index.drop([drop_idx])
 
 lm32 = ols('S ~ C(E) + X + C(M)', df=salary_table, subset=idx).fit()
 
@@ -196,6 +196,8 @@
     minority_table = pandas.read_table('minority.table')
 except: # don't have data already
     url = 'http://stats191.stanford.edu/data/minority.table'
+    #the next line is not necessary with recent version of pandas
+    url = urlopen(url)
     minority_table = pandas.read_table(url)
 
 factor_group = minority_table.groupby(['ETHN'])
@@ -293,6 +295,8 @@
     rehab_table = pandas.read_csv('rehab.table')
 except:
     url = 'http://stats191.stanford.edu/data/rehab.csv'
+    #the next line is not necessary with recent version of pandas
+    url = urlopen(url)
     rehab_table = pandas.read_table(url, delimiter=",")
     rehab_table.to_csv('rehab.table')
 
@@ -315,6 +319,8 @@
     kidney_table = pandas.read_table('./kidney.table')
 except:
     url = 'http://stats191.stanford.edu/data/kidney.table'
+    #the next line is not necessary with recent version of pandas
+    url = urlopen(url)
     kidney_table = pandas.read_table(url, delimiter=" *")
 
 # Explore the dataset
diff --git a/statsmodels/graphics/regressionplots.py b/statsmodels/graphics/regressionplots.py
--- a/statsmodels/graphics/regressionplots.py
+++ b/statsmodels/graphics/regressionplots.py
@@ -299,6 +299,12 @@ def plot_partregress(results, exog_idx=None, xnames=None, grid=None, fig=None):
         plot_partregress_ax(y, exog[:, idx], exog_others, ax=ax,
                                varname=xnames[i])
 
+    import matplotlib as mpl
+    if mpl.__version__ >= '1.1':
+        # The tight_layout feature is not available before version 1.1
+        # It automatically pads the figure so labels do not get clipped.
+        fig.tight_layout()
+
     return fig
 
 


Test patch:
Repository: statsmodels/statsmodels

Issue:
arima predict is broken for steps > q and q != 1
There's no test case for this apparently 

```
inv = sm.datasets.macrodata.load().data['realinv']
arima_mod = sm.tsa.ARIMA(np.log(inv), (1,1,2)).fit(start_params=[0,0,0,0])
arima_mod.forecast(4)
```



Discussion:

Resolving patch:
diff --git a/statsmodels/tsa/arima_model.py b/statsmodels/tsa/arima_model.py
--- a/statsmodels/tsa/arima_model.py
+++ b/statsmodels/tsa/arima_model.py
@@ -124,7 +124,7 @@ def _arma_predict_out_of_sample(params, steps, errors, p, q, k_trend, k_exog,
 
     for i in range(min(q,steps-1)):
         fcast = mu[i] + np.dot(arparams,endog[i:i+p]) + \
-                      np.dot(maparams,resid[i:i+q])
+                np.dot(maparams[:q-i],resid[i:i+q])
         forecast[i] = fcast
         endog[i+p] = fcast
 


Test patch:
diff --git a/statsmodels/tsa/tests/test_arima.py b/statsmodels/tsa/tests/test_arima.py
--- a/statsmodels/tsa/tests/test_arima.py
+++ b/statsmodels/tsa/tests/test_arima.py
@@ -1577,13 +1577,26 @@ def test_1dexog():
     exog = dta['m1'].values.squeeze()
     mod = ARMA(endog, (1,1), exog).fit(disp=-1)
 
-def arima_predict_bug():
+def test_arima_predict_bug():
     #predict_start_date wasn't getting set on start = None
-    dta = sm.datasets.sunspots.load_pandas().data
-    dta.index = pandas.Index(sm.tsa.datetools.dates_from_range('1700', '2008'))
-    arma_mod20 = sm.tsa.ARMA(dta, (2,0)).fit(disp=-1)
+    from statsmodels.datasets import sunspots
+    dta = sunspots.load_pandas().data.SUNACTIVITY
+    dta.index = pandas.Index(dates_from_range('1700', '2008'))
+    arma_mod20 = ARMA(dta, (2,0)).fit(disp=-1)
     arma_mod20.predict(None, None)
 
+def test_arima_predict_q2():
+    # bug with q > 1 for arima predict
+    from statsmodels.datasets import macrodata
+    inv = macrodata.load().data['realinv']
+    arima_mod = ARIMA(np.log(inv), (1,1,2)).fit(start_params=[0,0,0,0], disp=-1)
+    fc, stderr, conf_int = arima_mod.forecast(5)
+    # values copy-pasted from gretl
+    assert_almost_equal(fc,
+                        [7.306320, 7.313825, 7.321749, 7.329827, 7.337962],
+                        5)
+
+
 if __name__ == "__main__":
     import nose
     nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb'], exit=False)
Repository: statsmodels/statsmodels

Issue:
tsa models assume pandas object indices are dates
Even when they're not. Clarify and document this or add better checks.

https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/base/tsa_model.py#L42



Discussion:
Hmm, not quite sure what to do here. I'm thinking now to fail with a better warning message. If we're given a pandas object, it's going to have row_labels and everything for the wrappers even if we detect that they're not dates and carry on, so it's going to try and impute dates for out of sample prediction, so this will still fail just later. 


Resolving patch:
diff --git a/statsmodels/tsa/base/tsa_model.py b/statsmodels/tsa/base/tsa_model.py
--- a/statsmodels/tsa/base/tsa_model.py
+++ b/statsmodels/tsa/base/tsa_model.py
@@ -52,6 +52,10 @@ def _init_dates(self, dates, freq):
             dates = self._data.row_labels
 
         if dates is not None:
+            if (not isinstance(dates[0], datetime.datetime) and
+                    isinstance(self._data, data.PandasData)):
+                raise ValueError("Given a pandas object and the index does "
+                                 "not contain dates")
             if not freq:
                 try:
                     freq = datetools._infer_freq(dates)


Test patch:
diff --git a/statsmodels/tsa/base/tests/test_base.py b/statsmodels/tsa/base/tests/test_base.py
new file mode 100644
--- /dev/null
+++ b/statsmodels/tsa/base/tests/test_base.py
@@ -0,0 +1,8 @@
+from pandas import Series
+from statsmodels.tsa.base.tsa_model import TimeSeriesModel
+import numpy.testing as npt
+
+def test_pandas_nodates_index():
+    from statsmodels.datasets import sunspots
+    y = sunspots.load_pandas().data.SUNACTIVITY
+    npt.assert_raises(ValueError, TimeSeriesModel, y)
Repository: statsmodels/statsmodels

Issue:
Avoid cholesky decomposition of diagonal matrices in linear regression models
We needlessly take the cholesky decomposition of pinv(sigma) even in cases where we know sigma is diagonal. This could be avoided.



Discussion:

Resolving patch:
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
@@ -53,16 +53,18 @@ def _get_sigma(sigma, nobs):
     if sigma is None:
         return None, None
     sigma = np.asarray(sigma).squeeze()
+    if sigma.ndim == 0:
+        sigma = np.repeat(sigma, nobs)
     if sigma.ndim == 1:
+        cholsigmainv = np.diag(1/sigma**.5)
         sigma = np.diag(sigma)
-    elif sigma.ndim == 0:
-        sigma = np.diag([sigma] * nobs)
+    else:
+        cholsigmainv = np.linalg.cholesky(np.linalg.pinv(sigma)).T
 
     if sigma.shape != (nobs, nobs):
         raise ValueError("Sigma must be a scalar, 1d of length %s or a 2d "
                         "array of shape %s x %s" % (nobs, nobs))
 
-    cholsigmainv = np.linalg.cholesky(np.linalg.pinv(sigma)).T
     return sigma, cholsigmainv
 
 class RegressionModel(base.LikelihoodModel):


Test patch:
Repository: statsmodels/statsmodels

Issue:
Definition in macrodata NOTE
I think real DPI is probably disposable income not investment as the note says.



Discussion:

Resolving patch:
diff --git a/statsmodels/datasets/macrodata/data.py b/statsmodels/datasets/macrodata/data.py
--- a/statsmodels/datasets/macrodata/data.py
+++ b/statsmodels/datasets/macrodata/data.py
@@ -39,7 +39,7 @@
                 US$, seasonally adjusted annual rate)
     realgovt  - Real federal consumption expenditures & gross investment
                 (Bil. of chained 2005 US$, seasonally adjusted annual rate)
-    realdpi   - Real gross private domestic investment (Bil. of chained 2005
+    realdpi   - Real private disposable income (Bil. of chained 2005
                 US$, seasonally adjusted annual rate)
     cpi       - End of the quarter consumer price index for all urban
                 consumers: all items (1982-84 = 100, seasonally adjusted).


Test patch:
Repository: statsmodels/statsmodels

Issue:
PatsyData detection buglet
If exog is None, then is_using_patsy data utility function returns False. It's a quick fix, but I'm starting to use patsy a bit more internally for convenience (e.g., passing in names to plotting functions rather than having to pull out the data) so I'll make a ticket.



Discussion:

Resolving patch:
diff --git a/statsmodels/tools/data.py b/statsmodels/tools/data.py
--- a/statsmodels/tools/data.py
+++ b/statsmodels/tools/data.py
@@ -122,5 +122,6 @@ def _is_array_like(endog, exog):
 
 def _is_using_patsy(endog, exog):
     # we get this when a structured array is passed through a formula
-    return is_design_matrix(endog) and is_design_matrix(exog)
+    return (is_design_matrix(endog) and
+            (is_design_matrix(exog) or exog is None))
 


Test patch:
diff --git a/statsmodels/tools/tests/test_data.py b/statsmodels/tools/tests/test_data.py
--- a/statsmodels/tools/tests/test_data.py
+++ b/statsmodels/tools/tests/test_data.py
@@ -39,3 +39,13 @@ def test_dataframe():
     np.testing.assert_equal(vals, df.values)
     np.testing.assert_equal(rnames.tolist(), df.index.tolist())
     np.testing.assert_equal(cnames, df.columns.tolist())
+
+def test_patsy_577():
+    X = np.random.random((10, 2))
+    df = pandas.DataFrame(X, columns=["var1", "var2"])
+    from patsy import dmatrix
+    endog = dmatrix("var1 - 1", df)
+    np.testing.assert_(data._is_using_patsy(endog, None))
+    exog = dmatrix("var2 - 1", df)
+    np.testing.assert_(data._is_using_patsy(endog, exog))
+
Repository: statsmodels/statsmodels

Issue:
Test Baxter King band-pass filter fails with scipy 0.12 beta1
current git head 1b12824f53b1 and 0.4.3, python2.7 tested on ubuntu 13.04 amd64, haven't tried scipy 0.11 but it the test seems to work with the 0.10.1 package

```
======================================================================
ERROR: Test Baxter King band-pass filter. Results are taken from Stata
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/statsmodels/statsmodels/tsa/filters/tests/test_filters.py", line 47, in test_bking1d
    Y = bkfilter(X, 6, 32, 12)
  File "/statsmodels/statsmodels/tsa/filters/bk_filter.py", line 72, in bkfilter
    return fftconvolve(bweights, X, mode='valid') # get a centered moving avg/
  File "/usr/lib/python2.7/dist-packages/scipy/signal/signaltools.py", line 204, in fftconvolve
    _check_valid_mode_shapes(s1, s2)
  File "/usr/lib/python2.7/dist-packages/scipy/signal/signaltools.py", line 64, in _check_valid_mode_shapes
    "in1 should have at least as many items as in2 in "
ValueError: in1 should have at least as many items as in2 in every dimension for 'valid' mode.

----------------------------------------------------------------------
```



Discussion:
Thanks for the report. Odd. I don't see this with a very recent 0.12.0 dev build (should be later than the signaltools change). I'll look into it.

[_Edit:_ Yeah, I see it now. Looks like this changed last week.]


Resolving patch:
diff --git a/statsmodels/tsa/filters/bk_filter.py b/statsmodels/tsa/filters/bk_filter.py
--- a/statsmodels/tsa/filters/bk_filter.py
+++ b/statsmodels/tsa/filters/bk_filter.py
@@ -69,5 +69,5 @@ def bkfilter(X, low=6, high=32, K=12):
     bweights -= bweights.mean() # make sure weights sum to zero
     if X.ndim == 2:
         bweights = bweights[:,None]
-    return fftconvolve(bweights, X, mode='valid') # get a centered moving avg/
+    return fftconvolve(X, bweights, mode='valid') # get a centered moving avg/
                                                   # convolution


Test patch:
Repository: statsmodels/statsmodels

Issue:
Unable to run AR on named time series objects
I am running Python 2.7 and statsmodels 0.4.3. I am unable to perform time series analysis on named time series objects, but I am able to run the same analysis on unnamed time series objects. For example, the following code fails:

``` python
rng = pandas.date_range('1/1/2011', periods=72, freq='M')
ts = pandas.Series(scipy.randn(len(rng)), index=rng)
ts.name = 'FooBar'
model = sm.tsa.AR(ts, freq='M')
result = model.fit(2)
result.params
```

However, removing the name and running the following code succeeds:

``` python
ts.name = None
model = sm.tsa.AR(ts, freq='M')
result = model.fit(2)
result.params
```

Digging in a bit, it seems this has to do with how string names are generated for the lags. With the initial FooBar series name, I see that the index being created is:

``` python
Index([const, L1.F, L1.o, L1.o, L1.B, L1.a, L1.r, L2.F, L2.o, L2.o, L2.B, L2.a, L2.r], dtype=object)
```

The failing line for me is in statsmodels/base/data.py(164)attach_columns():

``` python
return Series(result, index=self.xnames)
```



Discussion:

Resolving patch:
diff --git a/statsmodels/tsa/vector_ar/util.py b/statsmodels/tsa/vector_ar/util.py
--- a/statsmodels/tsa/vector_ar/util.py
+++ b/statsmodels/tsa/vector_ar/util.py
@@ -54,6 +54,8 @@ def make_lag_names(names, lag_order, trendorder=1):
 
     """
     lag_names = []
+    if isinstance(names, basestring): # python 3?
+        names = [names]
 
     # take care of lagged endogenous names
     for i in range(1, lag_order + 1):


Test patch:
diff --git a/statsmodels/tsa/tests/test_ar.py b/statsmodels/tsa/tests/test_ar.py
--- a/statsmodels/tsa/tests/test_ar.py
+++ b/statsmodels/tsa/tests/test_ar.py
@@ -8,6 +8,7 @@
 from results import results_ar
 import numpy as np
 import numpy.testing as npt
+from pandas import Series, Index
 
 DECIMAL_6 = 6
 DECIMAL_5 = 5
@@ -223,7 +224,6 @@ def test_ar_dates():
     # just make sure they work
     data = sm.datasets.sunspots.load()
     dates = sm.tsa.datetools.dates_from_range('1700', length=len(data.endog))
-    from pandas import Series
     endog = Series(data.endog, index=dates)
     ar_model = sm.tsa.AR(endog, freq='A').fit(maxlag=9, method='mle', disp=-1)
     pred = ar_model.predict(start='2005', end='2015')
@@ -236,6 +236,14 @@ def test_ar_dates():
     assert_equal(ar_model.data.predict_dates, predict_dates)
     assert_equal(pred.index, predict_dates)
 
+def test_ar_named_series():
+    dates = sm.tsa.datetools.dates_from_range("2011m1", length=72)
+    y = Series(np.random.randn(72), name="foobar", index=dates)
+    results = sm.tsa.AR(y).fit(2)
+    assert_(results.params.index.equals(Index(["const", "L1.foobar",
+                                               "L2.foobar"])))
+
+
 #TODO: likelihood for ARX model?
 #class TestAutolagARX(object):
 #    def setup(self):
Repository: statsmodels/statsmodels

Issue:
bug, pylint stats.anova
stats/anova.py line 324

```
    if len(args) == 1:
        return anova_lm_single(*args, **kwargs)
```

`anova_lm_single` not defined, I guess it was renamed to `anova1_lm_single`, but there is also a `anova2_lm_single`



Discussion:

Resolving patch:
diff --git a/statsmodels/stats/anova.py b/statsmodels/stats/anova.py
--- a/statsmodels/stats/anova.py
+++ b/statsmodels/stats/anova.py
@@ -321,7 +321,7 @@ def anova_lm(*args, **kwargs):
 
     # if given a single model
     if len(args) == 1:
-        return anova_lm_single(*args, **kwargs)
+        return anova_single(*args, **kwargs)
 
     # received multiple fitted models
 


Test patch:
Repository: statsmodels/statsmodels

Issue:
DiscreteMargins duplicate method
(pylint complains)

statsmodels/discrete/discrete_margins.py line 575
Duplicated signature: get_margeff

the same method was already defined in line 430



Discussion:

Resolving patch:
diff --git a/statsmodels/discrete/discrete_margins.py b/statsmodels/discrete/discrete_margins.py
--- a/statsmodels/discrete/discrete_margins.py
+++ b/statsmodels/discrete/discrete_margins.py
@@ -369,7 +369,6 @@ def __init__(self, results, get_margeff, derivative, dist=None,
         self._cache = resettable_cache()
         self.results = results
         self.dist = dist
-        self._get_margeff = get_margeff
         self.get_margeff(margeff_args)
 
     def _reset(self):
@@ -377,7 +376,7 @@ def _reset(self):
 
     def get_margeff(self, *args, **kwargs):
         self._reset()
-        self.margeff = self._get_margeff(*args)
+        self.margeff = self.get_margeff(*args)
 
     @cache_readonly
     def tvalues(self):
@@ -427,10 +426,6 @@ def __init__(self, results, args, kwargs={}):
     def _reset(self):
         self._cache = resettable_cache()
 
-    def get_margeff(self, *args, **kwargs):
-        self._reset()
-        self.margeff = self._get_margeff(*args, **kwargs)
-
     @cache_readonly
     def tvalues(self):
         _check_at_is_all(self.margeff_options)


Test patch:
Repository: statsmodels/statsmodels

Issue:
AR start_params broken
AR with start_params checks for bool, instead of is `None`

```
>>> res1a = AR(data.endog).fit(maxlag=9, start_params=0.1*np.ones(9.),method="mle", disp=-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-josef_new\statsmodels\tsa\ar_model.py", line 550, in fit
    if not start_params:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
```



Discussion:
style in AR.select_order eval could be replaced by getattr, that's cleaner

results[lag] = eval('fit.'+ic)


Resolving patch:
diff --git a/statsmodels/tsa/ar_model.py b/statsmodels/tsa/ar_model.py
--- a/statsmodels/tsa/ar_model.py
+++ b/statsmodels/tsa/ar_model.py
@@ -567,9 +567,14 @@ def fit(self, maxlag=None, method='cmle', ic=None, trend='c',
             self.sigma2 = arfit.ssr/arfit.nobs #needed for predict fcasterr
         if method == "mle":
             self.nobs = nobs
-            if not start_params:
+            if start_params is None:
                 start_params = OLS(Y,X).fit().params
-                start_params = self._invtransparams(start_params)
+            else:
+                if len(start_params) != k_trend + k_ar:
+                    raise ValueError("Length of start params is %d. There"
+                            " are %d parameters." % (len(start_params),
+                                                     k_trend + k_ar))
+            start_params = self._invtransparams(start_params)
             loglike = lambda params : -self.loglike(params)
             if solver == None:  # use limited memory bfgs
                 bounds = [(None,)*2]*(k_ar+k)


Test patch:
diff --git a/statsmodels/tsa/tests/test_ar.py b/statsmodels/tsa/tests/test_ar.py
--- a/statsmodels/tsa/tests/test_ar.py
+++ b/statsmodels/tsa/tests/test_ar.py
@@ -243,6 +243,13 @@ def test_ar_named_series():
     assert_(results.params.index.equals(Index(["const", "L1.foobar",
                                                "L2.foobar"])))
 
+def test_ar_start_params():
+    # fix 236
+    # smoke test
+    data = sm.datasets.sunspots.load()
+    res = AR(data.endog).fit(maxlag=9, start_params=0.1*np.ones(10.),
+                             method="mle", disp=-1)
+
 
 #TODO: likelihood for ARX model?
 #class TestAutolagARX(object):
Repository: statsmodels/statsmodels

Issue:
Add ANOVA to docs
I'm not sure where it should go. Maybe in stats? Maybe we should rename regression.rst -> linear_model.rst and put it there?



Discussion:

Resolving patch:
diff --git a/statsmodels/stats/anova.py b/statsmodels/stats/anova.py
--- a/statsmodels/stats/anova.py
+++ b/statsmodels/stats/anova.py
@@ -271,13 +271,10 @@ def anova_lm(*args, **kwargs):
     """
     ANOVA table for one or more fitted linear models.
 
-    Parmeters
+    Parameters
     ---------
     args : fitted linear model results instance
         One or more fitted linear models
-
-    **kwargs**
-
     scale : float
         Estimate of variance, If None, will be estimated from the largest
         model. Default is None.
@@ -297,11 +294,27 @@ def anova_lm(*args, **kwargs):
     Notes
     -----
     Model statistics are given in the order of args. Models must have
-    a formula_str attribute.
+    been fit using the formula api.
 
     See Also
     --------
     model_results.compare_f_test, model_results.compare_lm_test
+
+    Example
+    -------
+    >>> import statsmodels.api as sm
+    >>> from statsmodels.formula.api import ols
+
+    >>> moore = sm.datasets.get_rdataset("Moore", "car",
+    ...                                  cache=True) # load data
+    >>> data = moore.data
+    >>> data = data.rename(columns={"partner.status" :
+    ...                             "partner_status"}) # make name pythonic
+    >>> moore_lm = ols('conformity ~ C(fcategory, Sum)*C(partner_status, Sum)',
+    ...                 data=data).fit()
+
+    >>> table = sm.stats.anova_lm(moore_lm, typ=2) # Type 2 ANOVA DataFrame
+    >>> print table
     """
     typ = kwargs.get('typ', 1)
 


Test patch: