Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Open
josef-pkt opened this Issue · 1 comment

2 participants

@josef-pkt

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

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.