Skip to content

Commit 7245b3e

Browse files
Improved error messages
1 parent e6fc911 commit 7245b3e

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

unboxapi/__init__.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,15 @@ def add_model(
412412
os.path.expanduser(requirements_txt_file)
413413
):
414414
raise UnboxResourceError(
415-
f"The file path `{requirements_txt_file}` specified on `requirements_txt_file` does not"
416-
" contain a file with the requirements. \n"
415+
f"File at path `{requirements_txt_file}` does not"
416+
" contain the requirements. \n"
417417
) from None
418418

419419
# Setup script
420420
if setup_script and not os.path.isfile(os.path.expanduser(setup_script)):
421421
raise UnboxResourceError(
422-
f"The file path `{setup_script}` specified on `setup_script` does not"
423-
" contain a file with the bash script with commands required before model loading. \n"
422+
f"File at path `{setup_script}` does not"
423+
" contain the bash script with commands required before model loading. \n"
424424
) from None
425425

426426
# Dependent dir
@@ -441,9 +441,8 @@ def add_model(
441441
if train_sample_df.isnull().values.any():
442442
raise UnboxResourceError(
443443
context="There is an issue with the specified `train_sample_df`. \n",
444-
message=f"The `train_sample_df` contains missing values. \n",
445-
mitigation="Currently, Unbox does not support datasets with missing values."
446-
+ "Make sure to upload a training set sample without missing values by applying the same"
444+
message=f"The `train_sample_df` contains missing values, which is currently not supported. \n",
445+
mitigation="Make sure to upload a training set sample without missing values by applying the same"
447446
+ " preprocessing steps expected by your model.",
448447
) from None
449448

@@ -454,7 +453,7 @@ def add_model(
454453
# predict_proba
455454
if not isinstance(function, Callable):
456455
raise UnboxValidationError(
457-
f"- The argument `{function}` specified as `function` is not callable. \n"
456+
f"- `{function}` specified as `function` is not callable. \n"
458457
) from None
459458

460459
user_args = function.__code__.co_varnames[: function.__code__.co_argcount][2:]
@@ -496,7 +495,7 @@ def add_model(
496495
if "tokenizer" not in kwargs:
497496
raise UnboxResourceError(
498497
context="There is a missing keyword argument for the specified model type. \n",
499-
message="The `tokenizer` must be specified in kwargs when using a transformers model. \n",
498+
message="`tokenizer` must be specified in kwargs when using a transformers model. \n",
500499
mitigation="Make sure to specify the additional kwargs needed for the model type.",
501500
) from None
502501

@@ -516,7 +515,7 @@ def add_model(
516515
if feature not in headers
517516
]
518517
raise UnboxDatasetInconsistencyError(
519-
f"The features {features_not_in_dataset} specified in `feature_names` are not on the dataset. \n"
518+
f"Features {features_not_in_dataset} specified in `feature_names` are not on the dataset. \n"
520519
) from None
521520

522521
required_fields = [
@@ -792,7 +791,7 @@ def add_dataset(
792791
object_name = "original.csv"
793792
if not os.path.isfile(exp_file_path):
794793
raise UnboxResourceError(
795-
f"The file path `{file_path}` specified on `file_path` does not contain a file with the dataset. \n"
794+
f"File at path `{file_path}` does not contain the dataset. \n"
796795
) from None
797796

798797
with open(exp_file_path, "rt") as f:
@@ -805,9 +804,8 @@ def add_dataset(
805804
if df.isnull().values.any():
806805
raise UnboxResourceError(
807806
context="There is an issue with the specified dataset. \n",
808-
message="The dataset contains missing values. \n",
809-
mitigation="Currently, Unbox does not support datasets with missing values."
810-
+ "Make sure to upload a training set sample without missing values by applying the same"
807+
message="The dataset contains missing values, which is currently not supported. \n",
808+
mitigation="Make sure to upload a training set sample without missing values by applying the same"
811809
+ " preprocessing steps expected by your model.",
812810
) from None
813811

@@ -817,13 +815,13 @@ def add_dataset(
817815
headers.index(label_column_name)
818816
except ValueError:
819817
raise UnboxDatasetInconsistencyError(
820-
f"The column `{label_column_name}` specified as `label_column_name` is not on the dataset. \n"
818+
f"`{label_column_name}` specified as `label_column_name` is not on the dataset. \n"
821819
) from None
822820

823821
dataset_classes = list(df[label_column_name].unique())
824822
if len(dataset_classes) > len(class_names):
825823
raise UnboxDatasetInconsistencyError(
826-
f"There are {len(dataset_classes)} classes represented on the dataset, but there are only"
824+
f"There are {len(dataset_classes)} classes represented on the dataset, but there are only "
827825
f"{len(class_names)} items on the `class_names` list. \n",
828826
mitigation=f"Make sure that there are at most {len(class_names)} classes in your dataset.",
829827
) from None
@@ -837,14 +835,14 @@ def add_dataset(
837835
except ValueError:
838836
if text_column_name:
839837
raise UnboxDatasetInconsistencyError(
840-
f"The column `{text_column_name}` specified as `text_column_name` is not on the dataset. \n"
838+
f"`{text_column_name}` specified as `text_column_name` is not on the dataset. \n"
841839
) from None
842840
else:
843841
features_not_in_dataset = [
844842
feature for feature in feature_names if feature not in headers
845843
]
846844
raise UnboxDatasetInconsistencyError(
847-
f"The features {features_not_in_dataset} specified in `feature_names` are not on the dataset. \n"
845+
f"Features {features_not_in_dataset} specified in `feature_names` are not on the dataset. \n"
848846
) from None
849847

850848
# Tag column validation
@@ -853,7 +851,7 @@ def add_dataset(
853851
headers.index(tag_column_name)
854852
except ValueError:
855853
raise UnboxDatasetInconsistencyError(
856-
f"The column `{tag_column_name}` specified as `tag_column_name` is not on the dataset. \n"
854+
f"`{tag_column_name}` specified as `tag_column_name` is not on the dataset. \n"
857855
) from None
858856

859857
# ----------------------- Subscription plan validations ---------------------- #

unboxapi/schemas.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ModelSchema(Schema):
4646
},
4747
validate=validate.OneOf(
4848
["text-classification", "tabular-classification"],
49-
error=f"The `task_type` must be one of either TaskType.TextClassification or TaskType.TabularClassification.",
49+
error=f"`task_type` must be one of either TaskType.TextClassification or TaskType.TabularClassification.",
5050
),
5151
)
5252
model_type = fields.Str(
@@ -56,7 +56,7 @@ class ModelSchema(Schema):
5656
},
5757
validate=validate.OneOf(
5858
[model_framework.value for model_framework in ModelType],
59-
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 ",
59+
error=f"`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 ",
6060
),
6161
)
6262
class_names = fields.List(
@@ -88,25 +88,25 @@ def validate_custom_model_code(self, data, **kwargs):
8888
"""Validates the model type when `custom_code` is specified"""
8989
if data["model_type"] == "Custom" and data["custom_model_code"] is None:
9090
raise ValidationError(
91-
"Must specify `custom_model_code` when using ModelType.custom. \n"
91+
"ModelType.custom without `custom_model_code`. Must specify `custom_model_code` when using ModelType.custom. \n"
9292
)
9393
elif data["custom_model_code"] is not None and data["model_type"] != "Custom":
9494
raise ValidationError(
95-
"`model_type` must be ModelType.custom if specifying `custom_model_code`. \n"
95+
"Incompatible `model_type` for `custom_model_code`. `model_type` must be ModelType.custom if specifying `custom_model_code`. \n"
9696
)
9797

9898
@validates_schema
9999
def validate_custom_model_dependent_dir(self, data, **kwargs):
100100
if data["model_type"] == "Custom" and data["dependent_dir"] is None:
101101
raise ValidationError(
102-
"Must specify `dependent_dir` when using ModelType.custom. \n"
102+
"`dependent_dir` not specified with ModelType.custom. Must specify `dependent_dir` when using ModelType.custom. \n"
103103
)
104104

105105
@validates_schema
106106
def validate_custom_model_requirements(self, data, **kwargs):
107107
if data["model_type"] == "Custom" and data["requirements_txt_file"] is None:
108108
raise ValidationError(
109-
"Must specify `requirements_txt_file` when using ModelType.custom. \n"
109+
"`requirements_txt_file` not specified with ModelType.custom. Must specify `requirements_txt_file` when using ModelType.custom. \n"
110110
)
111111

112112

@@ -132,7 +132,7 @@ class DatasetSchema(Schema):
132132
},
133133
validate=validate.OneOf(
134134
["text-classification", "tabular-classification"],
135-
error=f"The `task_type` must be one of either TaskType.TextClassification or TaskType.TabularClassification.",
135+
error=f"`task_type` must be one of either TaskType.TextClassification or TaskType.TabularClassification.",
136136
),
137137
)
138138
tag_column_name = fields.List(
@@ -147,7 +147,7 @@ class DatasetSchema(Schema):
147147
default="en",
148148
validate=validate.Regexp(
149149
r"^[a-z]{2}(-[A-Z]{2})?$",
150-
error="The `language` of the dataset is not in the ISO 639-1 (alpha-2 code) format.",
150+
error="`language` of the dataset is not in the ISO 639-1 (alpha-2 code) format.",
151151
),
152152
)
153153
sep = fields.Str()
@@ -167,21 +167,21 @@ def validates_label_column_not_in_feature_names(self, data, **kwargs):
167167
"""Validates whether the label column name is not on the feature names list"""
168168
if data["label_column_name"] in data["feature_names"]:
169169
raise ValidationError(
170-
f"The `label_column_name` `{data['label_column_name']}` must not be in `feature_names`."
170+
f"`label_column_name` `{data['label_column_name']}` must not be in `feature_names`."
171171
)
172172

173173
@validates_schema
174174
def validates_task_type_and_data_column(self, data, **kwargs):
175175
"""Validates whether the data columns are present according to the task type"""
176176
if data["task_type"] == "tabular-classification" and not data["feature_names"]:
177177
raise ValidationError(
178-
"Must specify `feature_names` for TabularClassification `task_type`."
178+
"`feature_names` not specified for tabular classification task. Must specify `feature_names` for TabularClassification `task_type`."
179179
)
180180
elif (
181181
data["task_type"] == "text-classification" and not data["text_column_name"]
182182
):
183183
raise ValidationError(
184-
"Must specify `text_column_name` for TextClassification `task_type`."
184+
"`text_column_name` not specified for text classification task. Must specify `text_column_name` for TextClassification `task_type`."
185185
)
186186
elif data["feature_names"] and data["text_column_name"]:
187187
if data["task_type"] == "tabular-classification":

0 commit comments

Comments
 (0)