-
Notifications
You must be signed in to change notification settings - Fork 15
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
Sbachmei/mic 5549/mypy results context #538
Conversation
@@ -356,7 +356,7 @@ def _get_groups( | |||
) | |||
else: | |||
pop_groups = filtered_pop.groupby(lambda _: "all") | |||
return pop_groups | |||
return pop_groups # type: ignore[return-value] |
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.
Happy to talk about this. I think it's a discrepancy between mypy requiring DataFrameGroupBys to be generic and python RuntimeErroring w/ DataFrameGroupBy is not subscriptable. from __future__ import annotations
does not fix like it does for pd.Series.
@@ -301,7 +302,7 @@ def _bin_data(data: Union[pd.Series, pd.DataFrame]) -> pd.Series: | |||
|
|||
def register_observation( | |||
self, | |||
observation_type, | |||
observation_type: Type[BaseObservation], |
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.
This wasn't causing an error but it was just wrong. At this point we're sending in the class itself, NOT an instantiation of it (actually, it might be worth just saying observation_type: Type[StratifiedObservation | UnstratifiedObservation | AddingObservation | ConcatenatingObservation]
if folks prefer b/c that's what it really is. But they all inherit from BaseObservation so this is less typing.
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.
Should BaseObservation
be called Observation
?
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 we had it called that at once and changed it to this but now can't recall why. It does subclass from abc, though there are no abstract methods or anything on it. Probably doesn't matter?
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.
Type[C] is covariant, so I think putting in the base observation makes sense. It looks like there is a builtin type
you could use instead, though
@@ -301,7 +302,7 @@ def _bin_data(data: Union[pd.Series, pd.DataFrame]) -> pd.Series: | |||
|
|||
def register_observation( | |||
self, | |||
observation_type, | |||
observation_type: Type[BaseObservation], |
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.
Should BaseObservation
be called Observation
?
@@ -60,7 +59,8 @@ class BaseObservation(ABC): | |||
DataFrame or one with a complete set of stratifications as the index and | |||
all values set to 0.0.""" | |||
results_gatherer: Callable[ | |||
[pd.DataFrame | DataFrameGroupBy[str], tuple[str, ...] | None], pd.DataFrame |
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'm assuming the things in this file were just type-hinted incorrectly?
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.
Yeah, though I'm not gonna lie - I'm having trouble understanding how to type-hint DataFrameGroupBys...
Fix mypy errors in framework/results/context.py
Description
Changes and notes
Testing