Skip to content

Commit

Permalink
[R] add deprecation/removal notes for 'info' in xgb.DMatrix (#11168)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes authored Jan 15, 2025
1 parent f5bad03 commit 5a94198
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
35 changes: 33 additions & 2 deletions R-package/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,13 @@ deprecated_predict_params <- list(
renamed = list("ntreelimit" = "iterationrange"),
removed = "reshape"
)
deprecated_dmatrix_params <- list(
renamed = character(),
removed = "info"
)

# These got moved from 'info' to function arguments
args_previous_dmatrix_info <- c("label", "weight", "base_margin", "group")

# Checks the dot-parameters for deprecated names
# (including partial matching), gives a deprecation warning,
Expand Down Expand Up @@ -647,7 +654,12 @@ check.deprecation <- function(
}
list_renamed <- deprecated_list$renamed
list_removed <- deprecated_list$removed
has_params_arg <- list_renamed[[1L]] == deprecated_train_params$renamed[[1L]]
has_params_arg <-
length(list_renamed) == length(deprecated_train_params$renamed) &&
list_renamed[[1L]] == deprecated_train_params$renamed[[1L]]
is_dmatrix_constructor <-
length(list_removed) == length(deprecated_dmatrix_params$removed) &&
list_removed[[1L]] == deprecated_dmatrix_params$removed[[1L]]
all_match <- pmatch(names(params), names(list_renamed))
# throw error on unrecognized parameters
if (!allow_unrecognized && anyNA(all_match)) {
Expand Down Expand Up @@ -685,6 +697,25 @@ check.deprecation <- function(
}
names_unrecognized <- setdiff(names_unrecognized, names_under_params)
}
} else if (is_dmatrix_constructor && NROW(params$info)) {
# same thing for the earlier 'info' in 'xgb.DMatrix'
throw_err_or_depr_msg(
"Passed invalid argument 'info' - entries on it should be passed as direct arguments."
)
entries_info <- names(params$info)
if (length(setdiff(entries_info, args_previous_dmatrix_info))) {
stop(
"Passed unrecognized entries under info: ",
paste(setdiff(entries_info, args_previous_dmatrix_info) |> head(), collapse = ", ")
)
}
for (entry_name in entries_info) {
if (!is.null(env[[entry_name]])) {
stop("Passed entry under both 'info' and function argument(s): ", entry_name)
}
env[[entry_name]] <- params$info[[entry_name]]
}
names_unrecognized <- setdiff(names_unrecognized, "info")
}

# check for parameters that were removed from a previous version
Expand All @@ -701,7 +732,7 @@ check.deprecation <- function(
if (length(names_unrecognized)) {
throw_err_or_depr_msg(
"Passed unrecognized parameters: ",
paste(head(names_unrecognized), collapse = ", ")
paste(head(names_unrecognized), collapse = ", "), "."
)
}

Expand Down
5 changes: 4 additions & 1 deletion R-package/R/xgb.DMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#' @param label_upper_bound Upper bound for survival training.
#' @param feature_weights Set feature weights for column sampling.
#' @param data_split_mode Not used yet. This parameter is for distributed training, which is not yet available for the R package.
#' @inheritParams xgb.train
#' @return An 'xgb.DMatrix' object. If calling `xgb.QuantileDMatrix`, it will have additional
#' subclass `xgb.QuantileDMatrix`.
#'
Expand Down Expand Up @@ -116,8 +117,10 @@ xgb.DMatrix <- function(
label_lower_bound = NULL,
label_upper_bound = NULL,
feature_weights = NULL,
data_split_mode = "row"
data_split_mode = "row",
...
) {
check.deprecation(deprecated_dmatrix_params, match.call(), ...)
if (!is.null(group) && !is.null(qid)) {
stop("Either one of 'group' or 'qid' should be NULL")
}
Expand Down
18 changes: 17 additions & 1 deletion R-package/man/xgb.DMatrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5a94198

Please sign in to comment.