-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Fixed silent ignore of legacy predict flags (#12211) #12218
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1321,7 +1321,9 @@ xgboost <- function( | |
| #' | ||
| #' Note that this check might add some sizable latency to the predictions, so it's | ||
| #' recommended to disable it for performance-sensitive applications. | ||
| #' @param ... Not used. | ||
| #' @param ... Legacy boolean flags (e.g., \code{predcontrib}) are supported for | ||
| #' backward compatibility but are deprecated and map to the \code{type} argument. | ||
| #' Any other arguments passed to \code{...} will cause an error. | ||
| #' @return Either a numeric vector (for 1D outputs), numeric matrix (for 2D outputs), numeric array | ||
| #' (for 3D and higher), or `factor` (for class predictions). See documentation for parameter `type` | ||
| #' for details about what the output type and shape will be. | ||
|
|
@@ -1352,6 +1354,47 @@ predict.xgboost <- function( | |
| validate_features = TRUE, | ||
| ... | ||
| ) { | ||
| dots <- list(...) | ||
| if (length(dots) > 0) { | ||
| mapping <- list( | ||
|
Sanidhyavijay24 marked this conversation as resolved.
|
||
| outputmargin = "raw", | ||
| predleaf = "leaf", | ||
| predcontrib = "contrib", | ||
| approxcontrib = "contrib", | ||
| predinteraction = "interaction" | ||
| ) | ||
| found_legacy <- intersect(names(dots), names(mapping)) | ||
|
|
||
| if (length(found_legacy) > 0) { | ||
| for (legacy_arg in found_legacy) { | ||
| if (isTRUE(dots[[legacy_arg]])) { | ||
| type <- mapping[[legacy_arg]] | ||
| warning( | ||
| sprintf( | ||
| "Argument '%s' is deprecated. Please use type = '%s' instead.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not the case that it's deprecated. |
||
| legacy_arg, type | ||
| ), | ||
| call. = FALSE | ||
| ) | ||
| break | ||
| } | ||
| } | ||
| dots[found_legacy] <- NULL | ||
| } | ||
|
|
||
| if (length(dots) > 0) { | ||
| dot_names <- names(dots) | ||
| if (is.null(dot_names)) { | ||
| dot_names <- rep("<unnamed>", length(dots)) | ||
| } | ||
| dot_names[dot_names == ""] <- "<unnamed>" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does this |
||
| stop( | ||
| "predict.xgboost: arguments in '...' are not supported (", | ||
| paste(dot_names, collapse = ", "), ")." | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| if (inherits(newdata, "xgb.DMatrix")) { | ||
| stop( | ||
| "Predictions on 'xgb.DMatrix' objects are not supported with 'xgboost' class.", | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually not how most libraries work. Consider for example:
Better to throw a warning than to error out.