[Scipy-svn] r6939 - in trunk/scipy/stats: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Tue Nov 23 09:28:53 EST 2010


Author: rgommers
Date: 2010-11-23 08:28:52 -0600 (Tue, 23 Nov 2010)
New Revision: 6939

Modified:
   trunk/scipy/stats/stats.py
   trunk/scipy/stats/tests/test_stats.py
Log:
ENH: stats: check shape of inputs in fisher_exact.

Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py	2010-11-22 00:39:25 UTC (rev 6938)
+++ trunk/scipy/stats/stats.py	2010-11-23 14:28:52 UTC (rev 6939)
@@ -2379,12 +2379,12 @@
     return r,prob
 
 
-def fisher_exact(c) :
+def fisher_exact(table) :
     """Performs a Fisher exact test on a 2x2 contingency table.
 
     Parameters
     ----------
-    c : array_like of ints
+    table : array_like of ints
         A 2x2 contingency table.
 
     Returns
@@ -2407,7 +2407,9 @@
     (0.25, 0.13007593634330314)
     """
     hypergeom = distributions.hypergeom
-    c = np.asarray(c, dtype=np.int64)  # int32 is not enough for the algorithm
+    c = np.asarray(table, dtype=np.int64)  # int32 is not enough for the algorithm
+    if not c.shape == (2, 2):
+        raise ValueError("The input `table` must be of shape (2, 2).")
 
     if c[1,0] > 0 and c[0,1] > 0:
         odssratio = c[0,0] * c[1,1] / float(c[1,0] * c[0,1])

Modified: trunk/scipy/stats/tests/test_stats.py
===================================================================
--- trunk/scipy/stats/tests/test_stats.py	2010-11-22 00:39:25 UTC (rev 6938)
+++ trunk/scipy/stats/tests/test_stats.py	2010-11-23 14:28:52 UTC (rev 6939)
@@ -447,7 +447,10 @@
         np.testing.assert_almost_equal(res[1], res_r[1], decimal=11,
                                        verbose=True)
 
+    # test we raise an error for wrong shape of input.
+    assert_raises(ValueError, fisher_exact, np.arange(6).reshape(2, 3))
 
+
 class TestCorrSpearmanr(TestCase):
     """ W.II.D. Compute a correlation matrix on all the variables.
 




More information about the Scipy-svn mailing list