Fixed silent ignore of legacy predict flags (#12211)#12218
Open
Sanidhyavijay24 wants to merge 2 commits into
Open
Fixed silent ignore of legacy predict flags (#12211)#12218Sanidhyavijay24 wants to merge 2 commits into
Sanidhyavijay24 wants to merge 2 commits into
Conversation
predict.xgboost was silently ignoring boolean flags like predcontrib=TRUE since they were absorbed by '...'. This maps those legacy flags to the appropriate 'type' and issues a deprecation warning so we don't break backward compatibility. Any completely unknown arguments in '...' will now throw a proper error.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the R predict.xgboost S3 method to prevent silent ignoring of legacy boolean prediction flags (e.g., predcontrib = TRUE) by mapping them to the modern type argument with a deprecation warning, and to error on unsupported arguments passed via ... to avoid silent typos.
Changes:
- Map legacy predict flags provided via
...(e.g.,predcontrib) totype = "<...>"and emit a deprecation warning. - Error out when any unsupported arguments are provided in
.... - Add test coverage for the new warning/error behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| R-package/R/xgboost.R | Adds legacy-flag mapping logic for predict.xgboost(...) and rejects unknown ... args. |
| R-package/tests/testthat/test_xgboost.R | Adds a regression test for legacy flag mapping + unknown ... argument errors. |
Comments suppressed due to low confidence (3)
R-package/R/xgboost.R:1379
- The legacy-argument mapping only inspects the first matched legacy flag (found_legacy[1]). This can fail to map a TRUE flag if an earlier legacy flag is present but FALSE (e.g., outputmargin = FALSE, predcontrib = TRUE), and it also silently ignores/overrides cases where multiple legacy flags are provided. Consider computing which legacy flags are isTRUE(), erroring on >1 TRUE (or conflicts with an explicit non-default 'type'), and then mapping the single TRUE flag deterministically.
found_legacy <- intersect(names(dots), names(mapping))
if (length(found_legacy) > 0) {
legacy_arg <- found_legacy[1]
if (isTRUE(dots[[legacy_arg]])) {
type <- mapping[[legacy_arg]]
warning(
sprintf(
"Argument '%s' is deprecated. Please use type = '%s' instead.",
legacy_arg, type
),
call. = FALSE
)
}
dots <- dots[setdiff(names(dots), names(mapping))]
}
R-package/R/xgboost.R:1363
- approxcontrib is mapped to type = 'contrib' here, but predict.xgboost never passes approxcontrib through to predict.xgb.Booster, so approxcontrib=TRUE will be silently ignored (and will compute exact SHAP instead of the requested approximation). Either add support for approxcontrib in predict.xgboost (and pass it through), or remove this mapping and error/warn with guidance (e.g., use predict.xgb.Booster for approxcontrib).
mapping <- list(
outputmargin = "raw",
predleaf = "leaf",
predcontrib = "contrib",
approxcontrib = "contrib",
predinteraction = "interaction"
)
R-package/R/xgboost.R:1385
- If '...' contains unnamed arguments, names(dots) will include "" and the error message will render as an empty entry ("not supported ()."), which is hard to debug. Consider detecting unnamed elements and printing a placeholder like "" or including positional indices in the message.
if (length(dots) > 0) {
stop(
"predict.xgboost: arguments in '...' are not supported (",
paste(names(dots), collapse = ", "), ")."
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Improved intent detection by checking for isTRUE() in legacy flags. - Use dots[found_legacy] <- NULL for safer subsetting. - Handle unnamed arguments in '...' with descriptive '<unnamed>' error messages. - Update roxygen2 documentation and metadata.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses #12211.
It prevents
predict.xgboostfrom silently ignoring legacy boolean flags (likepredcontrib = TRUE). These flags are now mapped to the modern type argument with a deprecation warning. Additionally, any unknown arguments in...will now trigger an error to prevent typos from causing silent failures.