WeichenXu123 opened a new pull request #28498:
URL: https://github.com/apache/spark/pull/28498


   ### What changes were proposed in this pull request?
   
   In QuantileDiscretizer.getDistinctSplits, before invoking distinct, 
normalize all -0.0 and 0.0 to be 0.0
   ```
       for (i <- 0 until splits.length) {
         if (splits(i) == -0.0) {
           splits(i) = 0.0
         }
       }
   ```
   ### Why are the changes needed?
   Fix bug.
   
   ### Does this PR introduce _any_ user-facing change?
   No
   
   
   ### How was this patch tested?
   Unit test.
   
   #### Manually test:
   
   ~~~scala
   import scala.util.Random
   val rng = new Random(3)
   
   val a1 = Array.tabulate(200)(_=>rng.nextDouble * 2.0 - 1.0) ++ 
Array.fill(20)(0.0) ++ Array.fill(20)(-0.0)
   
   import spark.implicits._
   val df1 = sc.parallelize(a1, 2).toDF("id")
   
   import org.apache.spark.ml.feature.QuantileDiscretizer
   val qd = new 
QuantileDiscretizer().setInputCol("id").setOutputCol("out").setNumBuckets(200).setRelativeError(0.0)
   
   val model = qd.fit(df1) // will raise error in spark master.
   ~~~


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to