Skip to content

Commit 38475dc

Browse files
Error message brush up
1 parent 1e1c002 commit 38475dc

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

unboxapi/__init__.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,10 @@ def add_model(
356356
raise UnboxValidationError(
357357
"`task_type` must be either TaskType.TabularClassification or TaskType.TextClassification. \n"
358358
)
359-
if model_type not in []:
360-
pass
359+
if model_type not in [model_framework for model_framework in ModelType]:
360+
raise UnboxValidationError(
361+
"`model_type` must be one of the supported ModelTypes. Check out our API reference for a full list https://reference.unbox.ai/reference/api/unboxapi.ModelType.html. \n"
362+
)
361363
model_schema = ModelSchema()
362364
try:
363365
model_schema.load(
@@ -386,14 +388,14 @@ def add_model(
386388
):
387389
raise UnboxResourceError(
388390
f"The file path `{requirements_txt_file}` specified on `requirements_txt_file` does not"
389-
" contain a file with the requirements ."
391+
" contain a file with the requirements. \n"
390392
)
391393

392394
# Setup script
393395
if setup_script and not os.path.isfile(os.path.expanduser(setup_script)):
394396
raise UnboxResourceError(
395397
f"The file path `{setup_script}` specified on `setup_script` does not"
396-
" contain a file with the bash script with commands required before model loading."
398+
" contain a file with the bash script with commands required before model loading. \n"
397399
)
398400

399401
# Dependent dir
@@ -467,7 +469,7 @@ def add_model(
467469
mitigation="Make sure to specify the additional kwargs needed for the model type.",
468470
)
469471

470-
# ----------------- Resource-schema consistency validations ---------------- #
472+
# ------------------ Resource-schema consistency validations ----------------- #
471473
# Feature validations
472474
if task_type in [TaskType.TabularClassification, TaskType.TabularRegression]:
473475
try:
@@ -483,7 +485,7 @@ def add_model(
483485
if feature not in headers
484486
]
485487
raise UnboxDatasetInconsistencyError(
486-
f"The features {features_not_in_dataset} specified as `feature_names` are not on the dataset. \n"
488+
f"The features {features_not_in_dataset} specified in `feature_names` are not on the dataset. \n"
487489
)
488490

489491
required_fields = [
@@ -497,7 +499,6 @@ def add_model(
497499
message=f"TabularClassification task with `{field}` missing. \n",
498500
mitigation=f"Make sure to specify `{field}` for tabular classification tasks.",
499501
)
500-
# --------------------- Subscription plan validations ---------------------- #
501502

502503
with TempDirectory() as dir:
503504
bento_service = create_template_model(
@@ -775,13 +776,13 @@ def add_dataset(
775776
+ " preprocessing steps expected by your model.",
776777
)
777778

778-
# ----------------- Resource-schema consistency validations ---------------- #
779+
# ------------------ Resource-schema consistency validations ----------------- #
779780
# Label column validations
780781
try:
781782
headers.index(label_column_name)
782783
except ValueError:
783784
raise UnboxDatasetInconsistencyError(
784-
f"The column {label_column_name} specified as `label_column_name` is not on the dataset. \n"
785+
f"The column `{label_column_name}` specified as `label_column_name` is not on the dataset. \n"
785786
)
786787

787788
dataset_classes = list(df[label_column_name].unique())
@@ -801,14 +802,14 @@ def add_dataset(
801802
except ValueError:
802803
if text_column_name:
803804
raise UnboxDatasetInconsistencyError(
804-
f"The column {text_column_name} specified as `text_column_name` is not on the dataset. \n"
805+
f"The column `{text_column_name}` specified as `text_column_name` is not on the dataset. \n"
805806
)
806807
else:
807808
features_not_in_dataset = [
808809
feature for feature in feature_names if feature not in headers
809810
]
810811
raise UnboxDatasetInconsistencyError(
811-
f"The features {features_not_in_dataset} specified as `feature_names` are not on the dataset. \n"
812+
f"The features {features_not_in_dataset} specified in `feature_names` are not on the dataset. \n"
812813
)
813814

814815
# Tag column validation
@@ -820,7 +821,7 @@ def add_dataset(
820821
f"The column `{tag_column_name}` specified as `tag_column_name` is not on the dataset. \n"
821822
)
822823

823-
# --------------------- Subscription plan validations ---------------------- #
824+
# ----------------------- Subscription plan validations ---------------------- #
824825
if row_count > self.subscription_plan["datasetSize"]:
825826
raise UnboxSubscriptionPlanException(
826827
f"The dataset your are trying to upload contains {row_count} rows, which exceeds your plan's"

unboxapi/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, message, context=None, mitigation=None):
5656
if not context:
5757
context = "You have reached your subscription plan's limits. \n"
5858
if not mitigation:
59-
mitigation = "To upgrade your plan, visit our website https://unbox.ai"
59+
mitigation = "To upgrade your plan, visit https://unbox.ai"
6060
super().__init__(context + message + mitigation)
6161

6262

unboxapi/schemas.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ValidationError,
66
validates_schema,
77
)
8+
from .models import ModelType
89

910

1011
class ProjectSchema(Schema):
@@ -80,7 +81,7 @@ def validates_label_column_not_in_feature_names(self, data, **kwargs):
8081
"""Validates whether the label column name is not on the feature names list"""
8182
if data["label_column_name"] in data["feature_names"]:
8283
raise ValidationError(
83-
f"The `label_column_name` {data['label_column_name']} must not be in `feature_names`."
84+
f"The `label_column_name` `{data['label_column_name']}` must not be in `feature_names`."
8485
)
8586

8687
@validates_schema
@@ -91,10 +92,12 @@ def validates_task_type_and_data_column(self, data, **kwargs):
9192
and "feature_names" not in data
9293
):
9394
raise ValidationError(
94-
"Must specify `feature_names` for TabularClassification."
95+
"Must specify `feature_names` for TabularClassification `task_type`. \n"
9596
)
9697
elif data["task_type"] == "text-classification" and "text_column" not in data:
97-
raise ValidationError("Must specify `text_column` for TextClassification.")
98+
raise ValidationError(
99+
"Must specify `text_column` for TextClassification. `task_type` \n"
100+
)
98101

99102

100103
class ModelSchema(Schema):
@@ -128,8 +131,8 @@ class ModelSchema(Schema):
128131
"invalid": "`model_type` is not valid. Make sure you are importing ModelType correctly."
129132
},
130133
validate=validate.OneOf(
131-
["SklearnModelArtifact", "hugging-face"],
132-
error=f"The `model_type` must be one of either ModelType.x or ModelType.y.",
134+
[model_framework.value for model_framework in ModelType],
135+
error=f"The `model_type` must be one of the supported frameworks. Check out our API reference for a full list https://reference.unbox.ai/reference/api/unboxapi.ModelType.html.\n ",
133136
),
134137
)
135138
class_names = fields.List(
@@ -159,25 +162,25 @@ class ModelSchema(Schema):
159162
@validates_schema
160163
def validate_custom_model_code(self, data, **kwargs):
161164
"""Validates the model type when `custom_code` is specified"""
162-
if data["model_type"] == "custom" and data["custom_model_code"] is None:
165+
if data["model_type"] == "Custom" and data["custom_model_code"] is None:
163166
raise ValidationError(
164-
"`model_type` must be ModelType.custom if specifying `custom_model_code`."
167+
"Must specify `custom_model_code` when using ModelType.custom. \n"
165168
)
166-
elif data["custom_model_code"] is not None and data["model_type"] != "custom":
169+
elif data["custom_model_code"] is not None and data["model_type"] != "Custom":
167170
raise ValidationError(
168-
"Must specify `custom_model_code` when using ModelType.custom"
171+
"`model_type` must be ModelType.custom if specifying `custom_model_code`. \n"
169172
)
170173

171174
@validates_schema
172175
def validate_custom_model_dependent_dir(self, data, **kwargs):
173-
if data["model_type"] == "custom" and data["dependent_dir"] is None:
176+
if data["model_type"] == "Custom" and data["dependent_dir"] is None:
174177
raise ValidationError(
175-
"Must specify `dependent_dir` when using ModelType.custom"
178+
"Must specify `dependent_dir` when using ModelType.custom. \n"
176179
)
177180

178181
@validates_schema
179182
def validate_custom_model_requirements(self, data, **kwargs):
180-
if data["model_type"] == "custom" and data["requirements_txt_file"] is None:
183+
if data["model_type"] == "Custom" and data["requirements_txt_file"] is None:
181184
raise ValidationError(
182-
"Must specify `requirements_txt_file` when using ModelType.custom"
185+
"Must specify `requirements_txt_file` when using ModelType.custom. \n"
183186
)

0 commit comments

Comments
 (0)