[query] frozendict - #10105
Merged
Merged
[query] frozendict#10105
Conversation
tpoterba
previously requested changes
Feb 25, 2021
tpoterba
left a comment
Contributor
There was a problem hiding this comment.
can you add a test to ensure we can correctly impute the type of these when we do hl.literal() or something?
danking
suggested changes
Feb 25, 2021
| U = TypeVar("U") | ||
|
|
||
|
|
||
| class frozendict(Mapping): |
Contributor
There was a problem hiding this comment.
I think Mapping can take type arguments Mapping[T, U].
Contributor
Author
There was a problem hiding this comment.
typing.Dict supports this, but typing.Mapping doesn't seem to, unless I'm misreading. I'm new to the python type annotations stuff.
danking
previously requested changes
Feb 25, 2021
| return len(self.d) | ||
|
|
||
| def __iter__(self): | ||
| return iter(self.d) |
Contributor
There was a problem hiding this comment.
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}) | ||
|
|
Contributor
There was a problem hiding this comment.
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
Contributor
Author
tpoterba
approved these changes
Mar 1, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.