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] frozendict #10105
[query] frozendict #10105
Conversation
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.
can you add a test to ensure we can correctly impute the type of these when we do hl.literal()
or something?
U = TypeVar("U") | ||
|
||
|
||
class frozendict(Mapping): |
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 think Mapping can take type arguments Mapping[T, U]
.
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.
typing.Dict
supports this, but typing.Mapping
doesn't seem to, unless I'm misreading. I'm new to the python type annotations stuff.
return len(self.d) | ||
|
||
def __iter__(self): | ||
return iter(self.d) |
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.
Can you add a repr:
def __repr__(self):
return f'frozendict({self.d!r})'
An object representing an immutable dictionary. | ||
|
||
>>> my_frozen_dict = hl.utils.frozendict({1:2, 7:5}) | ||
|
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.
Can you give an example of converting a frozendict back to a normal dict?
dict(frozendict({'a': 1, 'b': 2}))
…'t have a common setlike supertype
CHANGELOG: Evaluating hail expressions in python will now return
frozendict
, an immutable dictionary type. Sets will return python'sfrozenset
.This is necessary because hail supports hashable dicts, but python does not. Same with sets.