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

fix: improve LGBM error message for invalid slot names #1160

Merged
merged 1 commit into from
Aug 12, 2021
Merged
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 @@ -224,8 +224,10 @@ trait LightGBMBase[TrainedModel <: Model[TrainedModel]] extends Estimator[Traine
val badSlotNames = slotNames.flatMap(slotName =>
if (pattern.findFirstIn(slotName).isEmpty) None else Option(slotName))
if (!badSlotNames.isEmpty) {
val errorMsg = s"Invalid slot names detected in features column: ${badSlotNames.mkString(",")}"
throw new IllegalArgumentException(errorMsg)
throw new IllegalArgumentException(
s"Invalid slot names detected in features column: ${badSlotNames.mkString(",")}" +
" \n Special characters \" , : \\ [ ] { } will cause unexpected behavior in LGBM unless changed." +
" This error can be fixed by renaming the problematic columns prior to vector assembly.")
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.apache.spark.sql.{DataFrame, Row}
import org.apache.spark.sql.functions.{avg, col, lit, when}

// scalastyle:off magic.number

/** Tests to validate the functionality of LightGBM module.
*/
class VerifyLightGBMRegressor extends Benchmarks
Expand Down Expand Up @@ -121,7 +122,7 @@ class VerifyLightGBMRegressor extends Benchmarks
.withColumnRenamed("M-class flares production by this region", labelCol)

LightGBMUtils.getFeaturizer(df2, labelCol, featuresCol).transform(df2)
}.cache()
}.cache()

def regressionEvaluator: RegressionEvaluator = {
new RegressionEvaluator()
Expand All @@ -142,7 +143,9 @@ class VerifyLightGBMRegressor extends Benchmarks
test("Verify LightGBM Regressor with bad column names fails early") {
val baseModelWithBadSlots = baseModel.setSlotNames(Range(0, 22).map(i =>
"Invalid characters \",:[]{} " + i).toArray)
interceptWithoutLogging[IllegalArgumentException]{baseModelWithBadSlots.fit(flareDF).transform(flareDF).collect()}
interceptWithoutLogging[IllegalArgumentException] {
baseModelWithBadSlots.fit(flareDF).transform(flareDF).collect()
}
}

test("Verify LightGBM Regressor with tweedie distribution") {
Expand Down