[Scipy-tickets] [SciPy] #1098: nanmedian

SciPy Trac scipy-tickets@scipy....
Thu Jan 21 20:58:48 CST 2010


#1098: nanmedian
-------------------------+--------------------------------------------------
 Reporter:  kwgoodman    |       Owner:  somebody
     Type:  defect       |      Status:  new     
 Priority:  normal       |   Milestone:  0.8.0   
Component:  scipy.stats  |     Version:  0.7.0   
 Keywords:               |  
-------------------------+--------------------------------------------------
 I noticed a couple of issues with nanmedian in scipy.stats:
 {{{
 >> from scipy.stats import nanmedian
 >> nanmedian(1)
 ValueError: axis must be less than arr.ndim; axis=0, rank=0.
 >> nanmedian(True)
 ValueError: axis must be less than arr.ndim; axis=0, rank=0.
 >> nanmedian(np.array(1))
 ValueError: axis must be less than arr.ndim; axis=0, rank=0.
 >> nanmedian(np.array([1, 2, 3]))
   array(2.0)
 }}}
 Changing the function from the original:
 {{{
 def nanmedian(x, axis=0):
    x, axis = _chk_asarray(x,axis)
    x = x.copy()
    return np.apply_along_axis(_nanmedian,axis,x)
 }}}
 to this:
 {{{
 def nanmedian(x, axis=0):
    x, axis = _chk_asarray(x, axis)
    if x.ndim == 0:
        return float(x.item())
    x = x.copy()
    x = np.apply_along_axis(_nanmedian, axis, x)
    if x.ndim == 0:
        x = float(x.item())
    return x
 }}}
 gives the expected results:
 {{{
 >> nanmedian(1)
   1.0
 >> nanmedian(True)
   1.0
 >> nanmedian(np.array(1))
   1.0
 >> nanmedian(np.array([1, 2, 3]))
    2.0
 }}}
 which agrees with numpy:
 {{{
 >> np.median(1)
   1.0
 >> np.median(True)
   1.0
 >> np.median(np.array(1))
   1.0
 >> np.median(np.array([1, 2, 3]))
    2.0
 }}}

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1098>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list