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

Allow Any type to be used as an escape hatch #560

Merged
merged 1 commit into from Jun 23, 2022

Conversation

evansd
Copy link
Contributor

@evansd evansd commented Jun 21, 2022

This fixes a bug whereby attempting to select two columns of different types following a pick-one-row operation blows up with a type error.

The issue is that when we construct the internal query model node PickOoneRowPerPatientWithColumns we collect the selected column objects into a frozenset and make that a node attribute. Then, during type validation, we call get_typespec() on this attribute to determine its type specification. But this can't cope with sets containing more than one type (e.g. Series[bool] and Series[date]) so it blows up.

We could teach get_typespec() to be cleverer and work out the common ancestor class for heterogeneous sets like this. But that involves adding complexity to an already very complex system and I'm not sure there's sufficient benefit here. While strict type checking is essential for the public surface of the query model, I don't think it's so essential for the purely internal classes.

So instead we just ensure that the Any type functions as an escape hatch which shortcuts all the type checking behaviour and change the type annotation of the problematic attribute to Any.

@evansd evansd force-pushed the allow-any-type-escape-hatch branch from 994ff0d to 4465ee8 Compare June 21, 2022 21:19
@@ -20,7 +20,7 @@


class PickOneRowPerPatientWithColumns(PickOneRowPerPatient):
selected_columns: frozenset[Any]
selected_columns: Any
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 this could do with a comment to say that what the type should be, but that we can't easily enforce it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point

This fixes a bug whereby attempting to select two columns of different
types following a pick-one-row operation blows up with a type error.

The issue is that when we construct the internal query model node
`PickOoneRowPerPatientWithColumns` we collect the selected column
objects into a frozenset and make that a node attribute. Then,
during type validation, we call `get_typespec()` on this attribute to
determine its type specification. But this can't cope with sets
containing more than one type (e.g. `Series[bool]` and `Series[date]`)
so it blows up.

We _could_ teach `get_typespec()` to be cleverer and work out the common
ancestor class for heterogeneous sets like this. But that involves
adding complexity to an already very complex system and I'm not sure
there's sufficient benefit here. While strict type checking is essential
for the public surface of the query model, I don't think it's so
essential for the purely internal classes.

So instead we just ensure that the `Any` type functions as an escape
hatch which shortcuts all the type checking behaviour and change the
type annotation of the problematic attribute to `Any`.
@evansd evansd force-pushed the allow-any-type-escape-hatch branch from 4465ee8 to e39cdd6 Compare June 23, 2022 08:52
@evansd evansd enabled auto-merge June 23, 2022 08:55
@evansd evansd merged commit 7032a59 into main Jun 23, 2022
@evansd evansd deleted the allow-any-type-escape-hatch branch June 23, 2022 09:01
evansd added a commit that referenced this pull request Jun 24, 2022
I should have done this as part of the original PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants