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

[query] do not allow the creation of a field which classes with a necessary builtin #13495

Closed
danking opened this issue Aug 25, 2023 · 0 comments · Fixed by #13498
Closed

[query] do not allow the creation of a field which classes with a necessary builtin #13495

danking opened this issue Aug 25, 2023 · 0 comments · Fixed by #13498
Labels

Comments

@danking
Copy link
Contributor

danking commented Aug 25, 2023

What happened?

StructExpression s are Dict-like and we rely on this behavior for methods like .items(). We should probably ban the use of names like items so that you can always iterate over a struct expressions field names and field value expressions.

ht = ht.group_by(
    'gene'
).aggregate(
    items=hl.agg.take(ht.key, max(list(n_dict.values())), ordering = ht.rand_id)
)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_9677/3768472856.py in <cell line: 1>()
----> 1 ht = ht.group_by('gene').aggregate(items=hl.agg.take(ht.key, max(list(n_dict.values())), ordering = ht.rand_id))

<decorator-gen-1202> in aggregate(self, **named_exprs)

/opt/conda/miniconda3/lib/python3.10/site-packages/hail/typecheck/check.py in wrapper(__original_func, *args, **kwargs)
    582     def wrapper(__original_func, *args, **kwargs):
    583         args_, kwargs_ = check_all(__original_func, args, kwargs, checkers, is_method=is_method)
--> 584         return __original_func(*args_, **kwargs_)
    585
    586     return wrapper

/opt/conda/miniconda3/lib/python3.10/site-packages/hail/table.py in aggregate(self, **named_exprs)
    243
    244         key_struct = self._key_expr
--> 245         return Table(ir.TableKeyByAndAggregate(base._tir,
    246                                                hl.struct(**named_exprs)._ir,
    247                                                key_struct._ir,

/opt/conda/miniconda3/lib/python3.10/site-packages/hail/table.py in __init__(self, tir)
    365
    366         for k, v in itertools.chain(self._globals.items(),
--> 367                                     self._row.items()):
    368             self._set_field(k, v)
    369

TypeError: 'ArrayStructExpression' object is not callable

Version

0.2.120

Relevant log output

No response

@danking danking added the bug label Aug 25, 2023
danking pushed a commit that referenced this issue Sep 7, 2023
In particular, struct field names which clash with methods on
`StructExpression`.

close #13495

CHANGELOG: Fix a bug where field names can shadow methods on the
StructExpression class, e.g. "items", "keys", "values". Now the only way
to access such fields is through the getitem syntax, e.g.
"some_struct['items']". It's possible this could break existing code
that uses such field names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant