[Scipy-tickets] [SciPy] #1690: scipy.stats.kendalltau: division by zero error

SciPy Trac scipy-tickets@scipy....
Mon Jul 9 19:38:07 CDT 2012


#1690: scipy.stats.kendalltau: division by zero error
-------------------------+--------------------------------------------------
 Reporter:  marek        |       Owner:  somebody   
     Type:  defect       |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  scipy.stats  |     Version:  0.10.0     
 Keywords:               |  
-------------------------+--------------------------------------------------
 If one (but not both) of the input arrays contains only one unique value,
 the function will perform a division by zero.

 {{{
 >>> x1 = [1, 2]
 >>> x2 = [1, 1]
 >>> tau, p_value = scipy.stats.kendalltau(x1, x2)
 >>> tau
 nan
 }}}

 When first testing, an error was displayed as well:

 {{{
 /usr/lib/python2.7/site-packages/scipy/stats/stats.py:2725:
 RuntimeWarning: divide by zero encountered in log
   denom = np.exp(0.5 * (np.log(tot - u) + np.log(tot - v)))
 /usr/lib/python2.7/site-packages/scipy/stats/stats.py:2726:
 RuntimeWarning: invalid value encountered in double_scalars
   tau = ((tot - (v + u - t)) - 2.0 * exchanges) / denom
 }}}

 I believe there should be a test to check whether the denominator is 0; if
 yes, return 1. There is a similar test already in place:

 {{{
 if tot == u and tot == v:
         return 1    # Special case for all ties in both ranks
 }}}

 However, I think this should more like this:
 {{{
 if tot == u or tot == v:
         return 1
 }}}

 Related: The function is supposed to return both tau and p_value, whereas
 this check only returns tau. There is a different existing ticket for that
 already.

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


More information about the Scipy-tickets mailing list