[Scipy-tickets] [SciPy] #1805: rankdata returns wrong results on masked arrays

SciPy Trac scipy-tickets@scipy....
Sat Jan 5 22:05:43 CST 2013


#1805: rankdata returns wrong results on masked arrays
-------------------------+--------------------------------------------------
 Reporter:  hberger      |       Owner:  rgommers   
     Type:  defect       |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  scipy.stats  |     Version:  0.11.0     
 Keywords:               |  
-------------------------+--------------------------------------------------

Comment(by josefpktd):

 Thanks for the report.

 looks like a strange behavior in np.ma: sort is different from argsort
 sort ignores the fill_value

 {{{
 >>> np.__version__
 '1.5.1'
 >>> aam[np.ma.argsort(aam, axis=None, kind='quicksort', order=None,
 fill_value=None)]
 masked_array(data = [-1e-10 0.42 2.39 2.4 -- -- -- -- -- -- -- --
 2.4e+30],
              mask = [False False False False  True  True  True  True  True
 True  True  True
  False],
        fill_value = 1e+20)

 >>> np.ma.sort(aam, axis=None, kind='quicksort', order=None,
 fill_value=None)
 masked_array(data = [-1e-10 0.42 2.39 2.4 2.4e+30 -- -- -- -- -- -- --
 --],
              mask = [False False False False False  True  True  True  True
 True  True  True
   True],
        fill_value = 1e+20)
 }}}

 a possible workaround is to use the fill_value larger than aam.max, or the
 largest value supported by the dtype during argsort in _rank1d

 e.g.
 {{{
 >>> aam[np.ma.argsort(aam, axis=None, kind='quicksort', order=None,
 fill_value=aam.max()*1.1)]
 masked_array(data = [-1e-10 0.42 2.39 2.4 2.4e+30 -- -- -- -- -- -- --
 --],
              mask = [False False False False False  True  True  True  True
 True  True  True
   True],
        fill_value = 1e+20)
 }}}

 actually: looking at the implementation of np.ma.sort, there is a function
 to find the largest representable value

 {{{
 fill_value=np.ma.minimum_fill_value(aam)
 }}}

 Do you want to prepare a pull request? It would be helpful to get the fix
 in faster, and would get your name on the scipy author list.

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


More information about the Scipy-tickets mailing list