-
Notifications
You must be signed in to change notification settings - Fork 257
Add first and last methods to ArrayExpression #9474
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
Conversation
| >>> hl.eval(names.filter(lambda x: x.startswith('D')).tail()) | ||
| None | ||
| """ | ||
| return hl.rbind(self, hl.len(self), lambda x, n: hl.or_missing(n > 0, x[n - 1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blindly following the implementation of head with hl.rbind(self, .... Not sure why that is necessary.
hail/hail/python/hail/expr/expressions/typed_expressions.py
Lines 529 to 530 in e6ec5a2
| # FIXME: this should generate short-circuiting IR when that is possible | |
| return hl.rbind(self, lambda x: hl.case().when(x.length() > 0, x[0]).or_missing()) |
|
I guess we already have |
|
Good point @johnc1231, it would be nice to have the same interface for |
|
We just had a chat about this in Dev: https://hail.zulipchat.com/#narrow/stream/123011-Hail-Dev/topic/head.2Ftail.20vs.20first.2Flast/near/210522900 To summarize, I think |
|
We have a couple of deprecated things now, I think I'm going to go add a deprecation decorator so that people get warnings. |
|
Sounds good. Updated this PR to add |
|
Also, if this addition is approved, could someone comment on whether the hail/hail/python/hail/expr/expressions/typed_expressions.py Lines 529 to 530 in e6ec5a2
|
Should leave it for now, I think. Our common subexpression elimination pass would insert a binding, but it's not a bad idea to insert one explicitly in library code. The comment in the head() implementation refers to the fact that in many cases, we don't need to bind the entire array (suppose it's |
|
Restored the binding. Not sure what to do about this:
|
|
yeah, we don't have a way to avoid constructing the full array right now |
johnc1231
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add a test to ensure last works. You'll find a method called test_array_head in test_expr.py. I'd change that to test_array_first, call first instead. Then I'd add test_array_last and make sure there's a test for empty and nonempty arrays. Thanks
| >>> hl.eval(names.filter(lambda x: x.startswith('D')).first()) | ||
| None | ||
| """ | ||
| return hl.rbind(self, lambda x: hl.or_missing(hl.len(x) > 0, x[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd copy the FIXME comment down here, since it's still something we should address. I'd also then change head to just call first. That the logic only exists once, and any tests that may use head will now be tests for first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests were included in e2fcfb6. Are there more checks that should be added to those? |
|
You're good on tests, I was looking at the wrong thing. |
Add
firstmethod to ArrayExpression to replacehead. Addlastmethod as the counterpart tofirst.