-
Notifications
You must be signed in to change notification settings - Fork 145
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
[Tidy] Convert actions to classes #363
base: dev/actions_v2
Are you sure you want to change the base?
Conversation
… and arguments preparation
for more information, see https://pre-commit.ci
…izro into tidy/actions_to_class
for more information, see https://pre-commit.ci
|
||
|
||
class ExportDataClassAction(CapturedActionCallable): | ||
def __init__(self, *args, **kwargs): |
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.
What's this __init__
for?
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 used it to save input args and kwargs so they can be validated/adjusted in the _post_init
.
Now, I got rid of the constructor and self._arguments
is used inside the _post_init
.
if self.inputs: | ||
callback_inputs = [State(*input.split(".")) for input in self.inputs] | ||
elif hasattr(self.function, "inputs") and self.function.inputs: |
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 guess we're going to have a few switches here while we have both the "old" function actions and the new class ones.
Let's have a consistent way of doing this everywhere to make it clearer. I think just isinstance(function, CapturedActionCallable)
would work? No need to check if self.function.inputs
is False
y or not I think either.
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 guess we're going to have a few switches here while we have both the "old" function actions and the new class ones.
You're right, and after all actions become implemented as CapturedActionCallable, then the following line will be removed:
else: callback_inputs = _get_action_callback_mapping(action_id=ModelID(str(self.id)), argument="inputs")
|
||
# Validate and calculate "targets" | ||
targets = self._kwargs.get("targets") | ||
if targets: |
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 feels like an improvement on the old function version because we now validate targets
upfront rather than at runtime. Is that right?
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.
Yep, that's right! 😄
# Fake initialization - to let other actions see that this one exists. | ||
super().__init__(*args, **kwargs) | ||
|
||
def _post_init(self): |
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 this be called directly in __init__
or is that too early?
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.
It's too early to call _post_init
validation inside the action initialisation phase. To be able to validate action input arguments properly, all dashboard models have to be initialised. Some of the models are initialised in the _pre_build
phase of other models which means that the actions _post_init
has to be called within the build phase.
raise ValueError(f"Component '{target}' does not exist on the page '{self._page_id}'.") | ||
else: | ||
targets = model_manager._get_page_model_ids_with_figure(page_id=self._page_id) | ||
self._kwargs["targets"] = self.targets = targets |
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.
Not sure I understand what's happening with the _kwargs
stuff here, please could you explain?
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.
Now this line looks like this:
self._arguments["targets"] = self.targets = targets
targets
- represents new validated and calculated action's targetsself._arguments["targets"] = targets
- overwrites thepure_function
input argument. Since the pure_function is a staticmethod (and I'm pretty sure it should remain), new calculated targets have to be propagated through theself._arguments
.self.targets = targets
- Optionally, some of CapturedActionCallable attributes are also calculated in the _post_init phase. In this case,self.targets
is created calculated so it can be easily reused inside theoutputs and
components` calculations.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…izro into tidy/actions_to_class
for more information, see https://pre-commit.ci
Description
For those who will review this PR:
Here is a small recommendation on how to familiarise yourself with the PR changes in the fastest way and how to review the PR. It is only a recommendation and feel free to skip some of the suggested steps if you are already familiar with them or if you are not interested in them.
vizro-core/examples/_dev/
folder. They are already sorted alphabetically in the way they should run. For each example: read file docstrings, explore application configuration, and run and play with application UI.CapturedActionCallable
→ useful Gist that @antonymilne made: https://gist.github.com/antonymilne/174c4c49ace2dae1f1d7674183b8d140Link to the PS session -> https://mckinsey.box.com/s/fg1sdrpw6emprihhtg19ww4lft2ljma8
export_data_action
)TODO-AV2
and read everything. (especially since some "TODO-AV2" refer to multiple similar pieces of code, but are only written in one place)This PR is in the MVP phase because:
The most important changes:
filter_action
andparameter_action
public,_on_page_load
with a publicupdate_figures
action.Page.actions
so it can be overwritten.model_manager._get_model_page_id
method improvedBugfixes:
ControlType
#376) (model_manager._get_page_actions_chains
improved)export_data
is not able anymore to export data from other pages anymore (the bug is not spotted earlier and is fixed in this PR),TODO-AV2 legend:
TODO-AV2
- I will solve these as the part of this PR,TODO-AV2-OQ
- Open Questions,TODO-AV2-TICKET-CREATED
- These will be solved as a separate PR, and the ticket for these is already created,TODO-AV2-TICKET-NEW
- These will be solved as a separate PR, and the following tickets have to be created,*
- tagged TODOs (contain the characters-*:
) are candidate for solving by anyone from the team.PR TODOs:
Notice
I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":