prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  OLS residuals returned as Pandas series when endog and exog are Pandas series
  When I fit OLS model with pandas series and try to do a Durbin-Watson test, the function returns nan. In that case the RegressionResult.resid attribute is a pandas series, rather than a numpy array- converting to a numpy array explicitly, the durbin_watson function works like a charm. 
  
  My instinct is this is something that should probably be changed in OLS (to guarantee the type of resid), hence the title of the issue, but I leave that to the judgement of our fearless leaders.
  
  ``` python
  import statsmodels.api as sm
  import numpy as np
  from pandas import DataFrame
  x=np.arange(1,11)
  y=[num+np.random.normal() for num in np.arange(0,5, .5)]
  linmod=sm.OLS(y, x).fit()
  dw=sm.stats.stattools.durbin_watson(linmod.resid)
  data=DataFrame({'x':x, 'y':y}, index=x)
  linmod_pandas=sm.OLS(data.y, data.x).fit()
  dw_pandas=sm.stats.stattools.durbin_watson(linmod_pandas.resid)
  dw_pandas1=sm.stats.stattools.durbin_watson(array(linmod_pandas.resid))
  print type(linmod_pandas.resid)
  print dw, dw_pandas, dw_pandas1
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `statsmodels/stats/stattools.py`
  Content:
  ```
  1 """
  2 Statistical tests to be used in conjunction with the models
  3 
  4 Notes
  5 -----
  6 These functions haven't been formally tested.
  7 """
  8 
  9 from scipy import stats
  10 import numpy as np
  11 
  12 
  13 #TODO: these are pretty straightforward but they should be tested
  14 def durbin_watson(resids):
  15     """
  16     Calculates the Durbin-Watson statistic
  17 
  18     Parameters
  19     -----------
  20     resids : array-like
  21 
  22     Returns
  23         --------
  24     Durbin Watson statistic.  This is defined as
  25     sum_(t=2)^(T)((e_t - e_(t-1))^(2))/sum_(t=1)^(T)e_t^(2)
  26     """
  27     diff_resids = np.diff(resids, 1)
  28     dw = np.dot(diff_resids, diff_resids) / np.dot(resids, resids)
  29     return dw
  30 
  31 def omni_normtest(resids, axis=0):
  32     """
  33     Omnibus test for normality
  34 
  35     Parameters
  36     -----------
  37     resid : array-like
  38     axis : int, optional
  39         Default is 0
  40 
  41     Returns
  42     -------
  43     Chi^2 score, two-tail probability
  44     """
  45     #TODO: change to exception in summary branch and catch in summary()
  46     #behavior changed between scipy 0.9 and 0.10
  47     resids = np.asarray(resids)
  48     n = resids.shape[axis]
  49     if n < 8:
  50         return np.nan, np.nan
  51         return_shape = list(resids.shape)
  52         del return_shape[axis]
  53         return np.nan * np.zeros(return_shape), np.nan * np.zeros(return_shape)
  54         raise ValueError(
  55             "skewtest is not valid with less than 8 observations; %i samples"
  56             " were given." % int(n))
  57 
  58     return stats.normaltest(resids, axis=axis)
  59 
  60 def jarque_bera(resids):
  61     """
  62     Calculate residual skewness, kurtosis, and do the JB test for normality
  63 
  64     Parameters
  65     -----------
  66     resids : array-like
  67 
  68     Returns
  69     -------
  70     JB, JBpv, skew, kurtosis
  71 
  72     JB = n/6*(S^2 + (K-3)^2/4)
  73 
  74     JBpv is the Chi^2 two-tail probability value
  75 
  76     skew is the measure of skewness
  77 
  78     kurtosis is the measure of kurtosis
  79 
  80     """
  81     resids = np.asarray(resids)
  82     # Calculate residual skewness and kurtosis
  83     skew = stats.skew(resids)
  84     kurtosis = 3 + stats.kurtosis(resids)
  85 
  86     # Calculate the Jarque-Bera test for normality
  87     JB = (resids.shape[0] / 6.) * (skew**2 + (1 / 4.) * (kurtosis-3)**2)
  88     JBpv = stats.chi2.sf(JB,2)
  89 
  90     return JB, JBpv, skew, kurtosis
  91 
  92
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/statsmodels/stats/stattools.py b/statsmodels/stats/stattools.py
  --- a/statsmodels/stats/stattools.py
  +++ b/statsmodels/stats/stattools.py
  @@ -24,6 +24,7 @@
       Durbin Watson statistic.  This is defined as
       sum_(t=2)^(T)((e_t - e_(t-1))^(2))/sum_(t=1)^(T)e_t^(2)
       """
  +    resids=np.asarray(resids)
       diff_resids = np.diff(resids, 1)
       dw = np.dot(diff_resids, diff_resids) / np.dot(resids, resids)
       return dw
  
verification_info: {"golden_diff": "diff --git a/statsmodels/stats/stattools.py b/statsmodels/stats/stattools.py\n--- a/statsmodels/stats/stattools.py\n+++ b/statsmodels/stats/stattools.py\n@@ -24,6 +24,7 @@\n     Durbin Watson statistic.  This is defined as\n     sum_(t=2)^(T)((e_t - e_(t-1))^(2))/sum_(t=1)^(T)e_t^(2)\n     \"\"\"\n+    resids=np.asarray(resids)\n     diff_resids = np.diff(resids, 1)\n     dw = np.dot(diff_resids, diff_resids) / np.dot(resids, resids)\n     return dw\n", "issue": "OLS residuals returned as Pandas series when endog and exog are Pandas series\nWhen I fit OLS model with pandas series and try to do a Durbin-Watson test, the function returns nan. In that case the RegressionResult.resid attribute is a pandas series, rather than a numpy array- converting to a numpy array explicitly, the durbin_watson function works like a charm. \n\nMy instinct is this is something that should probably be changed in OLS (to guarantee the type of resid), hence the title of the issue, but I leave that to the judgement of our fearless leaders.\n\n``` python\nimport statsmodels.api as sm\nimport numpy as np\nfrom pandas import DataFrame\nx=np.arange(1,11)\ny=[num+np.random.normal() for num in np.arange(0,5, .5)]\nlinmod=sm.OLS(y, x).fit()\ndw=sm.stats.stattools.durbin_watson(linmod.resid)\ndata=DataFrame({'x':x, 'y':y}, index=x)\nlinmod_pandas=sm.OLS(data.y, data.x).fit()\ndw_pandas=sm.stats.stattools.durbin_watson(linmod_pandas.resid)\ndw_pandas1=sm.stats.stattools.durbin_watson(array(linmod_pandas.resid))\nprint type(linmod_pandas.resid)\nprint dw, dw_pandas, dw_pandas1\n```\n\n", "before_files": [{"content": "\"\"\"\nStatistical tests to be used in conjunction with the models\n\nNotes\n-----\nThese functions haven't been formally tested.\n\"\"\"\n\nfrom scipy import stats\nimport numpy as np\n\n\n#TODO: these are pretty straightforward but they should be tested\ndef durbin_watson(resids):\n    \"\"\"\n    Calculates the Durbin-Watson statistic\n\n    Parameters\n    -----------\n    resids : array-like\n\n    Returns\n        --------\n    Durbin Watson statistic.  This is defined as\n    sum_(t=2)^(T)((e_t - e_(t-1))^(2))/sum_(t=1)^(T)e_t^(2)\n    \"\"\"\n    diff_resids = np.diff(resids, 1)\n    dw = np.dot(diff_resids, diff_resids) / np.dot(resids, resids)\n    return dw\n\ndef omni_normtest(resids, axis=0):\n    \"\"\"\n    Omnibus test for normality\n\n    Parameters\n    -----------\n    resid : array-like\n    axis : int, optional\n        Default is 0\n\n    Returns\n    -------\n    Chi^2 score, two-tail probability\n    \"\"\"\n    #TODO: change to exception in summary branch and catch in summary()\n    #behavior changed between scipy 0.9 and 0.10\n    resids = np.asarray(resids)\n    n = resids.shape[axis]\n    if n < 8:\n        return np.nan, np.nan\n        return_shape = list(resids.shape)\n        del return_shape[axis]\n        return np.nan * np.zeros(return_shape), np.nan * np.zeros(return_shape)\n        raise ValueError(\n            \"skewtest is not valid with less than 8 observations; %i samples\"\n            \" were given.\" % int(n))\n\n    return stats.normaltest(resids, axis=axis)\n\ndef jarque_bera(resids):\n    \"\"\"\n    Calculate residual skewness, kurtosis, and do the JB test for normality\n\n    Parameters\n    -----------\n    resids : array-like\n\n    Returns\n    -------\n    JB, JBpv, skew, kurtosis\n\n    JB = n/6*(S^2 + (K-3)^2/4)\n\n    JBpv is the Chi^2 two-tail probability value\n\n    skew is the measure of skewness\n\n    kurtosis is the measure of kurtosis\n\n    \"\"\"\n    resids = np.asarray(resids)\n    # Calculate residual skewness and kurtosis\n    skew = stats.skew(resids)\n    kurtosis = 3 + stats.kurtosis(resids)\n\n    # Calculate the Jarque-Bera test for normality\n    JB = (resids.shape[0] / 6.) * (skew**2 + (1 / 4.) * (kurtosis-3)**2)\n    JBpv = stats.chi2.sf(JB,2)\n\n    return JB, JBpv, skew, kurtosis\n\n", "path": "statsmodels/stats/stattools.py"}], "after_files": [{"content": "\"\"\"\nStatistical tests to be used in conjunction with the models\n\nNotes\n-----\nThese functions haven't been formally tested.\n\"\"\"\n\nfrom scipy import stats\nimport numpy as np\n\n\n#TODO: these are pretty straightforward but they should be tested\ndef durbin_watson(resids):\n    \"\"\"\n    Calculates the Durbin-Watson statistic\n\n    Parameters\n    -----------\n    resids : array-like\n\n    Returns\n        --------\n    Durbin Watson statistic.  This is defined as\n    sum_(t=2)^(T)((e_t - e_(t-1))^(2))/sum_(t=1)^(T)e_t^(2)\n    \"\"\"\n    resids=np.asarray(resids)\n    diff_resids = np.diff(resids, 1)\n    dw = np.dot(diff_resids, diff_resids) / np.dot(resids, resids)\n    return dw\n\ndef omni_normtest(resids, axis=0):\n    \"\"\"\n    Omnibus test for normality\n\n    Parameters\n    -----------\n    resid : array-like\n    axis : int, optional\n        Default is 0\n\n    Returns\n    -------\n    Chi^2 score, two-tail probability\n    \"\"\"\n    #TODO: change to exception in summary branch and catch in summary()\n    #behavior changed between scipy 0.9 and 0.10\n    resids = np.asarray(resids)\n    n = resids.shape[axis]\n    if n < 8:\n        return np.nan, np.nan\n        return_shape = list(resids.shape)\n        del return_shape[axis]\n        return np.nan * np.zeros(return_shape), np.nan * np.zeros(return_shape)\n        raise ValueError(\n            \"skewtest is not valid with less than 8 observations; %i samples\"\n            \" were given.\" % int(n))\n\n    return stats.normaltest(resids, axis=axis)\n\ndef jarque_bera(resids):\n    \"\"\"\n    Calculate residual skewness, kurtosis, and do the JB test for normality\n\n    Parameters\n    -----------\n    resids : array-like\n\n    Returns\n    -------\n    JB, JBpv, skew, kurtosis\n\n    JB = n/6*(S^2 + (K-3)^2/4)\n\n    JBpv is the Chi^2 two-tail probability value\n\n    skew is the measure of skewness\n\n    kurtosis is the measure of kurtosis\n\n    \"\"\"\n    resids = np.asarray(resids)\n    # Calculate residual skewness and kurtosis\n    skew = stats.skew(resids)\n    kurtosis = 3 + stats.kurtosis(resids)\n\n    # Calculate the Jarque-Bera test for normality\n    JB = (resids.shape[0] / 6.) * (skew**2 + (1 / 4.) * (kurtosis-3)**2)\n    JBpv = stats.chi2.sf(JB,2)\n\n    return JB, JBpv, skew, kurtosis\n\n", "path": "statsmodels/stats/stattools.py"}]}