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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions hail/python/hail/expr/functions.py
Expand Up @@ -266,6 +266,16 @@ def typecheck_expr(t, x):
.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
ehigham marked this conversation as resolved.
Show resolved Hide resolved
):
raise ValueError(
"'literal' cannot be used with hail expressions that depend "
"on other expressions. Use expression 'x' directly "
"instead of passing it to 'literal'."
)

return literal(hl.eval(to_expr(x, dtype)), dtype)

if x is None or x is pd.NA:
Expand Down
7 changes: 7 additions & 0 deletions hail/python/test/hail/expr/test_functions.py
Expand Up @@ -85,3 +85,10 @@ def test_array():

with pytest.raises(ValueError, match='array: only one dimensional ndarrays are supported: ndarray<float64, 2>'):
hl.eval(hl.array(hl.nd.array([[1.0], [2.0]])))


def test_literal_free_vars():
"Give better error messages in response to code written by ChatGPT"
array = hl.literal([1, 2, 3])
with pytest.raises(ValueError, match='expressions that depend on other expressions'):
array.map(hl.literal)