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] frozendict #10105

Merged
merged 16 commits into from
Mar 1, 2021
Merged

[query] frozendict #10105

merged 16 commits into from
Mar 1, 2021

Conversation

johnc1231
Copy link
Contributor

CHANGELOG: Evaluating hail expressions in python will now return frozendict, an immutable dictionary type. Sets will return python's frozenset.

This is necessary because hail supports hashable dicts, but python does not. Same with sets.

Copy link
Contributor

@tpoterba tpoterba left a 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):
Copy link
Contributor

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].

Copy link
Contributor Author

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)
Copy link
Contributor

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})

Copy link
Contributor

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}))

@johnc1231
Copy link
Contributor Author

@danking @tpoterba Done everything you both asked for.

@danking danking merged commit c46d643 into hail-is:main Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants