Skip to content
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

Improve json serde error in evalMetFromJson #380

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix metric class name
  • Loading branch information
gerashegalov committed Aug 7, 2019
commit ce76d38dd6e9ff73597343649bc7c95dcdb3eb0e
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ case object ModelSelectorSummary {
*/
private[selector] def evalMetFromJson(className: String, json: String): Try[EvaluationMetrics] = {
def error(c: Class[_], t: Throwable): Try[MultiMetrics] = Failure[MultiMetrics] {
new IllegalArgumentException(
s"""Could not extract metrics of type ${classOf[MultiMetrics]}
|from:$json""".stripMargin, t)
new IllegalArgumentException(s"Could not extract metrics of type $c from: $json", t)
}

ReflectionUtils.classForName(className) match {
case n if n == classOf[MultiMetrics] =>
JsonUtils.fromString[Map[String, Map[String, Any]]](json).map{ d =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class ModelSelectorSummaryTest extends FlatSpec with TestSparkContext {
val thr = intercept[IllegalArgumentException](ModelSelectorSummary.evalMetFromJson(
classOf[MultiClassificationMetrics].getName, corruptJson).get)

thr.getMessage should startWith ("Could not extract metrics of type class " +
"com.salesforce.op.evaluators.MultiClassificationMetrics from: {")

thr.getCause.getMessage shouldEqual "Unsupported format. Supported formats: json, yaml"
}
}