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

scipy-svn@scip... scipy-svn@scip...
Thu Jan 8 06:37:49 CST 2009


Author: cdavid
Date: 2009-01-08 06:37:43 -0600 (Thu, 08 Jan 2009)
New Revision: 5395

Modified:
   trunk/scipy/stats/morestats.py
   trunk/scipy/stats/stats.py
   trunk/scipy/stats/tests/test_stats.py
Log:
Do not use stats.var anymore in stats.

Modified: trunk/scipy/stats/morestats.py
===================================================================
--- trunk/scipy/stats/morestats.py	2009-01-08 12:37:27 UTC (rev 5394)
+++ trunk/scipy/stats/morestats.py	2009-01-08 12:37:43 UTC (rev 5395)
@@ -667,7 +667,7 @@
     ssq = zeros(k,'d')
     for j in range(k):
         Ni[j] = len(args[j])
-        ssq[j] = stats.var(args[j])
+        ssq[j] = np.var(args[j], ddof=1)
     Ntot = sum(Ni,axis=0)
     spsq = sum((Ni-1)*ssq,axis=0)/(1.0*(Ntot-k))
     numer = (Ntot*1.0-k)*log(spsq) - sum((Ni-1.0)*log(ssq),axis=0)

Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py	2009-01-08 12:37:27 UTC (rev 5394)
+++ trunk/scipy/stats/stats.py	2009-01-08 12:37:43 UTC (rev 5395)
@@ -1289,23 +1289,14 @@
 array (i.e., N-1).  Axis can equal None (ravel array first), or an
 integer (the axis over which to operate).
 """
-    warnings.warn("""\
+    raise DeprecationWarning("""\
 scipy.stats.var is deprecated; please update your code to use numpy.var.
 Please note that:
     - numpy.var axis argument defaults to None, not 0
     - numpy.var has a ddof argument to replace bias in a more general manner.
       scipy.stats.var(a, bias=True) can be replaced by numpy.var(x,
       axis=0, ddof=0), scipy.stats.var(a, bias=False) by var(x, axis=0,
-      ddof=1).""", DeprecationWarning)
-    a, axis = _chk_asarray(a, axis)
-    mn = np.expand_dims(np.mean(a,axis),axis)
-    deviations = a - mn
-    n = a.shape[axis]
-    vals = sum(abs(deviations)**2,axis)/(n-1.0)
-    if bias:
-        return vals * (n-1.0)/n
-    else:
-        return vals
+      ddof=1).""")
 
 def std(a, axis=0, bias=False):
     """
@@ -1320,8 +1311,7 @@
     - numpy.std has a ddof argument to replace bias in a more general manner.
       scipy.stats.std(a, bias=True) can be replaced by numpy.std(x,
       axis=0, ddof=0), scipy.stats.std(a, bias=False) by numpy.std(x, axis=0,
-      ddof=1).""", DeprecationWarning)
-    return np.sqrt(var(a,axis,bias))
+      ddof=1).""")
 
 
 def stderr(a, axis=0):

Modified: trunk/scipy/stats/tests/test_stats.py
===================================================================
--- trunk/scipy/stats/tests/test_stats.py	2009-01-08 12:37:27 UTC (rev 5394)
+++ trunk/scipy/stats/tests/test_stats.py	2009-01-08 12:37:43 UTC (rev 5395)
@@ -721,7 +721,9 @@
         var(testcase) = 1.666666667 """
         #y = stats.var(self.shoes[0])
         #assert_approx_equal(y,6.009)
-        y = stats.var(self.testcase)
+        y = np.var(self.testcase)
+        assert_approx_equal(y,1.25)
+        y = np.var(self.testcase, ddof=1)
         assert_approx_equal(y,1.666666667)
 
     def test_samplevar(self):



More information about the Scipy-svn mailing list