Skip to content

Commit fbc39f0

Browse files
committed
pass test:compile
1 parent 108937e commit fbc39f0

File tree

12 files changed

+45
-32
lines changed

12 files changed

+45
-32
lines changed

mllib/src/test/java/org/apache/spark/ml/classification/JavaLogisticRegressionSuite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void logisticRegressionWithSetters() {
8484
.setThreshold(0.6)
8585
.setProbabilityCol("myProbability");
8686
LogisticRegressionModel model = lr.fit(dataset);
87-
LogisticRegression parent = model.parent();
87+
LogisticRegression parent = (LogisticRegression) model.parent();
8888
assert(parent.getMaxIter() == 10);
8989
assert(parent.getRegParam() == 1.0);
9090
assert(parent.getThreshold() == 0.6);
@@ -110,7 +110,7 @@ public void logisticRegressionWithSetters() {
110110
// Call fit() with new params, and check as many params as we can.
111111
LogisticRegressionModel model2 = lr.fit(dataset, lr.maxIter().w(5), lr.regParam().w(0.1),
112112
lr.threshold().w(0.4), lr.probabilityCol().w("theProb"));
113-
LogisticRegression parent2 = model2.parent();
113+
LogisticRegression parent2 = (LogisticRegression) model2.parent();
114114
assert(parent2.getMaxIter() == 5);
115115
assert(parent2.getRegParam() == 0.1);
116116
assert(parent2.getThreshold() == 0.4);

mllib/src/test/java/org/apache/spark/ml/param/JavaTestParams.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,30 @@
2121

2222
import com.google.common.collect.Lists;
2323

24+
import org.apache.spark.ml.util.Identifiable$;
25+
2426
/**
2527
* A subclass of Params for testing.
2628
*/
2729
public class JavaTestParams extends JavaParams {
2830

31+
public JavaTestParams() {
32+
this._uid = Identifiable$.MODULE$.randomUID("javaTestParams");
33+
_init();
34+
}
35+
36+
public JavaTestParams(String uid) {
37+
this._uid = uid;
38+
_init();
39+
}
40+
41+
private String _uid;
42+
43+
@Override
44+
public String uid() {
45+
return _uid;
46+
}
47+
2948
public IntParam myIntParam;
3049

3150
public int getMyIntParam() { return (Integer)getOrDefault(myIntParam); }
@@ -50,7 +69,7 @@ public JavaTestParams setMyStringParam(String value) {
5069
set(myStringParam, value); return this;
5170
}
5271

53-
public JavaTestParams() {
72+
private void _init() {
5473
myIntParam = new IntParam(this, "myIntParam", "this is an int param", ParamValidators.gt(0));
5574
myDoubleParam = new DoubleParam(this, "myDoubleParam", "this is a double param",
5675
ParamValidators.inRange(0.0, 1.0));

mllib/src/test/java/org/apache/spark/ml/regression/JavaLinearRegressionSuite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ public void linearRegressionWithSetters() {
7777
.setMaxIter(10)
7878
.setRegParam(1.0);
7979
LinearRegressionModel model = lr.fit(dataset);
80-
LinearRegression parent = model.parent();
80+
LinearRegression parent = (LinearRegression) model.parent();
8181
assertEquals(10, parent.getMaxIter());
8282
assertEquals(1.0, parent.getRegParam(), 0.0);
8383

8484
// Call fit() with new params, and check as many params as we can.
8585
LinearRegressionModel model2 =
8686
lr.fit(dataset, lr.maxIter().w(5), lr.regParam().w(0.1), lr.predictionCol().w("thePred"));
87-
LinearRegression parent2 = model2.parent();
87+
LinearRegression parent2 = (LinearRegression) model2.parent();
8888
assertEquals(5, parent2.getMaxIter());
8989
assertEquals(0.1, parent2.getRegParam(), 0.0);
9090
assertEquals("thePred", model2.getPredictionCol());

mllib/src/test/java/org/apache/spark/ml/util/IdentifiableSuite.scala

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,20 @@ import org.scalatest.FunSuite
2121

2222
class IdentifiableSuite extends FunSuite {
2323

24-
import IdentifiableSuite._
24+
import IdentifiableSuite.Test
2525

2626
test("Identifiable") {
27-
val test0 = new Test0
28-
assert(test0.uid.startsWith(classOf[Test0].getSimpleName + "_"))
29-
30-
val test1 = new Test1
31-
assert(test1.uid.startsWith("test_"),
32-
"simpleClassName should be the first part of the generated UID.")
33-
val copied = test1.copy
34-
assert(copied.uid === test1.uid, "Copied objects should be able to use the same UID.")
27+
val test0 = new Test("test_0")
28+
assert(test0.uid === "test_0")
29+
30+
val test1 = new Test
31+
assert(test1.uid.startsWith("test_"))
3532
}
3633
}
3734

3835
object IdentifiableSuite {
3936

40-
class Test0 extends Identifiable
41-
42-
class Test1 extends Identifiable {
43-
44-
override def simpleClassName: String = "test"
45-
46-
def copy: Test1 = {
47-
new Test1().setUID(uid)
48-
}
37+
class Test(override val uid: String) extends Identifiable {
38+
def this() = this(Identifiable.randomUID("test"))
4939
}
5040
}

mllib/src/test/scala/org/apache/spark/ml/classification/DecisionTreeClassifierSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private[ml] object DecisionTreeClassifierSuite extends FunSuite {
268268
val newTree = dt.fit(newData)
269269
// Use parent, fittingParamMap from newTree since these are not checked anyways.
270270
val oldTreeAsNew = DecisionTreeClassificationModel.fromOld(
271-
oldTree, newTree.parent, categoricalFeatures)
271+
oldTree, newTree.parent.asInstanceOf[DecisionTreeClassifier], categoricalFeatures)
272272
TreeTests.checkEqual(oldTreeAsNew, newTree)
273273
}
274274
}

mllib/src/test/scala/org/apache/spark/ml/classification/GBTClassifierSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private object GBTClassifierSuite {
130130
val newModel = gbt.fit(newData)
131131
// Use parent, fittingParamMap from newTree since these are not checked anyways.
132132
val oldModelAsNew = GBTClassificationModel.fromOld(
133-
oldModel, newModel.parent, categoricalFeatures)
133+
oldModel, newModel.parent.asInstanceOf[GBTClassifier], categoricalFeatures)
134134
TreeTests.checkEqual(oldModelAsNew, newModel)
135135
}
136136
}

mllib/src/test/scala/org/apache/spark/ml/classification/LogisticRegressionSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class LogisticRegressionSuite extends FunSuite with MLlibTestSparkContext {
7474
.setThreshold(0.6)
7575
.setProbabilityCol("myProbability")
7676
val model = lr.fit(dataset)
77-
val parent = model.parent
77+
val parent = model.parent.asInstanceOf[LogisticRegression]
7878
assert(parent.getMaxIter === 10)
7979
assert(parent.getRegParam === 1.0)
8080
assert(parent.getThreshold === 0.6)
@@ -100,7 +100,7 @@ class LogisticRegressionSuite extends FunSuite with MLlibTestSparkContext {
100100
// Call fit() with new params, and check as many params as we can.
101101
val model2 = lr.fit(dataset, lr.maxIter -> 5, lr.regParam -> 0.1, lr.threshold -> 0.4,
102102
lr.probabilityCol -> "theProb")
103-
val parent2 = model2.parent
103+
val parent2 = model2.parent.asInstanceOf[LogisticRegression]
104104
assert(parent2.getMaxIter === 5)
105105
assert(parent2.getRegParam === 0.1)
106106
assert(parent2.getThreshold === 0.4)

mllib/src/test/scala/org/apache/spark/ml/classification/RandomForestClassifierSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private object RandomForestClassifierSuite {
160160
val newModel = rf.fit(newData)
161161
// Use parent, fittingParamMap from newTree since these are not checked anyways.
162162
val oldModelAsNew = RandomForestClassificationModel.fromOld(
163-
oldModel, newModel.parent, categoricalFeatures)
163+
oldModel, newModel.parent.asInstanceOf[RandomForestClassifier], categoricalFeatures)
164164
TreeTests.checkEqual(oldModelAsNew, newModel)
165165
}
166166
}

mllib/src/test/scala/org/apache/spark/ml/param/TestParams.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
package org.apache.spark.ml.param
1919

2020
import org.apache.spark.ml.param.shared.{HasInputCol, HasMaxIter}
21+
import org.apache.spark.ml.util.Identifiable
2122

2223
/** A subclass of Params for testing. */
23-
class TestParams extends Params with HasMaxIter with HasInputCol {
24+
class TestParams(override val uid: String) extends Params with HasMaxIter with HasInputCol {
25+
26+
def this() = this(Identifiable.randomUID("testParams"))
2427

2528
def setMaxIter(value: Int): this.type = { set(maxIter, value); this }
2629

mllib/src/test/scala/org/apache/spark/ml/regression/DecisionTreeRegressorSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private[ml] object DecisionTreeRegressorSuite extends FunSuite {
8585
val newTree = dt.fit(newData)
8686
// Use parent, fittingParamMap from newTree since these are not checked anyways.
8787
val oldTreeAsNew = DecisionTreeRegressionModel.fromOld(
88-
oldTree, newTree.parent, categoricalFeatures)
88+
oldTree, newTree.parent.asInstanceOf[DecisionTreeRegressor], categoricalFeatures)
8989
TreeTests.checkEqual(oldTreeAsNew, newTree)
9090
}
9191
}

0 commit comments

Comments
 (0)