[Scipy-tickets] [SciPy] #1372: scoreatpercentile() does not handle empty list inputs

SciPy Trac scipy-tickets@scipy....
Thu Jan 27 10:42:55 CST 2011

#1372: scoreatpercentile() does not handle empty list inputs
 Reporter:  mpenning     |       Owner:  somebody
     Type:  defect       |      Status:  new     
 Priority:  normal       |   Milestone:  0.9.0   
Component:  scipy.stats  |     Version:  0.8.0   
 Keywords:               |  
 When iterating through slices of list structures, occasionally
 scoreatpercentile() may get called with an empty list, resulting in a
 IndexError traceback that looks similar to this:

 Traceback (most recent call last):
   File "reverse.py", line 1154, in <module>
   File "reverse.py", line 130, in update_all_stats
     self.stats[ii] = self.infra[ii][0](sig,current)
   File "reverse.py", line 82, in <lambda>
     fn = lambda sig,current:
   File "reverse.py", line 887, in pct
     return pctl(array.truncate(before=current-
   File "/usr/lib/python2.5/site-packages/scipy/stats/stats.py", line 1287,
 in scoreatpercentile
     return _interpolate(values[int(idx)], values[int(idx) + 1], idx % 1)
 IndexError: index out of bounds
 [mpenning@Bucksnort data]$

 scoreatpercentile() should return numpy.nan if the input list is empty...

 The following code may be useful as a local substitute while the bug gets

 def scoreatpercentile(a, per):
     values = np.sort(a,axis=0)

     _interpolate = lambda a,b,fraction: a + (b - a)*fraction

     idx = per /100. * (values.shape[0] - 1)
     if (idx % 1 == 0):
         return values[idx]
     elif values.shape[0]==0:
         return np.nan
         return _interpolate(values[int(idx)], values[int(idx) + 1], idx %

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

More information about the Scipy-tickets mailing list