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
merged 2 commits into from
May 27, 2019

Conversation

tpoterba
Copy link
Contributor

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
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants