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

[Tidy] Improve code style in response models #626

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

lingyielia
Copy link
Contributor

@lingyielia lingyielia commented Aug 9, 2024

Description

Addressed 2 TODOs in controls.py, as per discussion with @maxschulz-COL, to make response models more consistent in styles

  1. make “_create_filter_proxy” a callable class
  2. instead of requesting the df_name, we should request the target component name, replace df_name with target_component_name, then later retrieve the df_name from the controllable components. This logic is more aligned with the Vizro usage pattern.

Plus 2 minor cleanup in components.py and layout.py

Screenshot

Notice

  • I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":

    • I submit this contribution under the Apache 2.0 license and represent that I am entitled to do so on behalf of myself, my employer, or relevant third parties, as applicable.
    • I certify that (a) this contribution is my original creation and / or (b) to the extent it is not my original creation, I am authorized to submit this contribution on behalf of the original creator(s) or their licensees.
    • I certify that the use of this contribution as authorized by the Apache 2.0 license does not violate the intellectual property rights of anyone else.
    • I have not referenced individuals, products or companies in any commits, directly or indirectly.
    • I have not added data or restricted code in any commits, directly or indirectly.

@github-actions github-actions bot added the Vizro-AI 🤖 Issue/PR that addresses Vizro-AI package label Aug 9, 2024
@lingyielia lingyielia self-assigned this Aug 9, 2024
@lingyielia lingyielia marked this pull request as ready for review August 9, 2024 19:37
Copy link
Contributor

@maxschulz-COL maxschulz-COL left a comment

Choose a reason for hiding this comment

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

Hey, thanks for tackling those already - here are my initial thoughts

Copy link
Contributor

Choose a reason for hiding this comment

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

I was more imagining something along the following lines:

from typing import Any


try:
    from pydantic.v1 import BaseModel, Field, create_model
except ImportError:  # pragma: no cov
    from pydantic import BaseModel, Field
    
class FooModel(BaseModel):
    foo: str
    bar: int = 123

class ProxyModel:
    def __new__(cls, color) -> Any:
        return create_model(
            'BarModel',
            apple='russet',
            banana=color,
            __base__=FooModel,
        )
        

Proxy = ProxyModel(color="orange")

print(Proxy.__fields__.keys())
print(Proxy.__fields__.values())

So in the above toy example, Proxy can just act as a normal response model no?

Comment on lines +102 to +115
def _get_target_df_name(self, components_plan, controllable_components):
target_controllable = set(self.target_components_id) & set(controllable_components)
df_names = {
component_plan.df_name
for component_plan in components_plan
if component_plan.component_id in target_controllable
}

if len(df_names) > 1:
logger.warning(
f"""
[FALLBACK] Multiple dataframes found in the target components: {df_names}.
Choose one dataframe to build the filter.
"""
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 I do not understand this. Should the logic not be:

  • model determines which components should be controlled
  • we then check if those components can be controlled, and take a subset at worst
  • the remaining dfs are what we get the metadata for (and the could be multiple no?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Vizro-AI 🤖 Issue/PR that addresses Vizro-AI package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants