Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature/sbachmei/refactor observation registrations and other minor updates #437

Conversation

stevebachmeier
Copy link
Contributor

Refactor observation registrations and other minor updates

Description

  • Category: refactor, other
  • JIRA issue: na

Changes and notes

This PR is a sort of follow-on to the previous one because that one was

already getting a bit bloated. The primary change here is that it consolidates
the context and manager observation registration functions into a single
one. Note that we have kept explicit register_<type>_observation functions
exposed in interface.

There are a few other minor updates as well stemming from other comments
on the previous PR.

Most unique changes are contained in specific commits.

Testing

tests pass

@stevebachmeier stevebachmeier changed the base branch from main to epic/MIC-4968-results-processing June 20, 2024 20:34
when=when,
included_columns=["event_time"] + requires_columns + requires_values,
results_formatter=results_formatter,
if observation_type == ConcatenatingObservation:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the best way to do this? Alternatively I can add included_columns as a BaseObserver attribute that just defaults to an empty list everywhere

Copy link
Contributor

Choose a reason for hiding this comment

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

How about in results_interface.register_concatenating_observation()?

…vivarium into feature/sbachmei/refactor-observation-registrations-and-other-minor-updates
[pd.DataFrame, pd.DataFrame], pd.DataFrame
] = _raise_missing_stratified_observation_results_updater,
results_updater: Callable[[pd.DataFrame, pd.DataFrame], pd.DataFrame] = partial(
StratifiedObservation._raise_missing, "results_updater"
Copy link
Contributor

Choose a reason for hiding this comment

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

Upon reflection, isn't this error going to be thrown when the updater is called? Don't we want it to be thrown during registration instead? We could throw on registration if we define a default method (e.g. BaseObserver.foo) and then have this:

def register_stratified_observation(...):
    if results_updater == BaseObserver.foo:
        raise ValueError(...)

self._add_resources(requires_values, SourceType.VALUE)
observation_type,
is_stratified: bool,
**kwargs,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since name is required, should we include it as an explicit argument here? Same goes for requires_columns/values, which enable us not to need to del them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I'll include pop_filter and when as well (not precisely required b/c of defaults but is common among everything)

when=when,
included_columns=["event_time"] + requires_columns + requires_values,
results_formatter=results_formatter,
if observation_type == ConcatenatingObservation:
Copy link
Contributor

Choose a reason for hiding this comment

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

How about in results_interface.register_concatenating_observation()?

@@ -57,6 +64,10 @@ def __init__(
results_formatter=results_formatter,
)

@property
def stratifications(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be defined on BaseObservation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch - this is lingering from when I was trying to make @DataClass work for everything

@stevebachmeier stevebachmeier merged commit d8a97f8 into epic/MIC-4968-results-processing Jun 21, 2024
6 checks passed
@stevebachmeier stevebachmeier deleted the feature/sbachmei/refactor-observation-registrations-and-other-minor-updates branch June 21, 2024 20:08
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants