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

[R] Gracefully handle deprecated parameters #10563

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hcho3
Copy link
Collaborator

@hcho3 hcho3 commented Jul 10, 2024

Reproducer:

require(xgboost)
data(agaricus.train, package='xgboost')
data(agaricus.test, package='xgboost')
train <- agaricus.train
test <- agaricus.test
dtrain <- xgb.DMatrix(data = train$data, label=train$label)
dtest <- xgb.DMatrix(data = test$data, label=test$label)
watchlist <- list(train=dtrain, test=dtest)
bst <- xgb.train(data=dtrain, max_depth=2, eta=1, nthread = 2, nrounds=2,
                 watchlist=watchlist, objective = "binary:logistic")

The current master version fails with cryptic error

Loading required package: xgboost
Error in parse(text = paste(new_par, "<-", pars[[pars_par]])) :
  <text>:1:10: unexpected '<'
1: evals <- <
             ^
Calls: xgb.train -> check.deprecation -> eval -> parse
In addition: Warning message:
In check.deprecation(...) : 'watchlist' is deprecated.
Use 'evals' instead.
See help("Deprecated") and help("xgboost-deprecated").
4: parse(text = paste(new_par, "<-", pars[[pars_par]]))
3: eval(parse(text = paste(new_par, "<-", pars[[pars_par]])), envir = env)
2: check.deprecation(...)
1: xgb.train(data = dtrain, max_depth = 2, eta = 1, nthread = 2,
       nrounds = 2, watchlist = watchlist, objective = "binary:logistic")

The error occurs because the use of eval(parse(...)) does not correctly handle data frame values.
This pull request replaces the expression with assign(...).

Also: Explicitly filter out deprecated parameters from the dot params. In the reproducer script, not filtering out watchlist leads to error Error: No method asJSON S3 class: xgb.DMatrix because watchlist was still part of the params list and R tried to serialize the params list as JSON.

After the fix, the reproducer script successfully runs, with only a warning:

Loading required package: xgboost
[1]     train-logloss:0.233156  test-logloss:0.226460
[2]     train-logloss:0.136542  test-logloss:0.137763
Warning message:
In check.deprecation(...) : 'watchlist' is deprecated.
Use 'evals' instead.
See help("Deprecated") and help("xgboost-deprecated").

@hcho3
Copy link
Collaborator Author

hcho3 commented Jul 10, 2024

@david-cortes @mayer79 @trivialfis Can I get a review for this patch?

@hcho3
Copy link
Collaborator Author

hcho3 commented Jul 10, 2024

Let me look at the failing tests.

@trivialfis
Copy link
Member

Is this necessary considering that the rewrite will break pretty much everything.

@gtumuluri
Copy link

gtumuluri commented Jul 22, 2024

I am running into this exact issue, and am unable to use xgboost. Is there a version that I should be using instead?

Here is what I am using:

> packageVersion('xgboost')
[1] '1.7.7.1'

@hcho3
Copy link
Collaborator Author

hcho3 commented Jul 22, 2024

@gtumuluri For now, please ensure that you are not using any of the deprecated parameters.

@david-cortes
Copy link
Contributor

LGTM.

Unrelated to the changes here, but since things are being modified:

  • It currently suggests:

See help("Deprecated") and help("xgboost-deprecated").

But help("Deprecated") doesn't really help the end user here. Perhaps it could be removed.

  • Docs for help("xgboost-deprecated") suggest:

check the xgboost:::depr_par_lut table.

Perhaps it could be publicly exported as a function that would return said table. Might even help package authors that have dependencies on XGBoost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants