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

[hail][feature] Expose binary_search for numeric arrays. #6123

merged 2 commits into from May 27, 2019


Copy link

@tpoterba tpoterba commented May 16, 2019

No description provided.

if not c.can_coerce(elem.dtype):
raise TypeError(f"'binary_search': cannot search an array of type {array.dtype} for a value of type {elem.dtype}")
elem = c.coerce(elem)
return hl.switch(elem).when_missing(hl.null(hl.tint32)).default(_lower_bound(array, elem))
Copy link

@patrick-schultz patrick-schultz May 20, 2019

Is this always the right behavior regarding missingness? Might there be cases where the array contains some missing values (at the end), and the user would want the first missing index in that case (or the length of the array if there are no missing values)?

Actually, there are more issues than that if the array can contain missing values. We want to say "if all elements in array are smaller than elem, the returned value is the length of array", but it's really "if all non-missing elements in array are smaller than elem, the returned value is the index of the first missing value", which might be surprising.

At the least, we might make a warning about surprising behavior when the array contains missing values.

Copy link
Collaborator Author

@tpoterba tpoterba May 20, 2019

I think this is the right interface for general use, but others might disagree so perhaps we should mark this experimental for now. A warning sounds appropriate.

@danking danking merged commit 7e7ca42 into hail-is:master May 27, 2019
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants