Skip to content

Commit 0a15ed6

Browse files
Checkpoint: project schema validations
1 parent 3a3a740 commit 0a15ed6

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

unboxapi/__init__.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from .projects import Project
3232
from .version import __version__
3333

34-
from .schemas import DatasetSchema, ModelSchema
34+
from .schemas import DatasetSchema, ModelSchema, ProjectSchema
3535
from marshmallow import ValidationError
3636

3737

@@ -86,6 +86,13 @@ def create_project(
8686
name: str,
8787
description: str,
8888
):
89+
# ----------------------------- Schema validation ---------------------------- #
90+
project_schema = ProjectSchema()
91+
try:
92+
project_schema.load({"name": name, "description": description})
93+
except ValidationError as err:
94+
raise UnboxValidationError(self._format_error_message(err))
95+
8996
endpoint = "initialize_project"
9097
payload = dict(
9198
name=name,
@@ -346,6 +353,15 @@ def add_model(
346353
>>> model.to_dict()
347354
"""
348355
# ---------------------------- Schema validations ---------------------------- #
356+
if task_type not in [
357+
TaskType.TabularClassification,
358+
TaskType.TextClassification,
359+
]:
360+
raise UnboxValidationError(
361+
"`task_type` must be either TaskType.TabularClassification or TaskType.TextClassification. \n"
362+
)
363+
if model_type not in []:
364+
pass
349365
model_schema = ModelSchema()
350366
try:
351367
model_schema.load(
@@ -711,14 +727,21 @@ def add_dataset(
711727
>>> dataset.to_dict()
712728
"""
713729
# ---------------------------- Schema validations ---------------------------- #
730+
if task_type not in [
731+
TaskType.TabularClassification,
732+
TaskType.TextClassification,
733+
]:
734+
raise UnboxValidationError(
735+
"`task_type` must be either TaskType.TabularClassification or TaskType.TextClassification. \n"
736+
)
714737
dataset_schema = DatasetSchema()
715738
try:
716739
dataset_schema.load(
717740
{
718741
"name": name,
719742
"file_path": file_path,
720-
"description": description,
721743
"task_type": task_type.value,
744+
"description": description,
722745
"class_names": class_names,
723746
"label_column_name": label_column_name,
724747
"tag_column_name": tag_column_name,

unboxapi/schemas.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@
77
)
88

99

10+
class ProjectSchema(Schema):
11+
name = name = fields.Str(
12+
required=True,
13+
validate=validate.Length(
14+
min=1,
15+
max=64,
16+
),
17+
)
18+
description = fields.Str(
19+
validate=validate.Length(
20+
min=1,
21+
max=140,
22+
),
23+
)
24+
25+
1026
class DatasetSchema(Schema):
1127
file_path = fields.Str()
1228
name = fields.Str(

0 commit comments

Comments
 (0)