Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maxschulz-COL committed Jan 30, 2025
1 parent 1fde992 commit f6e3c76
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 18 deletions.
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ repos:
additional_dependencies: ["bandit[toml]"]

- repo: https://github.com/pre-commit/mirrors-mypy
# Upgrade to v1.11.1 not possible as it doesn't seem compatible with pydantic<2 plugin.
# Similar issue with previous v.1.11.X versions: https://github.com/pydantic/pydantic/issues/10000
# We need to revert the changes from the pre-commit autoupdate for now.
rev: v1.14.1
hooks:
- id: mypy
Expand Down
2 changes: 0 additions & 2 deletions vizro-core/examples/scratch_dev/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,3 @@

if __name__ == "__main__":
Vizro().build(dashboard).run()
# print(dashboard._to_python())
# print(dashboard.model_dump(context={"add_name": True}))
1 change: 0 additions & 1 deletion vizro-core/src/vizro/models/_action/_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class Action(VizroBaseModel):
description="Outputs in the form `<component_id>.<property>` changed by the action function.",
)

# Validators
_validate_function = field_validator("function", mode="before")(validate_captured_callable)

def _get_callback_mapping(self):
Expand Down
6 changes: 4 additions & 2 deletions vizro-core/src/vizro/models/_components/form/_form_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Helper functions for models inside form folder."""

from datetime import date
from typing import Any, Union
from typing import Any, Optional, Union

from pydantic import ValidationInfo

Expand Down Expand Up @@ -114,7 +114,9 @@ def validate_step(step, info: ValidationInfo):
return step


def set_default_marks(marks, info: ValidationInfo):
def set_default_marks(
marks: Optional[dict[Union[float, int], str]], info: ValidationInfo
) -> Optional[dict[Union[float, int], str]]:
if not marks and info.data.get("step") is None:
marks = None

Expand Down
6 changes: 3 additions & 3 deletions vizro-core/src/vizro/models/_components/form/range_slider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated, Literal, Optional
from typing import Annotated, Literal, Optional, Union

import dash_bootstrap_components as dbc
from dash import ClientsideFunction, Input, Output, State, clientside_callback, dcc, html
Expand Down Expand Up @@ -28,7 +28,7 @@ class RangeSlider(VizroBaseModel):
min (Optional[float]): Start value for slider. Defaults to `None`.
max (Optional[float]): End value for slider. Defaults to `None`.
step (Optional[float]): Step-size for marks on slider. Defaults to `None`.
marks (Optional[dict[float, str]]): Marks to be displayed on slider. Defaults to `{}`.
marks (Optional[dict[Union[float, int], str]]): Marks to be displayed on slider. Defaults to `{}`.
value (Optional[list[float]]): Default start and end value for slider. Must be 2 items. Defaults to `None`.
title (str): Title to be displayed. Defaults to `""`.
actions (list[Action]): See [`Action`][vizro.models.Action]. Defaults to `[]`.
Expand All @@ -46,7 +46,7 @@ class RangeSlider(VizroBaseModel):
Field(default=None, description="Step-size for marks on slider."),
]
marks: Annotated[
Optional[dict[float, str]],
Optional[dict[Union[float, int], str]],
AfterValidator(set_default_marks),
Field(default={}, description="Marks to be displayed on slider.", validate_default=True),
]
Expand Down
6 changes: 3 additions & 3 deletions vizro-core/src/vizro/models/_components/form/slider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated, Literal, Optional
from typing import Annotated, Literal, Optional, Union

import dash_bootstrap_components as dbc
from dash import ClientsideFunction, Input, Output, State, clientside_callback, dcc, html
Expand Down Expand Up @@ -28,7 +28,7 @@ class Slider(VizroBaseModel):
min (Optional[float]): Start value for slider. Defaults to `None`.
max (Optional[float]): End value for slider. Defaults to `None`.
step (Optional[float]): Step-size for marks on slider. Defaults to `None`.
marks (Optional[dict[float, str]]): Marks to be displayed on slider. Defaults to `{}`.
marks (Optional[dict[Union[float, int], str]]): Marks to be displayed on slider. Defaults to `{}`.
value (Optional[float]): Default value for slider. Defaults to `None`.
title (str): Title to be displayed. Defaults to `""`.
actions (list[Action]): See [`Action`][vizro.models.Action]. Defaults to `[]`.
Expand All @@ -46,7 +46,7 @@ class Slider(VizroBaseModel):
Field(default=None, description="Step-size for marks on slider."),
]
marks: Annotated[
Optional[dict[float, str]],
Optional[dict[Union[float, int], str]],
AfterValidator(set_default_marks),
Field(default={}, description="Marks to be displayed on slider.", validate_default=True),
]
Expand Down
4 changes: 2 additions & 2 deletions vizro-core/src/vizro/models/_controls/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
# Ideally we might define these as NumericalSelectorType = Union[RangeSlider, Slider] etc., but that will not work
# with isinstance checks.
# First entry in each tuple is the default selector for that column type.
# MS: For mypy we need to do this anyway - i have tried to make a function that takes the tuples and converts them, but
# I think it does not work
# MS: For mypy we need to do this anyway, see below - I have tried to make a function that takes the tuples and
# converts them in order to reuse code, but I think it does not work
SELECTORS = {
"numerical": (RangeSlider, Slider),
"categorical": (Dropdown, Checklist, RadioItems),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test_valid_marks(self, marks, expected):
]

def test_invalid_marks(self):
with pytest.raises(ValidationError, match="4 validation errors for RangeSlider"):
with pytest.raises(ValidationError, match="6 validation errors for RangeSlider"):
vm.RangeSlider(min=1, max=10, marks={"start": 0, "end": 10})

@pytest.mark.parametrize("step, expected", [(1, {}), (None, None)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_valid_marks(self, marks, expected):
]

def test_invalid_marks(self):
with pytest.raises(ValidationError, match="4 validation errors for Slider"):
with pytest.raises(ValidationError, match="6 validation errors for Slider"):
vm.Slider(min=1, max=10, marks={"start": 0, "end": 10})

@pytest.mark.parametrize("step, expected", [(1, {}), (None, None)])
Expand Down

0 comments on commit f6e3c76

Please sign in to comment.