-
Notifications
You must be signed in to change notification settings - Fork 4
🚀 Use Pydantic for Problem Definition #308
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,11 +21,18 @@ | |||||||||||||
| import csv | ||||||||||||||
| import json | ||||||||||||||
| import logging | ||||||||||||||
| import warnings | ||||||||||||||
| from pathlib import Path | ||||||||||||||
| from typing import Optional, Sequence, Union | ||||||||||||||
| from typing import Any, Dict, List, Optional, Sequence, Union | ||||||||||||||
|
|
||||||||||||||
| import yaml | ||||||||||||||
|
Comment on lines
+26
to
28
|
||||||||||||||
| from packaging.version import Version | ||||||||||||||
| from pydantic import ( | ||||||||||||||
| BaseModel, | ||||||||||||||
| ConfigDict, | ||||||||||||||
| Field, | ||||||||||||||
| field_validator, | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| import plaid | ||||||||||||||
| from plaid.constants import AUTHORIZED_SCORE_FUNCTIONS, AUTHORIZED_TASKS | ||||||||||||||
|
|
@@ -42,13 +49,46 @@ | |||||||||||||
| # %% Classes | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class ProblemDefinition(object): | ||||||||||||||
| class ProblemDefinition(BaseModel): | ||||||||||||||
| """Gathers all necessary informations to define a learning problem.""" | ||||||||||||||
|
|
||||||||||||||
| model_config = ConfigDict(arbitrary_types_allowed=True, extra="ignore") | ||||||||||||||
|
||||||||||||||
| model_config = ConfigDict(arbitrary_types_allowed=True, extra="ignore") | |
| model_config = ConfigDict( | |
| arbitrary_types_allowed=True, | |
| extra="ignore", | |
| validate_assignment=True, | |
| ) |
Copilot
AI
Feb 1, 2026
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.
The raise line is indented with an extra space, which violates the repo’s Ruff E111 indentation rule (indentation not a multiple of four). Align the indentation inside this if block.
Copilot
AI
Feb 1, 2026
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.
New behavior: task and score_function can now be validated via Pydantic on model construction. There are existing tests for set_task/set_score_function, but none covering ProblemDefinition(task=...) / ProblemDefinition(score_function=...) success and failure cases. Add tests to lock in the new validation path.
Copilot
AI
Feb 1, 2026
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.
Same indentation issue here: the raise statement has indentation that isn’t a multiple of four, which will be flagged by Ruff (E111).
Copilot
AI
Feb 1, 2026
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 error message refers to "authorized tasks" but this validator is for score_function. Update the message to mention authorized score functions (and ideally include AUTHORIZED_SCORE_FUNCTIONS).
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.
The docs claim tasks/score functions are "strictly enforced", but the current implementation can bypass Pydantic validation when values are assigned after initialization (e.g., when loading from disk) unless assignment validation is enabled. Either adjust the wording or ensure the implementation validates assignments during load.