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

Fix #13045 - Comparison of Structs and Struct Exprs #13226

Merged
merged 6 commits into from
Jul 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions hail/python/hail/expr/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,17 @@ def literal(x: Any, dtype: Optional[Union[HailType, str]] = None):
-------
:class:`.Expression`
"""
wrapper = {'has_expr': False}
wrapper = {'has_expr': False, 'has_free_vars': False}

def typecheck_expr(t, x):
if isinstance(x, Expression):
wrapper['has_expr'] = True
wrapper['has_free_vars'] = (
x._ir.free_vars.__len__() > 0 or
x._ir.free_agg_vars.__len__() > 0 or
x._ir.free_scan_vars.__len__() > 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be a |=, no?

Copy link
Collaborator Author

@ehigham ehigham Jul 7, 2023

Choose a reason for hiding this comment

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

no difference for positive integers?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean wrapper['has_free_vars'] |= .... Otherwise, if there are multiple nested expressions, and the last has no free variables but others do, we will only remember the False from the last.

Copy link
Collaborator Author

@ehigham ehigham Jul 7, 2023

Choose a reason for hiding this comment

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

Ah yes. Mutation. I forgot this can get called more than once

)

if x.dtype != t:
raise TypeError(f"'literal': type mismatch: expected '{t}', found '{x.dtype}'")
elif x._indices.source is not None:
Expand Down Expand Up @@ -265,17 +271,14 @@ def typecheck_expr(t, x):
raise TypeError("'literal': object did not match the passed type '{}'"
.format(dtype)) from e

if wrapper['has_expr']:
if ( x._ir.free_vars.__len__() > 0 or
x._ir.free_agg_vars.__len__() > 0 or
x._ir.free_scan_vars.__len__() > 0
):
raise ValueError(
"'literal' cannot be used with hail expressions that depend "
"on other expressions. Use expression 'x' directly "
"instead of passing it to 'literal'."
)
if wrapper['has_free_vars']:
raise ValueError(
"'literal' cannot be used with hail expressions that depend "
"on other expressions. Use expression 'x' directly "
"instead of passing it to 'literal'."
)

if wrapper['has_expr']:
return literal(hl.eval(to_expr(x, dtype)), dtype)

if x is None or x is pd.NA:
Expand Down