Github user MLnick commented on a diff in the pull request:
https://github.com/apache/spark/pull/11601#discussion_r80488125
--- Diff:
mllib/src/test/scala/org/apache/spark/ml/feature/ImputerSuite.scala ---
@@ -0,0 +1,122 @@
+/*
+ * 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.feature
+
+import org.apache.spark.SparkFunSuite
+import org.apache.spark.ml.util.{DefaultReadWriteTest}
+import org.apache.spark.mllib.util.MLlibTestSparkContext
+import org.apache.spark.mllib.util.TestingUtils._
+import org.apache.spark.sql.Row
+
+class ImputerSuite extends SparkFunSuite with MLlibTestSparkContext with
DefaultReadWriteTest {
+
+ test("Imputer for Double with default missing Value NaN") {
+ val df = spark.createDataFrame( Seq(
+ (0, 1.0, 1.0, 1.0),
+ (1, 1.0, 1.0, 1.0),
+ (2, 3.0, 3.0, 3.0),
+ (3, 4.0, 4.0, 4.0),
+ (4, Double.NaN, 2.25, 1.0)
+ )).toDF("id", "value", "expected_mean", "expected_median")
+ Seq("mean", "median").foreach { strategy =>
+ val imputer = new
Imputer().setInputCol("value").setOutputCol("out").setStrategy(strategy)
+ val model = imputer.fit(df)
+ model.transform(df).select("expected_" + strategy,
"out").collect().foreach {
+ case Row(exp: Double, out: Double) =>
+ assert(exp ~== out absTol 1e-5, s"Imputed values differ.
Expected: $exp, actual: $out")
+ }
+ }
+ }
+
--- End diff --
Good catch yes - obviously the imputer can't actually do anything useful in
that case - but it should either throw a useful error, or return the dataset
unchanged.
I would favor an error in this case as if a user is explicitly wanting to
impute missing data and all their data is missing, rather blow up now than
later in the pipeline.
---
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]