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

scipy-svn@scip... scipy-svn@scip...
Sun Nov 21 03:57:23 CST 2010


Author: rgommers
Date: 2010-11-21 03:57:22 -0600 (Sun, 21 Nov 2010)
New Revision: 6937

Modified:
   trunk/scipy/stats/stats.py
   trunk/scipy/stats/tests/test_stats.py
Log:
BUG: fix nanmedian for scalar inputs. Closes #1098. Thanks to Keith Goodman.

Modified: trunk/scipy/stats/stats.py
===================================================================
--- trunk/scipy/stats/stats.py	2010-11-20 18:49:16 UTC (rev 6936)
+++ trunk/scipy/stats/stats.py	2010-11-21 09:57:22 UTC (rev 6937)
@@ -408,9 +408,14 @@
     array([  2. ,   9. ,  15. ,  20.5,  26. ])
 
     """
-    x, axis = _chk_asarray(x,axis)
+    x, axis = _chk_asarray(x, axis)
+    if x.ndim == 0:
+        return float(x.item())
     x = x.copy()
-    return np.apply_along_axis(_nanmedian,axis,x)
+    x = np.apply_along_axis(_nanmedian, axis, x)
+    if x.ndim == 0:
+        x = float(x.item())
+    return x
 
 
 #####################################

Modified: trunk/scipy/stats/tests/test_stats.py
===================================================================
--- trunk/scipy/stats/tests/test_stats.py	2010-11-20 18:49:16 UTC (rev 6936)
+++ trunk/scipy/stats/tests/test_stats.py	2010-11-21 09:57:22 UTC (rev 6937)
@@ -254,6 +254,14 @@
         m = stats.nanmedian(self.Xall)
         assert_(np.isnan(m))
 
+    def test_nanmedian_scalars(self):
+        """Check nanmedian for scalar inputs. See ticket #1098."""
+        assert_equal(stats.nanmedian(1), np.median(1))
+        assert_equal(stats.nanmedian(True), np.median(True))
+        assert_equal(stats.nanmedian(np.array(1)), np.median(np.array(1)))
+        assert_equal(stats.nanmedian(np.nan), np.median(np.nan))
+
+
 class TestCorrPearsonr(TestCase):
     """ W.II.D. Compute a correlation matrix on all the variables.
 



More information about the Scipy-svn mailing list