Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Ann Zhang <ann.zhang@databricks.com>
  • Loading branch information
annzhang-db committed Dec 21, 2023
1 parent c11b78a commit 60c32ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions mlflow/models/evaluation/default_evaluator.py
Expand Up @@ -1468,7 +1468,7 @@ def _compute_builtin_metrics(self):
)

def _get_error_message_missing_columns(self, metric_name, param_names):
error_message_parts = [f"Metric '{metric_name}' requires the following:\n"]
error_message_parts = [f"Metric '{metric_name}' requires the following:"]

special_params = ["targets", "predictions"]
for param in special_params:
Expand All @@ -1479,10 +1479,10 @@ def _get_error_message_missing_columns(self, metric_name, param_names):

if remaining_params:
error_message_parts.append(
f" - missing columns {remaining_params} to be defined or mapped"
f" - missing columns {remaining_params} need to be defined or mapped"
)

return "".join(error_message_parts)
return "\n".join(error_message_parts)

def _check_args(self, metrics, eval_df):
failed_metrics = []
Expand Down
15 changes: 9 additions & 6 deletions tests/evaluate/test_default_evaluator.py
Expand Up @@ -2190,13 +2190,17 @@ def dummy_fn2(param_3, param_4, builtin_metrics):

error_message = (
r"Error: Metric calculation failed for the following metrics:\n"
r"Metric 'metric_1' requires the columns \['param_1', 'param_2'\]\n"
r"Metric 'metric_2' requires the columns \['param_3', 'builtin_metrics'\]\n\n"
r"Metric 'metric_1' requires the following:\n"
r"- the 'targets' parameter needs to be specified\n"
r"- missing columns \['param_1', 'param_2'\] need to be defined or mapped\n"
r"Metric 'metric_2' requires the following:\n"
r"- missing columns \['param_3', 'builtin_metrics'\] need to be defined or mapped\n\n"
r"Below are the existing column names for the input/output data:\n"
r"Input Columns: \['question', 'answer'\]\n"
r"Output Columns: \['predictions'\]\n"
r"To resolve this issue, you may want to map the missing column to an existing column\n"
r"using the following configuration:\n"
r"Output Columns: \['predictions'\]\n\n"
r"To resolve this issue, you may need to specify any required parameters, or if you are\n"
r"missing columns, you may want to map them to an existing column using the following\n"
r"configuration:\n"
r"evaluator_config=\{'col_mapping': \{<missing column name>: <existing column name>\}\}"
)

Expand All @@ -2208,7 +2212,6 @@ def dummy_fn2(param_3, param_4, builtin_metrics):
mlflow.evaluate(
model_info.model_uri,
data,
targets="answer",
evaluators="default",
model_type="question-answering",
extra_metrics=[metric_1, metric_2],
Expand Down

0 comments on commit 60c32ed

Please sign in to comment.