Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ak.argsort returns floats #763

Closed
jrueb opened this issue Feb 22, 2021 · 1 comment · Fixed by #764
Closed

ak.argsort returns floats #763

jrueb opened this issue Feb 22, 2021 · 1 comment · Fixed by #764
Labels
bug The problem described is something that must be fixed

Comments

@jrueb
Copy link
Contributor

jrueb commented Feb 22, 2021

import awkward as ak
arr = ak.Array([[]])
print(ak.argsort(arr))

Will print <Array [[]] type='1 * var * float64'>, which has the value type float64 instead of int64. It works normally (returning int64) if arr is not empty. If you try to use this result to sort arr, you will get ValueError: only arrays of integers or booleans may be used as a slice.

Related to this I noticed that the following does not raise an error, even though argsort still returns floats here

arr = ak.Array([])
arr[ak.argsort(arr)]

I'm not sure if this is to be expected.

Tested on the latest git main (1.2.0rc2).

@jrueb jrueb added the bug (unverified) The problem described would be a bug, but needs to be triaged label Feb 22, 2021
@jpivarski jpivarski added bug The problem described is something that must be fixed and removed bug (unverified) The problem described would be a bug, but needs to be triaged labels Feb 22, 2021
@jpivarski
Copy link
Member

Thanks; that was just an oversight in the definition of EmptyArray::argsort_next.

The second example probably should be raising an error because the type is wrong—it certainly does when the array is not empty. It's complicated by the fact that EmptyArray declares itself to be an array of integers when used in a slice, but an array of floats when used in other contexts (except ak.argsort, after PR #764 goes through), though I think your example has an empty NumpyArray, rather than an EmptyArray. As for that case, I think it would be better for it to be picky about the type, even if the array is empty, but it's pretty low priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The problem described is something that must be fixed
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants