Repository: statsmodels/statsmodels

Issue:
TestAnova2.test_results fails with pandas 0.13.1
with pandas 0.13.1, cython 0.20, numpy 1.7.1 and 1.8.0

it does not seem to happen with pandas 0.12, maybe they changed how NaN are handled as the element which is different originates from NaN inputs.

```
======================================================================
FAIL: __main__.TestAnova2.test_results
----------------------------------------------------------------------
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/stats/tests/test_anova.py", line 149, in test_results
    np.testing.assert_equal(results['df'].values, Df)
  File "/usr/lib/pymodules/python2.7/numpy/testing/utils.py", line 257, in assert_equal
    return assert_array_equal(actual, desired, err_msg, verbose)
  File "/usr/lib/pymodules/python2.7/numpy/testing/utils.py", line 719, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/usr/lib/pymodules/python2.7/numpy/testing/utils.py", line 645, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not equal

(mismatch 25.0%)
 x: array([ 1.,  2.,  2.,  0.])
 y: array([ 1,  2,  2, 51])

----------------------------------------------------------------------
Ran 1 test in 8.314s
```

TestAnova2.test_results fails with pandas 0.13.1
with pandas 0.13.1, cython 0.20, numpy 1.7.1 and 1.8.0

it does not seem to happen with pandas 0.12, maybe they changed how NaN are handled as the element which is different originates from NaN inputs.

```
======================================================================
FAIL: __main__.TestAnova2.test_results
----------------------------------------------------------------------
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/stats/tests/test_anova.py", line 149, in test_results
    np.testing.assert_equal(results['df'].values, Df)
  File "/usr/lib/pymodules/python2.7/numpy/testing/utils.py", line 257, in assert_equal
    return assert_array_equal(actual, desired, err_msg, verbose)
  File "/usr/lib/pymodules/python2.7/numpy/testing/utils.py", line 719, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/usr/lib/pymodules/python2.7/numpy/testing/utils.py", line 645, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not equal

(mismatch 25.0%)
 x: array([ 1.,  2.,  2.,  0.])
 y: array([ 1,  2,  2, 51])

----------------------------------------------------------------------
Ran 1 test in 8.314s
```



Discussion:
probably a pandas bug, failures is fixed by 6d56e7300d66d3ba76684334bbb44b6cd0ea9f61 of pandas
https://github.com/pydata/pandas/issues/6254

If this is really a pandas bug, then we should have paid more attention to the pythonxy test failure.
I'm far behind in testing new versions of numpy, scipy, pandas and patsy, and most of our automatic testing also uses older versions.

Thanks Julian

probably a pandas bug, failures is fixed by 6d56e7300d66d3ba76684334bbb44b6cd0ea9f61 of pandas
https://github.com/pydata/pandas/issues/6254

If this is really a pandas bug, then we should have paid more attention to the pythonxy test failure.
I'm far behind in testing new versions of numpy, scipy, pandas and patsy, and most of our automatic testing also uses older versions.

Thanks Julian


Resolving patch:
diff --git a/statsmodels/graphics/gofplots.py b/statsmodels/graphics/gofplots.py
--- a/statsmodels/graphics/gofplots.py
+++ b/statsmodels/graphics/gofplots.py
@@ -704,7 +704,7 @@ def _fmt_probplot_axis(ax, dist, nobs):
                        verticalalignment='center')
     ax.set_xlim([axis_qntls.min(), axis_qntls.max()])
 
-def _do_plot(x, y, dist=None, line=False, ax=None, fmt='bo'):
+def _do_plot(x, y, dist=None, line=False, ax=None, fmt='bo', **kwargs):
     """
     Boiler plate plotting function for the `ppplot`, `qqplot`, and
     `probplot` methods of the `ProbPlot` class
@@ -722,6 +722,8 @@ def _do_plot(x, y, dist=None, line=False, ax=None, fmt='bo'):
         created.
     fmt : str, optional
         matplotlib-compatible formatting string for the data markers
+    kwargs : keywords
+        These are passed to matplotlib.plot
 
     Returns
     -------
@@ -731,7 +733,7 @@ def _do_plot(x, y, dist=None, line=False, ax=None, fmt='bo'):
     """
     fig, ax = utils.create_mpl_ax(ax)
     ax.set_xmargin(0.02)
-    ax.plot(x, y, fmt)
+    ax.plot(x, y, fmt, **kwargs)
     if line:
         if line not in ['r','q','45','s']:
             msg = "%s option for line not understood" % line
diff --git a/statsmodels/stats/anova.py b/statsmodels/stats/anova.py
--- a/statsmodels/stats/anova.py
+++ b/statsmodels/stats/anova.py
@@ -133,7 +133,7 @@ def anova1_lm_single(model, endog, exog, nobs, design_info, table, n_rows, test,
                                 model.df_resid)
 
     # fill in residual
-    table.ix[['Residual'], ['sum_sq','df', test, pr_test]] = (model.ssr,
+    table.ix['Residual', ['sum_sq','df', test, pr_test]] = (model.ssr,
                                                             model.df_resid,
                                                             np.nan, np.nan)
     table['mean_sq'] = table['sum_sq'] / table['df']
@@ -208,11 +208,11 @@ def anova2_lm_single(model, design_info, n_rows, test, pr_test, robust):
         #from IPython.core.debugger import Pdb; Pdb().set_trace()
         if test == 'F':
             f = model.f_test(L12, cov_p=robust_cov)
-            table.ix[i][test] = test_value = f.fvalue
-            table.ix[i][pr_test] = f.pvalue
+            table.ix[i, test] = test_value = f.fvalue
+            table.ix[i, pr_test] = f.pvalue
 
         # need to back out SSR from f_test
-        table.ix[i]['df'] = r
+        table.ix[i, 'df'] = r
         col_order.append(cols.start)
         index.append(term.name())
 
@@ -222,7 +222,7 @@ def anova2_lm_single(model, design_info, n_rows, test, pr_test, robust):
     ssr = table[test] * table['df'] * model.ssr/model.df_resid
     table['sum_sq'] = ssr
     # fill in residual
-    table.ix['Residual'][['sum_sq','df', test, pr_test]] = (model.ssr,
+    table.ix['Residual', ['sum_sq','df', test, pr_test]] = (model.ssr,
                                                             model.df_resid,
                                                             np.nan, np.nan)
 
@@ -247,11 +247,11 @@ def anova3_lm_single(model, design_info, n_rows, test, pr_test, robust):
 
         if test == 'F':
             f = model.f_test(L12, cov_p=cov)
-            table.ix[i][test] = test_value = f.fvalue
-            table.ix[i][pr_test] = f.pvalue
+            table.ix[i, test] = test_value = f.fvalue
+            table.ix[i, pr_test] = f.pvalue
 
         # need to back out SSR from f_test
-        table.ix[i]['df'] = r
+        table.ix[i, 'df'] = r
         #col_order.append(cols.start)
         index.append(term.name())
 
@@ -262,7 +262,7 @@ def anova3_lm_single(model, design_info, n_rows, test, pr_test, robust):
     ssr = table[test] * table['df'] * model.ssr/model.df_resid
     table['sum_sq'] = ssr
     # fill in residual
-    table.ix['Residual'][['sum_sq','df', test, pr_test]] = (model.ssr,
+    table.ix['Residual', ['sum_sq','df', test, pr_test]] = (model.ssr,
                                                             model.df_resid,
                                                             np.nan, np.nan)
     return table


Test patch:
diff --git a/statsmodels/graphics/tests/test_gofplots.py b/statsmodels/graphics/tests/test_gofplots.py
--- a/statsmodels/graphics/tests/test_gofplots.py
+++ b/statsmodels/graphics/tests/test_gofplots.py
@@ -161,18 +161,18 @@ def teardown(self):
             plt.close('all')
 
     @dec.skipif(not have_matplotlib)
-    def test_qqplot():
+    def test_qqplot(self):
         fig = sm.qqplot(self.res, line='r')
 
     @dec.skipif(not have_matplotlib)
-    def test_qqplot_2samples_ProbPlotObjects():
+    def test_qqplot_2samples_ProbPlotObjects(self):
         # also tests all values for line
         for line in ['r', 'q', '45', 's']:
             # test with `ProbPlot` instances
             fig = sm.qqplot_2samples(self.prbplt, self.other_prbplot,
                                      line=line)
     @dec.skipif(not have_matplotlib)
-    def test_qqplot_2samples_arrays():
+    def test_qqplot_2samples_arrays(self):
         # also tests all values for line
         for line in ['r', 'q', '45', 's']:
             # test with arrays
diff --git a/statsmodels/sandbox/tests/test_pca.py b/statsmodels/sandbox/tests/test_pca.py
--- a/statsmodels/sandbox/tests/test_pca.py
+++ b/statsmodels/sandbox/tests/test_pca.py
@@ -29,7 +29,7 @@ def check_pca_svd(pcares, pcasvdres):
     xred_svd, factors_svd, evals_svd, evecs_svd = pcasvdres
     assert_array_almost_equal(evals_svd, evals, 14)
     msign = (evecs/evecs_svd)[0]
-    assert_array_almost_equal(msign*evecs_svd, evecs, 14)
+    assert_array_almost_equal(msign*evecs_svd, evecs, 13)
     assert_array_almost_equal(msign*factors_svd, factors, 13)
     assert_array_almost_equal(xred_svd, xreduced, 13)