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

Issue:
BUG: Non-ASCII character in KPSS docstring
The hyphen in the page numbers (159-178) is a non-ASCII character. This doesn't break on Python 2.x on Travis, but it does on my machine.

```
  File "/Users/fulton/projects/statsmodels/statsmodels/tsa/stattools.py", line 1114
    `Journal of Econometrics` 54, 159–178.
                                          ^
SyntaxError: Non-ASCII character '\xe2' in file .../statsmodels/statsmodels/tsa/stattools.py on line 1115, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
```



Discussion:
@ChadFulton  Can you make the change to ASCII?    (one character PR and merge?)

AFAIK, all my editors default to utf-8, but we should stick with ASCII unless there is a non-ASCII name.
My spyder default header adds `# -*- coding: utf-8 -*-` to new modules, but we never defined or even discussed this in general.

(BTW: try to add github labels to new issues and PRs)

No problem - just wanted to make sure it wasn't something specific to my machine. I still don't fully understand the unicode idiosyncracies of Py2 vs Py3.

Thanks for the reminder about labels - I forgot I could do that.

Copy-pasting non-ASCII and non utf-8 can happen easily when we copy things from another editor like references. I need to change things like forward quotes and hyphens every once in a while. But the original contributor might not realize because everything is in a compatible encoding.

I think python 3 interprets all modules as utf-8 by default, so there shouldn't be a problem with unicode characters. But it's easy to copy-paste the default system encoding, latin-1, cpxxxx. In the past I ran into problems with greek letters in PRs where I didn't know the original encoding which wasn't utf-8.
IIRC, Python 2 falls back to system encoding, which for me was always Windows cp1252 and is, AFAIK, incompatible for special characters with other (Linux) defaults.

Sticking to ASCII avoids the problems, but we don't want to mess up proper names either.
(I find Julia's preference for greek unicode letters "weird", I never remember for most of them how that squiggly things are pronounced nor what the keyboard shortcut would be, except maybe a, b, d, g :)


Resolving patch:
diff --git a/statsmodels/tsa/stattools.py b/statsmodels/tsa/stattools.py
--- a/statsmodels/tsa/stattools.py
+++ b/statsmodels/tsa/stattools.py
@@ -1111,7 +1111,7 @@ def kpss(x, regression='c', lags=None, store=False):
     ----------
     D. Kwiatkowski, P. C. B. Phillips, P. Schmidt, and Y. Shin (1992): Testing
     the Null Hypothesis of Stationarity against the Alternative of a Unit Root.
-    `Journal of Econometrics` 54, 159–178.
+    `Journal of Econometrics` 54, 159-178.
     """
     from warnings import warn
 


Test patch:
Repository: statsmodels/statsmodels

Issue:
BUG adfuller _str missing in ResultsStore
reported by Alan on the mailing list

```
statsmodels\tsa\stattools.pyc in __str__(self)
     23 class ResultsStore(object):
     24     def __str__(self):
---> 25         return self._str  # pylint: disable=E1101

AttributeError: 'ResultsStore' object has no attribute '_str'
```

and 

the attribute names given for the ADF results
http://statsmodels.sourceforge.net/0.6.0/generated/statsmodels.tsa.stattools.adfuller.html
do not match the attribute names in the results store.



Discussion:
I can "fix" this one what the fix means. Why can't ResultsStore be just a Python hash?

> Why can't ResultsStore be just a Python hash?

I like attribute access instead of dictionary access (for autocompletion and less typing), so we use either a simple class or a `Bunch`.

The idea was to get a nice string representation, but the individual hypothesis test need to provide the `_str` attribute, which is missing in 
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/stattools.py#L267

The quickfix is to add a informative `_str`, the longterm solution is to find a common structure for which we have several attempts but haven't settled on a conistent pattern yet.

Often I check Stata, R or SAS printouts to see what is useful information for string representation of results.

Got it. Do you think one of the hacks [here](http://stackoverflow.com/questions/4984647/accessing-dict-keys-like-an-attribute-in-python) will work?

A little help to start @josef-pkt


Resolving patch:
diff --git a/statsmodels/tsa/stattools.py b/statsmodels/tsa/stattools.py
--- a/statsmodels/tsa/stattools.py
+++ b/statsmodels/tsa/stattools.py
@@ -276,6 +276,7 @@ def adfuller(x, maxlag=None, regression="c", autolag='AIC',
                        "unit root")
         resstore.HA = "The coefficient on the lagged level < 1 - stationary"
         resstore.icbest = icbest
+        resstore._str = 'Augmented Dickey-Fuller Test Results'
         return adfstat, pvalue, critvalues, resstore
     else:
         if not autolag:


Test patch:
diff --git a/statsmodels/tsa/tests/test_stattools.py b/statsmodels/tsa/tests/test_stattools.py
--- a/statsmodels/tsa/tests/test_stattools.py
+++ b/statsmodels/tsa/tests/test_stattools.py
@@ -107,6 +107,11 @@ def __init__(self):
         self.pvalue = 0.013747 # Stata does not return a p-value for noconstant
                                # this value is just taken from our results
         self.critvalues = [-2.587,-1.950,-1.617]
+        _, _1, _2, self.store = adfuller(self.y, regression="nc", autolag=None,
+                                         maxlag=1, store=True)
+
+    def test_store_str(self):
+        assert_equal(self.store.__str__(), 'Augmented Dickey-Fuller Test Results')
 
 class CheckCorrGram(object):
     """
Repository: statsmodels/statsmodels

Issue:
In statsmodels.tsa.ar_model.AR.select_order, bestlag may be undefined when ic=='t-stat'
See:

https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/ar_model.py#L444

When `np.abs(fit.tvalues[-1]) >= stop` is false at all lags, python throws an exception `UnboundLocalError: local variable 'bestlag' referenced before assignment` .  We should set a default value for bestlag to act as a fallback.



Discussion:
Based on your description, the default would be zero, which is just OLS, and if I remember correctly should work now as special case.

What should be the answer in this case, exception, warning, no lags or bestlag=1?
Based on reading the other branch (`ic != 't-stat'`) the smallest lag is 1, as far as I can tell.

Instead of defining a default for bestlag, we could also add a `else` to the `for` loop that additionally warns that we use bestlag 1 even though bestlag should be 0.

(Or switch to returning the no lag model ?)

Given that this is in time series analysis, I think a minimum lag of 1 sounds fine, otherwise users might not have any explanatory variables to forecast, except unconditional mean.

So initializing bestlag=1 sounds fine, but the minimum should be mentioned in the "ic" part of the `fit` docstring.

@121onto  Thanks for reporting this. Do you want to make a PR?

@josef-pkt I would like to make a PR . What i understood is that we need to add bestlag=1 in the else part to the for loop but i did not get the reason ??


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
@@ -448,6 +448,7 @@ def select_order(self, maxlag, ic, trend='c', method='mle'):
                                         full_output=0, trend=trend,
                                         maxiter=35, disp=-1)
 
+                bestlag = 0
                 if np.abs(fit.tvalues[-1]) >= stop:
                     bestlag = lag
                     break


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
@@ -303,6 +303,20 @@ def test_ar_select_order():
     res = ar.select_order(maxlag=12, ic='aic')
     assert_(res == 2)
 
+# GH 2658
+def test_ar_select_order_tstat():
+    rs = np.random.RandomState(123)
+    tau = 25
+    y = rs.randn(tau)
+    ts = Series(y, index=DatetimeIndex(start='1/1/1990', periods=tau,
+                                   freq='M'))
+
+    ar = AR(ts)
+    res = ar.select_order(maxlag=5, ic='t-stat')
+    assert_equal(res, 0)
+
+
+
 #TODO: likelihood for ARX model?
 #class TestAutolagARX(object):
 #    def setup(self):
Repository: statsmodels/statsmodels

Issue:
BLD/DOC: See also error
Error with one of the attributes of the `Family` class of `statsmodels.genmod.families.family.py`. The docstring is:

``` python
"""
The Anscombe residuals.

See also
--------
statsmodels.genmod.families.family.Family docstring and the
`resid_anscombe` for the individual families for more information.
"""
```

I guess the line-break is causing Sphinx to try and interpret the second line as a new See Also item.

The error is:

```
building [html]: targets for 64 source files that are out of date
updating environment: 2962 added, 0 changed, 0 removed
reading sources... [ 16%] generated/statsmodels.duration.hazard_regression.PHRegResults.baseline_cumulative_hazard_functreading sources... [ 20%] generated/statsmodels.genmod.families.family.Family                                           
Exception occurred:
  File "/Users/.../.virtualenvs/default/lib/python2.7/site-packages/numpydoc/docscrape.py", line 211, in parse_item_name
    raise ValueError("%s is not a item name" % text)
ValueError: `resid_anscombe` for the individual families for more information. is not a item name
The full traceback has been saved in /var/folders/vx/x4l96f_n1hvdpzq1bqzcx9xw0000gn/T/sphinx-err-kutxkc.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [html] Error 1
```

This can be fixed with:

``` python
"""
The Anscombe residuals.

See also
--------
statsmodels.genmod.families.family.Family
    docstring and the `resid_anscombe` for the individual families for
    more information.
"""
```

@bashtage I see you did some work on these See Also lines, does this sound reasonable to you?



Discussion:

Resolving patch:
diff --git a/statsmodels/genmod/families/family.py b/statsmodels/genmod/families/family.py
--- a/statsmodels/genmod/families/family.py
+++ b/statsmodels/genmod/families/family.py
@@ -253,12 +253,12 @@ def loglike(self, endog, mu, freq_weights=1., scale=1.):
 
     def resid_anscombe(self, endog, mu):
         """
-        The Anscombe residuals.
+        The Anscombe residuals
 
-        See also
+        See Also
         --------
-        statsmodels.genmod.families.family.Family docstring and the
-        `resid_anscombe` for the individual families for more information.
+        statsmodels.genmod.families.family.Family : `resid_anscombe` for the
+          individual families for more information
         """
         raise NotImplementedError
 


Test patch:
Repository: statsmodels/statsmodels

Issue:
Jarque-Bera does not include null in the docstring
Consider closing as part of #1182.



Discussion:
Punting on this since we can never make decisions.


Resolving patch:
diff --git a/statsmodels/stats/stattools.py b/statsmodels/stats/stattools.py
--- a/statsmodels/stats/stattools.py
+++ b/statsmodels/stats/stattools.py
@@ -76,27 +76,44 @@ def omni_normtest(resids, axis=0):
 
 
 def jarque_bera(resids, axis=0):
-    """
-    Calculate residual skewness, kurtosis, and do the JB test for normality
+    r"""
+    Calculates the Jarque-Bera test for normality
 
     Parameters
     -----------
-    resids : array-like
+    data : array-like
+        Data to test for normality
     axis : int, optional
-        Default is 0
+        Axis to use if data has more than 1 dimension. Default is 0
 
     Returns
     -------
-    JB, JBpv, skew, kurtosis
+    JB : float or array
+        The Jarque-Bera test statistic
+    JBpv : float or array
+        The pvalue of the test statistic
+    skew : float or array
+        Estimated skewness of the data
+    kurtosis : float or array
+        Estimated kurtosis of the data
+
+    Notes
+    -----
+    Each output returned has 1 dimension fewer than data
 
-    JB = n/6*(S^2 + (K-3)^2/4)
 
-    JBpv is the Chi^2 two-tail probability value
+    The Jarque-Bera test statistic tests the null that the data is normally
+    distributed against an alternative that the data follow some other
+    distribution. The test statistic is based on two moments of the data,
+    the skewness, and the kurtosis, and has an asymptotic :math:`\chi^2_2`
+    distribution.
 
-    skew is the measure of skewness
+    The test statistic is defined
 
-    kurtosis is the measure of kurtosis
+    .. math:: JB = n(S^2/6+(K-3)^2/24)
 
+    where n is the number of data points, S is the sample skewness, and K is
+    the sample kurtosis of the data.
     """
     resids = np.asarray(resids)
     # Calculate residual skewness and kurtosis
@@ -105,7 +122,7 @@ def jarque_bera(resids, axis=0):
 
     # Calculate the Jarque-Bera test for normality
     n = resids.shape[axis]
-    jb = (n / 6.) * (skew**2 + (1 / 4.) * (kurtosis - 3)**2)
+    jb = (n / 6.) * (skew ** 2 + (1 / 4.) * (kurtosis - 3) ** 2)
     jb_pv = stats.chi2.sf(jb, 2)
 
     return jb, jb_pv, skew, kurtosis


Test patch:
Repository: statsmodels/statsmodels

Issue:
test_markov_regression numpy deprecation warning
I just saw this in https://travis-ci.org/statsmodels/statsmodels/jobs/140853476

```
statsmodels.tsa.regime_switching.tests.test_markov_regression.TestAreturnsConstL1Variance.test_llf ... ok
/home/travis/miniconda2/envs/statsmodels-test/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/tsa/regime_switching/markov_switching.py:2140: VisibleDeprecationWarning: non integer (and non boolean) array-likes will not be accepted as indices in the future
  res = (self, self.params[mask], self.bse[mask],
/home/travis/miniconda2/envs/statsmodels-test/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/tsa/regime_switching/markov_switching.py:2141: VisibleDeprecationWarning: non integer (and non boolean) array-likes will not be accepted as indices in the future
  self.tvalues[mask], self.pvalues[mask],
/home/travis/miniconda2/envs/statsmodels-test/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/tsa/regime_switching/markov_switching.py:2142: VisibleDeprecationWarning: non integer (and non boolean) array-likes will not be accepted as indices in the future
  self.conf_int(alpha)[mask])
/home/travis/miniconda2/envs/statsmodels-test/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/tsa/regime_switching/markov_switching.py:2146: VisibleDeprecationWarning: non integer (and non boolean) array-likes will not be accepted as indices in the future
  np.array(self.data.param_names)[mask].tolist()
```



Discussion:
@ChadFulton  What dtype is `mask` supposed to be?  Can you look at this?


Resolving patch:
diff --git a/statsmodels/tsa/regime_switching/markov_switching.py b/statsmodels/tsa/regime_switching/markov_switching.py
--- a/statsmodels/tsa/regime_switching/markov_switching.py
+++ b/statsmodels/tsa/regime_switching/markov_switching.py
@@ -554,7 +554,7 @@ def __setitem__(self, key, value):
                     self.index_regime_purpose[j][k] = v
                     indices.append(v)
                     offset += self.k_parameters[k]
-                self.index_regime[j] = np.concatenate(indices)
+                self.index_regime[j] = np.concatenate(indices).astype(int)
         else:
             raise IndexError('Invalid index')
 
@@ -2173,9 +2173,9 @@ def make_table(self, mask, title, strip_end=True):
 
         mask = []
         for key, _mask in other_masks.items():
-            mask = np.r_[mask, _mask]
+            mask.extend(_mask)
         if len(mask) > 0:
-            table = make_table(self, mask.tolist(), 'Non-switching parameters')
+            table = make_table(self, mask, 'Non-switching parameters')
             summary.tables.append(table)
 
         # Transition parameters


Test patch:
Repository: statsmodels/statsmodels

Issue:
"Jeffreys" misspelled as "Jeffrey's"
The documentation for [`statsmodels.stats.proportion.proportion_confint`](http://statsmodels.sourceforge.net/devel/generated/statsmodels.stats.proportion.proportion_confint.html) describes an option as "Jeffrey’s Bayesian Interval". The interval in question is named after the Jeffreys prior, which itself is named after Harold Jeffreys. The option itself should then be named `jeffreys`, not `jeffrey`.



Discussion:
Thanks for pointing this out.

I'm not very good in spelling names. option needs to be fixed


Resolving patch:
diff --git a/statsmodels/stats/proportion.py b/statsmodels/stats/proportion.py
--- a/statsmodels/stats/proportion.py
+++ b/statsmodels/stats/proportion.py
@@ -34,7 +34,7 @@ def proportion_confint(count, nobs, alpha=0.05, method='normal'):
          - `agresti_coull` : Agresti-Coull interval
          - `beta` : Clopper-Pearson interval based on Beta distribution
          - `wilson` : Wilson Score interval
-         - `jeffrey` : Jeffrey's Bayesian Interval
+         - `jeffreys` : Jeffreys Bayesian Interval
          - `binom_test` : experimental, inversion of binom_test
 
     Returns
@@ -90,7 +90,7 @@ def func(qi):
             ci_upp = optimize.brentq(func, q_, 1. - float_info.epsilon)
 
     elif method == 'beta':
-        ci_low = stats.beta.ppf(alpha_2 , count, nobs - count + 1)
+        ci_low = stats.beta.ppf(alpha_2, count, nobs - count + 1)
         ci_upp = stats.beta.isf(alpha_2, count + 1, nobs - count)
 
     elif method == 'agresti_coull':
@@ -112,14 +112,16 @@ def func(qi):
         ci_low = center - dist
         ci_upp = center + dist
 
-    elif method == 'jeffrey':
-        ci_low, ci_upp = stats.beta.interval(1 - alpha,  count + 0.5,
+    # method adjusted to be more forgiving of misspellings or incorrect option name
+    elif method[:4] == 'jeff':
+        ci_low, ci_upp = stats.beta.interval(1 - alpha, count + 0.5,
                                              nobs - count + 0.5)
 
     else:
         raise NotImplementedError('method "%s" is not available' % method)
     return ci_low, ci_upp
 
+
 def multinomial_proportions_confint(counts, alpha=0.05, method='goodman'):
     '''Confidence intervals for multinomial proportions.
 
@@ -777,7 +779,7 @@ def proportions_ztest(count, nobs, value=None, alternative='two-sided',
 
     count = np.asarray(count)
     nobs = np.asarray(nobs)
-    
+
     if nobs.size == 1:
         nobs = nobs * np.ones_like(count)
 


Test patch:
Repository: statsmodels/statsmodels

Issue:
BUG/ENH: MICEData should give a more informative error with missing column names
With the following initialization:

```
MICEData(DataFrame([[1, 4], [2, 3]]))
```

you get a TypeError exception:

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/statsmodels/imputation/mice.py", line 242, in __init__
    self.set_imputer(vname)
  File "/usr/local/lib/python2.7/dist-packages/statsmodels/imputation/mice.py", line 352, in set_imputer
    fml = endog_name + " ~ " + " + ".join(main_effects)
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S21') dtype('S21') dtype('S21')
```

This error seems to be because the column names are missing, since the below code does not give any error:

```
MICEData(DataFrame([[1, None], [2, 3], [1, np.nan]], columns=['a', 'b']))
```

I would have expected a more informative error. Or perhaps that it even was able to handle columns with no names. 



Discussion:

Resolving patch:
diff --git a/statsmodels/imputation/mice.py b/statsmodels/imputation/mice.py
--- a/statsmodels/imputation/mice.py
+++ b/statsmodels/imputation/mice.py
@@ -197,6 +197,9 @@ class MICEData(object):
     def __init__(self, data, perturbation_method='gaussian',
                  k_pmm=20, history_callback=None):
 
+        if data.columns.dtype != np.dtype('O'):
+            raise ValueError("MICEData data column names should be string type")
+
         # Drop observations where all variables are missing.  This
         # also has the effect of copying the data frame.
         self.data = data.dropna(how='all').reset_index(drop=True)


Test patch:
Repository: statsmodels/statsmodels

Issue:
BUG predict pandas wrapper breaks without pandas exog but formula
after using a standard formula and pandas model, I use just a dict with numpy array for predict.
(

This raises and exception

```
>>> res.predict({'temp': x_p})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "m:\josef_new\eclipse_ws\statsmodels\statsmodels_py34_pr\statsmodels\base\model.py", line 774, in predict
    if len(exog) < len(exog_index):
TypeError: object of type 'NoneType' has no len()
```

in base: we compare length even though `exog_index` could be None.
We need `exog_index` is None check first

```
            if len(exog) < len(exog_index):
                # missing values, rows have been dropped
                if exog_index is not None:
```

If exog in predict is a dict for patsy handling, then we cannot tell how many observations are in the dict `exog`, given that we don't parse the original data names.



Discussion:
workaround: use pandas

```
df_p = pd.DataFrame({'temp': x_p})
res.predict(df_p)
```

i.e. we could convert to DataFrame, if predict exog is a dict. (instance check would still break dict-like)


Resolving patch:
diff --git a/statsmodels/base/model.py b/statsmodels/base/model.py
--- a/statsmodels/base/model.py
+++ b/statsmodels/base/model.py
@@ -769,6 +769,9 @@ def predict(self, exog=None, transform=True, *args, **kwargs):
 
         if transform and hasattr(self.model, 'formula') and exog is not None:
             from patsy import dmatrix
+            exog = pd.DataFrame(exog)  # user may pass series, if one predictor
+            if exog_index is None:  # user passed in a dictionary
+                exog_index = exog.index
             exog = dmatrix(self.model.data.design_info.builder,
                            exog, return_type="dataframe")
             if len(exog) < len(exog_index):


Test patch:
diff --git a/statsmodels/formula/tests/test_formula.py b/statsmodels/formula/tests/test_formula.py
--- a/statsmodels/formula/tests/test_formula.py
+++ b/statsmodels/formula/tests/test_formula.py
@@ -101,3 +101,25 @@ def test_formula_predict():
     results = ols(formula, dta).fit()
     npt.assert_almost_equal(results.fittedvalues.values,
                             results.predict(data.exog), 8)
+
+
+def test_formula_predict_series():
+    import pandas as pd
+    import pandas.util.testing as tm
+    data = pd.DataFrame({"y": [1, 2, 3], "x": [1, 2, 3]}, index=[5, 3, 1])
+    results = ols('y ~ x', data).fit()
+
+    result = results.predict(data)
+    expected = pd.Series([1., 2., 3.], index=[5, 3, 1])
+    tm.assert_series_equal(result, expected)
+
+    result = results.predict(data.x)
+    tm.assert_series_equal(result, expected)
+
+    result = results.predict(pd.Series([1, 2, 3], index=[1, 2, 3], name='x'))
+    expected = pd.Series([1., 2., 3.], index=[1, 2, 3])
+    tm.assert_series_equal(result, expected)
+
+    result = results.predict({"x": [1, 2, 3]})
+    expected = pd.Series([1., 2., 3.], index=[0, 1, 2])
+    tm.assert_series_equal(result, expected)