# np.ma.argsort uses default fill_value not largest representable value #2890

Closed
opened this Issue Jan 6, 2013 · 3 comments

Projects
None yet
4 participants

### josef-pkt commented Jan 6, 2013

 example for bug with wrong sorting: http://projects.scipy.org/scipy/ticket/1805 np.ma.sort uses fill_value=np.ma.minimum_fill_value(aam) which uses the largest representable value fix should be to use this also in argsort

### hberger commented Jan 7, 2013• Edited 1 time eric-wieser Apr 21, 2017

 Actually, it is unclear why masked_array.sort/argsort have to use the fill value at all. Basically, NaN values exist in non-masked array as well and there sorting works fine. Can't we treat masked values in the same way as NaN ? Short example to explain the problem: ``````values=[5e40,-1e20,numpy.inf,0,100,-0.3,2,1,-numpy.inf] na=numpy.log(-1) v1=numpy.array(values) v2=numpy.array([na]+values+[na]) // these work fine numpy.sort(v1) numpy.sort(v2) numpy.argsort(v1) numpy.argsort(v2) // using ma.array sorting fails for both sort and argsort - note that the Inf is sorted to the same position as the masked values v3 = numpy.ma.array([na]+values+[na],mask=numpy.isnan([na]+values+[na])) numpy.sort(v3) numpy.argsort(v3) ``````

Open

Open

Member

### eric-wieser commented Apr 21, 2017

 Is this resolved by #8678?
Member

### eric-wieser commented Apr 21, 2017

 Looks good to me: ``````In [28]: np.sort(v3) Out[28]: masked_array(data = [-inf -1e+20 -0.3 0.0 1.0 2.0 100.0 5e+40 inf -- --], mask = [False False False False False False False False False True True], fill_value = 1e+20) ``````