Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/3099#discussion_r20123262
--- Diff: mllib/src/test/scala/org/apache/spark/ml/param/ParamsSuite.scala
---
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.ml.param
+
+import org.scalatest.FunSuite
+
+class ParamsSuite extends FunSuite {
+
+ val solver = new TestParams()
+ import solver.{inputCol, maxIter}
+
+ test("param") {
+ assert(maxIter.name === "maxIter")
+ assert(maxIter.doc === "max number of iterations")
+ assert(maxIter.default.get === 100)
+ assert(maxIter.parent.eq(solver))
+ assert(maxIter.toString === "maxIter: max number of iterations
(default: 100)")
+ assert(inputCol.default === None)
+ }
+
+ test("param pair") {
+ val pair0 = maxIter -> 5
+ val pair1 = maxIter.w(5)
+ val pair2 = ParamPair(maxIter, 5)
+ for (pair <- Seq(pair0, pair1, pair2)) {
+ assert(pair.param.eq(maxIter))
+ assert(pair.value === 5)
+ }
+ }
+
+ test("param map") {
+ val map0 = ParamMap.empty
+
+ assert(!map0.contains(maxIter))
+ assert(map0(maxIter) === maxIter.default.get)
+ map0.put(maxIter, 10)
+ assert(map0.contains(maxIter))
+ assert(map0(maxIter) === 10)
+
+ assert(!map0.contains(inputCol))
+ intercept[NoSuchElementException] {
+ map0(inputCol)
+ }
+ map0.put(inputCol -> "input")
+ assert(map0.contains(inputCol))
+ assert(map0(inputCol) === "input")
+
+ val map1 = map0.copy
+ val map2 = ParamMap(maxIter -> 10, inputCol -> "input")
+ val map3 = new ParamMap()
+ .put(maxIter, 10)
+ .put(inputCol, "input")
+ val map4 = ParamMap.empty ++ map0
+ val map5 = ParamMap.empty
+ map5 ++= map0
+
+ for (m <- Seq(map1, map2, map3, map4, map5)) {
+ assert(m.contains(maxIter))
+ assert(m(maxIter) === 10)
+ assert(m.contains(inputCol))
+ assert(m(inputCol) === "input")
+ }
+ }
+
+ test("params") {
+ val params = solver.params
+ assert(params.size === 2)
+ assert(params(0).eq(inputCol), "params must be ordered by name")
--- End diff --
It might be nice to change this at some point. Ideally, it would be: order
first by parent (with parents sorted by name), then by required/optional
(whether there is a default), and then sorted by name.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]