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

scipy-svn@scip... scipy-svn@scip...
Sat Nov 1 06:27:49 CDT 2008


Author: stefan
Date: 2008-11-01 06:27:41 -0500 (Sat, 01 Nov 2008)
New Revision: 4865

Modified:
   trunk/scipy/stats/stats.py
   trunk/scipy/stats/tests/test_stats.py
Log:
`skew` should return float for 1-d input [patch by Pieter Rautenbach].
Closes #771.


Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py	2008-11-01 11:11:05 UTC (rev 4864)
+++ trunk/scipy/stats/stats.py	2008-11-01 11:27:41 UTC (rev 4865)
@@ -757,6 +757,8 @@
             m3 = np.extract(can_correct, m3)
             nval = np.sqrt((n-1.0)*n)/(n-2.0)*m3/m2**1.5
             np.place(vals, can_correct, nval)
+    if vals.ndim == 0:
+        return vals.item()
     return vals
 
 def kurtosis(a, axis=0, fisher=True, bias=True):

Modified: trunk/scipy/stats/tests/test_stats.py
===================================================================
--- trunk/scipy/stats/tests/test_stats.py	2008-11-01 11:11:05 UTC (rev 4864)
+++ trunk/scipy/stats/tests/test_stats.py	2008-11-01 11:27:41 UTC (rev 4865)
@@ -820,7 +820,8 @@
 
     def test_skewness(self):
         """
-            sum((testmathworks-mean(testmathworks,axis=0))**3,axis=0)/((sqrt(var(testmathworks)*4/5))**3)/5
+        sum((testmathworks-mean(testmathworks,axis=0))**3,axis=0)/
+            ((sqrt(var(testmathworks)*4/5))**3)/5
         """
         y = stats.skew(self.testmathworks)
         assert_approx_equal(y,-0.29322304336607,10)
@@ -828,6 +829,13 @@
         assert_approx_equal(y,-0.437111105023940,10)
         y = stats.skew(self.testcase)
         assert_approx_equal(y,0.0,10)
+
+    def test_skewness_scalar(self):
+        """
+        `skew` must return a scalar for 1-dim input
+        """
+        assert_equal(stats.skew(arange(10)), 0.0)
+
     def test_kurtosis(self):
         """
             sum((testcase-mean(testcase,axis=0))**4,axis=0)/((sqrt(var(testcase)*3/4))**4)/4



More information about the Scipy-svn mailing list