Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19439#discussion_r147690566
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/image/ImageSchemaSuite.scala ---
    @@ -0,0 +1,109 @@
    +/*
    + * 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.image
    +
    +import java.nio.file.Paths
    +import java.util.Arrays
    +
    +import org.apache.spark.SparkFunSuite
    +import org.apache.spark.ml.image.ImageSchema._
    +import org.apache.spark.mllib.util.MLlibTestSparkContext
    +import org.apache.spark.sql.Row
    +import org.apache.spark.sql.types._
    +
    +class ImageSchemaSuite extends SparkFunSuite with MLlibTestSparkContext {
    +  // Single column of images named "image"
    +  private lazy val imagePath =
    +    
Thread.currentThread().getContextClassLoader.getResource("test-data/images").getPath
    +
    +  test("Smoke test: create basic ImageSchema dataframe") {
    +    val origin = "path"
    +    val width = 1
    +    val height = 1
    +    val nChannels = 3
    +    val data = Array[Byte](0, 0, 0)
    +    val mode = ocvTypes("CV_8UC3")
    +
    +    // Internal Row corresponds to image StructType
    +    val rows = Seq(Row(Row(origin, height, width, nChannels, mode, data)),
    +      Row(Row(null, height, width, nChannels, mode, data)))
    +    val rdd = sc.makeRDD(rows)
    +    val df = spark.createDataFrame(rdd, ImageSchema.imageSchema)
    +
    +    assert(df.count === 2, "incorrect image count")
    +    assert(ImageSchema.isImageColumn(df, "image"), "data do not fit 
ImageSchema")
    +  }
    +
    +  test("readImages count test") {
    +    var df = readImages(imagePath, recursive = false)
    +    assert(df.count === 1)
    +
    +    df = readImages(imagePath, recursive = true, dropImageFailures = false)
    +    assert(df.count === 9)
    +
    +    df = readImages(imagePath, recursive = true, dropImageFailures = true)
    +    val count100 = df.count
    +    assert(count100 === 7)
    +
    +    df = readImages(imagePath, recursive = true, sampleRatio = 0.5, 
dropImageFailures = true)
    +    // Random number about half of the size of the original dataset
    +    val count50 = df.count
    +    assert(count50 > 0.2 * count100 && count50 < 0.8 * count100)
    --- End diff --
    
    Without a close look, this test seems flaky in my local:
    
    ```
    6 was greater than 1.4000000000000001, but 6 was not less than 
5.6000000000000005
    ScalaTestFailureLocation: 
org.apache.spark.ml.image.ImageSchemaSuite$$anonfun$3 at 
(ImageSchemaSuite.scala:66)
    org.scalatest.exceptions.TestFailedException: 6 was greater than 
1.4000000000000001, but 6 was not less than 5.6000000000000005
        at 
org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:528)
        at 
org.scalatest.FunSuite.newAssertionFailedException(FunSuite.scala:1560)
    ```
    
    or
    
    ```
    1 was not greater than 1.4000000000000001
    ScalaTestFailureLocation: 
org.apache.spark.ml.image.ImageSchemaSuite$$anonfun$3 at 
(ImageSchemaSuite.scala:66)
    org.scalatest.exceptions.TestFailedException: 1 was not greater than 
1.4000000000000001
        at 
org.scalatest.Assertions$class.newAssertionFailedException(Assertions.scala:528)
        at 
org.scalatest.FunSuite.newAssertionFailedException(FunSuite.scala:1560)
        at 
org.scalatest.Assertions$AssertionsHelper.macroAssert(Assertions.scala:501)
    ```
    
    It roughly fails at 1 out of 7 tries.


---

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

Reply via email to