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

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


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

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

Modified: trunk/scipy/stats/morestats.py
===================================================================
--- trunk/scipy/stats/morestats.py	2009-01-08 12:37:06 UTC (rev 5393)
+++ trunk/scipy/stats/morestats.py	2009-01-08 12:37:27 UTC (rev 5394)
@@ -719,7 +719,7 @@
         raise ValueError, "Keyword argument <center> must be 'mean', 'median'"\
               + "or 'trimmed'."
     if center == 'median':
-        func = stats.median
+        func = lambda x: np.median(x, axis=0)
     elif center == 'mean':
         func = lambda x: np.mean(x, axis=0)
     else:
@@ -841,7 +841,7 @@
         raise ValueError, "Keyword argument <center> must be 'mean', 'median'"\
               + "or 'trimmed'."
     if center == 'median':
-        func = stats.median
+        func = lambda x: np.median(x, axis=0)
     elif center == 'mean':
         func = lambda x: np.mean(x, axis=0)
     else:

Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py	2009-01-08 12:37:06 UTC (rev 5393)
+++ trunk/scipy/stats/stats.py	2009-01-08 12:37:27 UTC (rev 5394)
@@ -330,7 +330,7 @@
     x = np.sort(np.compress(cond,arr1d,axis=-1))
     if x.size == 0:
         return np.nan
-    return median(x)
+    return np.median(x)
 
 def nanmedian(x, axis=0):
     """ Compute the median along the given axis ignoring nan values
@@ -485,14 +485,13 @@
     The median of each remaining axis, or of all of the values in the array
     if axis is None.
     """
-    warnings.warn("""\
+    raise DeprecationWarning("""\
 scipy.stats.median is deprecated; please update your code to use numpy.median.
 Please note that:
     - numpy.median axis argument defaults to None, not 0
     - numpy.median has a ddof argument to replace bias in a more general manner.
       scipy.stats.median(a, bias=True) can be replaced by numpy.median(x,
-axis=0, ddof=1).""", DeprecationWarning)
-    return np.median(a, axis)
+axis=0, ddof=1).""")
 
 def mode(a, axis=0):
     """Returns an array of the modal (most common) value in the passed array.

Modified: trunk/scipy/stats/tests/test_stats.py
===================================================================
--- trunk/scipy/stats/tests/test_stats.py	2009-01-08 12:37:06 UTC (rev 5393)
+++ trunk/scipy/stats/tests/test_stats.py	2009-01-08 12:37:27 UTC (rev 5394)
@@ -228,12 +228,12 @@
     def test_nanmedian_none(self):
         """Check nanmedian when no values are nan."""
         m = stats.nanmedian(self.X)
-        assert_approx_equal(m, stats.median(self.X))
+        assert_approx_equal(m, np.median(self.X))
 
     def test_nanmedian_some(self):
         """Check nanmedian when some values only are nan."""
         m = stats.nanmedian(self.Xsome)
-        assert_approx_equal(m, stats.median(self.Xsomet))
+        assert_approx_equal(m, np.median(self.Xsomet))
 
     def test_nanmedian_all(self):
         """Check nanmedian when all values are nan."""
@@ -631,9 +631,9 @@
         self.a3 = [3.,4,5,10,-3,-5,-6,7.0]
 
     def test_median(self):
-        assert_equal(stats.median(self.a1), 4)
-        assert_equal(stats.median(self.a2), 2.5)
-        assert_equal(stats.median(self.a3), 3.5)
+        assert_equal(np.median(self.a1), 4)
+        assert_equal(np.median(self.a2), 2.5)
+        assert_equal(np.median(self.a3), 3.5)
 
     def test_percentile(self):
         x = arange(8) * 0.5
@@ -681,22 +681,23 @@
     def test_basic(self):
         data1 = [1,3,5,2,3,1,19,-10,2,4.0]
         data2 = [3,5,1,10,23,-10,3,-2,6,8,15]
-        assert_almost_equal(stats.median(data1),2.5)
-        assert_almost_equal(stats.median(data2),5)
+        assert_almost_equal(np.median(data1),2.5)
+        assert_almost_equal(np.median(data2),5)
 
     def test_basic2(self):
         a1 = [3,4,5,10,-3,-5,6]
         a2 = [3,-6,-2,8,7,4,2,1]
         a3 = [3.,4,5,10,-3,-5,-6,7.0]
-        assert_equal(stats.median(a1),4)
-        assert_equal(stats.median(a2),2.5)
-        assert_equal(stats.median(a3),3.5)
+        assert_equal(np.median(a1),4)
+        assert_equal(np.median(a2),2.5)
+        assert_equal(np.median(a3),3.5)
 
     def test_axis(self):
         """Regression test for #760."""
         a1 = np.array([[3,4,5], [10,-3,-5]])
-        assert_equal(stats.median(a1), np.array([6.5, 0.5, 0.]))
-        assert_equal(stats.median(a1, axis=-1), np.array([4., -3]))
+        assert_equal(np.median(a1), 3.5)
+        assert_equal(np.median(a1, axis=0), np.array([6.5, 0.5, 0.]))
+        assert_equal(np.median(a1, axis=-1), np.array([4., -3]))
 
 class TestMode(TestCase):
     def test_basic(self):



More information about the Scipy-svn mailing list