Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/19439#discussion_r148696592
--- Diff:
mllib/src/test/scala/org/apache/spark/ml/image/ImageSchemaSuite.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.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 = "../data/mllib/images"
+
+ 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(df.schema("image").dataType == columnSchema, "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 countTotal = df.count
+ assert(countTotal === 7)
+
+ df = readImages(imagePath, recursive = true, sampleRatio = 0.5,
dropImageFailures = true)
--- End diff --
This would be a good reason to have a seed: We can make the test
deterministic to avoid flakiness (from occasionally having an actual
sampleRatio of 0 or 1).
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]