Skip to content

Commit

Permalink
[SPARK-9720] [ML] Identifiable types need UID in toString methods
Browse files Browse the repository at this point in the history
A few Identifiable types did override their toString method but without using the parent implementation. As a consequence, the uid was not present anymore in the toString result. It is the default behaviour.

This patch is a quick fix. The question of enforcement is still up.

No tests have been written to verify the toString method behaviour. That would be long to do because all types should be tested and not only those which have a regression now.

It is possible to enforce the condition using the compiler by making the toString method final but that would introduce unwanted potential API breaking changes (see jira).

Author: Bertrand Dechoux <BertrandDechoux@users.noreply.github.com>

Closes #8062 from BertrandDechoux/SPARK-9720.
  • Loading branch information
BertrandDechoux authored and srowen committed Sep 14, 2015
1 parent 1dc614b commit d815654
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ final class DecisionTreeClassificationModel private[ml] (
}

override def toString: String = {
s"DecisionTreeClassificationModel of depth $depth with $numNodes nodes"
s"DecisionTreeClassificationModel (uid=$uid) of depth $depth with $numNodes nodes"
}

/** (private[ml]) Convert to a model in the old API */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ final class GBTClassificationModel(
}

override def toString: String = {
s"GBTClassificationModel with $numTrees trees"
s"GBTClassificationModel (uid=$uid) with $numTrees trees"
}

/** (private[ml]) Convert to a model in the old API */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class NaiveBayesModel private[ml] (
}

override def toString: String = {
s"NaiveBayesModel with ${pi.size} classes"
s"NaiveBayesModel (uid=$uid) with ${pi.size} classes"
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ final class RandomForestClassificationModel private[ml] (
}

override def toString: String = {
s"RandomForestClassificationModel with $numTrees trees"
s"RandomForestClassificationModel (uid=$uid) with $numTrees trees"
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class RFormula(override val uid: String) extends Estimator[RFormulaModel] with R

override def copy(extra: ParamMap): RFormula = defaultCopy(extra)

override def toString: String = s"RFormula(${get(formula)})"
override def toString: String = s"RFormula(${get(formula)}) (uid=$uid)"
}

/**
Expand Down Expand Up @@ -171,7 +171,7 @@ class RFormulaModel private[feature](
override def copy(extra: ParamMap): RFormulaModel = copyValues(
new RFormulaModel(uid, resolvedFormula, pipelineModel))

override def toString: String = s"RFormulaModel(${resolvedFormula})"
override def toString: String = s"RFormulaModel(${resolvedFormula}) (uid=$uid)"

private def transformLabel(dataset: DataFrame): DataFrame = {
val labelName = resolvedFormula.label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ final class DecisionTreeRegressionModel private[ml] (
}

override def toString: String = {
s"DecisionTreeRegressionModel of depth $depth with $numNodes nodes"
s"DecisionTreeRegressionModel (uid=$uid) of depth $depth with $numNodes nodes"
}

/** Convert to a model in the old API */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ final class GBTRegressionModel(
}

override def toString: String = {
s"GBTRegressionModel with $numTrees trees"
s"GBTRegressionModel (uid=$uid) with $numTrees trees"
}

/** (private[ml]) Convert to a model in the old API */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ final class RandomForestRegressionModel private[ml] (
}

override def toString: String = {
s"RandomForestRegressionModel with $numTrees trees"
s"RandomForestRegressionModel (uid=$uid) with $numTrees trees"
}

/**
Expand Down

0 comments on commit d815654

Please sign in to comment.