Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-24489][ML]Check for invalid input type of weight data in ml.PowerIterationClustering #21509

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class PowerIterationClustering private[clustering] (
val w = if (!isDefined(weightCol) || $(weightCol).isEmpty) {
lit(1.0)
} else {
SchemaUtils.checkNumericType(dataset.schema, $(weightCol))
col($(weightCol)).cast(DoubleType)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ class PowerIterationClusteringSuite extends SparkFunSuite
assert(msg.contains("Similarity must be nonnegative"))
}

test("check for invalid input types of weight") {
val invalidWeightData = spark.createDataFrame(Seq(
(0L, 1L, "a"),
(2L, 3L, "b")
)).toDF("src", "dst", "weight")

val msg = intercept[IllegalArgumentException] {
new PowerIterationClustering()
.setWeightCol("weight")
.assignClusters(invalidWeightData)
}.getMessage
assert(msg.contains("requirement failed: Column weight must be of type numeric" +
" but was actually of type string."))
}

test("test default weight") {
val dataWithoutWeight = data.sample(0.5, 1L).select('src, 'dst)

Expand Down