Skip to content

Commit

Permalink
Use tuple instead of list in validation options
Browse files Browse the repository at this point in the history
This enesures that this type can be serialized.
  • Loading branch information
naddeoa committed Mar 25, 2024
1 parent 8b07401 commit 250e7e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions langkit/validators/comparison.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass, replace
from functools import partial
from typing import Any, Callable, List, Literal, Optional, Sequence, Set, Union
from typing import Any, Callable, List, Literal, Optional, Sequence, Set, Tuple, Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -208,7 +208,7 @@ def validate_result(self, df: pd.DataFrame) -> Optional[ValidationResult]:

@dataclass
class MultiColumnConstraintValidatorOptions:
constraints: List[ConstraintValidatorOptions]
constraints: Tuple[ConstraintValidatorOptions, ...]
operator: Literal["AND", "OR"] = "AND"
report_mode: Literal["ALL_FAILED_METRICS", "FIRST_FAILED_METRIC"] = "FIRST_FAILED_METRIC"

Expand Down
2 changes: 1 addition & 1 deletion langkit/validators/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ def multi_column_constraint(
report_mode: Literal["ALL_FAILED_METRICS", "FIRST_FAILED_METRIC"] = "FIRST_FAILED_METRIC",
) -> Validator:
return MultiColumnConstraintValidator(
MultiColumnConstraintValidatorOptions(constraints=constraints, operator=operator, report_mode=report_mode)
MultiColumnConstraintValidatorOptions(constraints=tuple(constraints), operator=operator, report_mode=report_mode)
)
24 changes: 12 additions & 12 deletions tests/langkit/validators/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ def test_must_be_non_none():
def test_multiple_contraint_first_failure():
validator = MultiColumnConstraintValidator(
MultiColumnConstraintValidatorOptions(
[
(
ConstraintValidatorOptions("prompt.stats.char_count", lower_threshold=5),
ConstraintValidatorOptions("prompt.stats.token_count", lower_threshold=5),
]
)
)
)
wf = Workflow(
Expand Down Expand Up @@ -188,10 +188,10 @@ def test_multiple_contraint_first_failure():
def test_multiple_constriant_all_failure():
validator = MultiColumnConstraintValidator(
MultiColumnConstraintValidatorOptions(
[
(
ConstraintValidatorOptions("prompt.stats.char_count", lower_threshold=5),
ConstraintValidatorOptions("prompt.stats.token_count", lower_threshold=5),
],
),
report_mode="ALL_FAILED_METRICS",
operator="AND",
)
Expand Down Expand Up @@ -234,10 +234,10 @@ def test_multiple_constriant_all_failure():
def test_multiple_constriant_all_failure_or():
validator = MultiColumnConstraintValidator(
MultiColumnConstraintValidatorOptions(
[
(
ConstraintValidatorOptions("prompt.stats.char_count", lower_threshold=4),
ConstraintValidatorOptions("prompt.stats.token_count", lower_threshold=4),
],
),
report_mode="ALL_FAILED_METRICS",
operator="OR",
)
Expand Down Expand Up @@ -268,10 +268,10 @@ def test_multiple_constriant_all_failure_or():
def test_multiple_constriant_first_failure_or():
validator = MultiColumnConstraintValidator(
MultiColumnConstraintValidatorOptions(
[
(
ConstraintValidatorOptions("prompt.stats.char_count", lower_threshold=4),
ConstraintValidatorOptions("prompt.stats.token_count", lower_threshold=4),
],
),
report_mode="FIRST_FAILED_METRIC",
operator="OR",
)
Expand Down Expand Up @@ -302,11 +302,11 @@ def test_multiple_constriant_first_failure_or():
def test_multiple_constriant_first_failure_or_multiple_failures():
validator = MultiColumnConstraintValidator(
MultiColumnConstraintValidatorOptions(
[
(
ConstraintValidatorOptions("prompt.stats.char_count", upper_threshold=100),
ConstraintValidatorOptions("prompt.stats.token_count", upper_threshold=1),
ConstraintValidatorOptions("prompt.regex.email_address", upper_threshold=0),
],
),
report_mode="FIRST_FAILED_METRIC",
operator="OR",
)
Expand Down Expand Up @@ -338,11 +338,11 @@ def test_multiple_constriant_first_failure_or_multiple_failures():
def test_multiple_constriant_first_failure_and_ordering():
validator = MultiColumnConstraintValidator(
MultiColumnConstraintValidatorOptions(
[
(
ConstraintValidatorOptions("prompt.regex.email_address", upper_threshold=0),
ConstraintValidatorOptions("prompt.stats.char_count", upper_threshold=1),
ConstraintValidatorOptions("prompt.stats.token_count", upper_threshold=1),
],
),
report_mode="FIRST_FAILED_METRIC",
operator="AND",
)
Expand Down

0 comments on commit 250e7e8

Please sign in to comment.