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] Add product option to index methods #5937

Merged
merged 9 commits into from May 6, 2019

Conversation

patrick-schultz
Copy link
Collaborator

@patrick-schultz patrick-schultz commented Apr 22, 2019

Add product option to Table.index, and MatrixTable.{index_rows, index_cols}. Supports interval joins. Refactored the index methods to reduce code duplication, and make them more consistent with each other. Only case not supporting product=True is annotating columns of a matrix table with an interval keyed table.

@patrick-schultz patrick-schultz changed the title [Hail][Feature] Add product option to Table.index [Hail][Feature] Add product option to index methods Apr 23, 2019
Copy link
Contributor

@tpoterba tpoterba left a comment

Choose a reason for hiding this comment

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

looks great, a few minor changes


def _compute_type(self):
child_typ = self.child.typ
if self.product:
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer the if/else to just compute the value type, without duplication of the rest

@@ -2726,6 +2726,8 @@ def index_rows(self, *exprs) -> 'StructExpression':
----------
exprs : variable-length args of :class:`.Expression`
Index expressions.
product : bool
If ``True``, value of expression is array of all matches.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we mark as experimental? Might want to change the name -- product seems like not quite the right word to communicate the concept.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree product is a bad name. What about all_matches or collect_matches?

Copy link
Contributor

Choose a reason for hiding this comment

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

Konrad?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe the simpler array=True?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, this only happens on intervals, right? Yeah, I like something that gets across all

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not just intervals. It also makes arrays of all rows with the matching key in the non-interval case.

right = right.select(i=hl.range(right.idx + 1, 5)).explode('i').key_by('i')
left = left.annotate_rows(matches=right.index(left.row_key, product=True))
rows = left.rows()
self.assertTrue(rows.all(rows.matches.length() == rows.row_idx))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test case here and in test_table.py that tests the content of the joined array, not just the length? Something like annotating the interval as a value (or adding the interval key to the annotated value in all cases) and checking that

tpoterba
tpoterba previously approved these changes Apr 25, 2019
@@ -1504,8 +1504,8 @@ def index(self, *exprs, product=False) -> 'Expression':
----------
exprs : variable-length args of :class:`.Expression`
Index expressions.
product : bool
If ``True``, value of expression is array of all matches.
all_matches : bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

You renamed it to all_matches, but in the downstream code it's still product

@tpoterba tpoterba dismissed their stale review April 25, 2019 15:51

oh yeah, name needs to be consistent

Copy link
Contributor

@tpoterba tpoterba left a comment

Choose a reason for hiding this comment

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

er, meant to request changes. need to fix names

@marksantcroos
Copy link
Contributor

Just letting know that this PR also addresses my issue in https://discuss.hail.is/t/annotate-matrixtable-with-count-from-another-table/950.

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.

None yet

5 participants