Skip to content

Commit

Permalink
allow None in eval response (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekorman authored Aug 22, 2024
1 parent ab45038 commit 18b08b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions api/tests/unit-tests/schemas/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,20 @@ def test_EvaluationResponse():
created_at=datetime.now(),
meta={},
)

# test validation for meta
er = schemas.EvaluationResponse(
id=1,
dataset_names=["ds"],
model_name="test",
filters=schemas.Filter(),
parameters=schemas.EvaluationParameters(
task_type=enums.TaskType.CLASSIFICATION,
),
status=enums.EvaluationStatus.DONE,
metrics=[],
confusion_matrices=[],
created_at=datetime.now(),
meta=None,
)
assert er.meta == {}
8 changes: 7 additions & 1 deletion api/valor_api/schemas/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class EvaluationResponse(BaseModel):
parameters: EvaluationParameters
status: EvaluationStatus
created_at: datetime.datetime
meta: dict[str, str | int | float] | None
meta: dict[str, str | int | float] | None = {}
metrics: list[Metric] | None = None
confusion_matrices: list[ConfusionMatrixResponse] | None = None
ignored_pred_labels: list[Label] | None = None
Expand All @@ -286,3 +286,9 @@ class EvaluationResponse(BaseModel):
model_config = ConfigDict(
extra="allow", protected_namespaces=("protected_",)
)

# make sure that `meta` is a dictionary
@field_validator("meta")
@classmethod
def null_to_empty_dict(cls, v):
return v or {}

0 comments on commit 18b08b7

Please sign in to comment.