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-package] remove Dataset getinfo() #4864

Merged
merged 2 commits into from
Dec 7, 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
2 changes: 0 additions & 2 deletions R-package/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ S3method("dimnames<-",lgb.Dataset)
S3method(dim,lgb.Dataset)
S3method(dimnames,lgb.Dataset)
S3method(get_field,lgb.Dataset)
S3method(getinfo,lgb.Dataset)
S3method(predict,lgb.Booster)
S3method(print,lgb.Booster)
S3method(set_field,lgb.Dataset)
S3method(slice,lgb.Dataset)
S3method(summary,lgb.Booster)
export(get_field)
export(getinfo)
export(lgb.Dataset)
export(lgb.Dataset.construct)
export(lgb.Dataset.create.valid)
Expand Down
77 changes: 0 additions & 77 deletions R-package/R/lgb.Dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -464,18 +464,6 @@ Dataset <- R6::R6Class(

},

getinfo = function(name) {
warning(paste0(
"Dataset$getinfo() is deprecated and will be removed in a future release. "
, "Use Dataset$get_field() instead."
))
return(
self$get_field(
field_name = name
)
)
},

get_field = function(field_name) {

# Check if attribute key is in the known attribute list
Expand Down Expand Up @@ -1157,71 +1145,6 @@ slice.lgb.Dataset <- function(dataset, idxset, ...) {

}

#' @name getinfo
#' @title Get information of an \code{lgb.Dataset} object
#' @description Get one attribute of a \code{lgb.Dataset}
#' @param dataset Object of class \code{lgb.Dataset}
#' @param name the name of the information field to get (see details)
#' @param ... other parameters (ignored)
#' @return info data
#'
#' @details
#' The \code{name} field can be one of the following:
#'
#' \itemize{
#' \item \code{label}: label lightgbm learn from ;
#' \item \code{weight}: to do a weight rescale ;
#' \item{\code{group}: used for learning-to-rank tasks. An integer vector describing how to
#' group rows together as ordered results from the same set of candidate results to be ranked.
#' For example, if you have a 100-document dataset with \code{group = c(10, 20, 40, 10, 10, 10)},
#' that means that you have 6 groups, where the first 10 records are in the first group,
#' records 11-30 are in the second group, etc.}
#' \item \code{init_score}: initial score is the base prediction lightgbm will boost from.
#' }
#'
#' @examples
#' \donttest{
#' data(agaricus.train, package = "lightgbm")
#' train <- agaricus.train
#' dtrain <- lgb.Dataset(train$data, label = train$label)
#' lgb.Dataset.construct(dtrain)
#'
#' labels <- lightgbm::getinfo(dtrain, "label")
#' lightgbm::set_field(dtrain, "label", 1 - labels)
#'
#' labels2 <- lightgbm::getinfo(dtrain, "label")
#' stopifnot(all(labels2 == 1 - labels))
#' }
#' @export
getinfo <- function(dataset, ...) {
UseMethod("getinfo")
}

#' @rdname getinfo
#' @export
getinfo.lgb.Dataset <- function(dataset, name, ...) {

warning("Calling getinfo() on a lgb.Dataset is deprecated. Use get_field() instead.")

additional_args <- list(...)
if (length(additional_args) > 0L) {
warning(paste0(
"getinfo.lgb.Dataset: Found the following passed through '...': "
, paste(names(additional_args), collapse = ", ")
, ". These are ignored. In future releases of lightgbm, this warning will become an error. "
, "See ?getinfo.lgb.Dataset for documentation on how to call this function."
))
}

if (!lgb.is.Dataset(x = dataset)) {
stop("getinfo.lgb.Dataset: input dataset should be an lgb.Dataset object")
}

return(dataset$get_field(field_name = name))

}


#' @name get_field
#' @title Get one attribute of a \code{lgb.Dataset}
#' @description Get one attribute of a \code{lgb.Dataset}
Expand Down
52 changes: 0 additions & 52 deletions R-package/man/getinfo.Rd

This file was deleted.

21 changes: 2 additions & 19 deletions R-package/tests/testthat/test_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ test_that("lgb.Dataset: basic construction, saving, loading", {
dtest1 <- lgb.Dataset(test_data, label = test_label)
# from dense matrix
dtest2 <- lgb.Dataset(as.matrix(test_data), label = test_label)
expect_equal(getinfo(dtest1, "label"), getinfo(dtest2, "label"))
expect_equal(get_field(dtest1, "label"), get_field(dtest2, "label"))

# save to a local file
Expand All @@ -23,25 +22,9 @@ test_that("lgb.Dataset: basic construction, saving, loading", {
dtest3 <- lgb.Dataset(tmp_file)
lgb.Dataset.construct(dtest3)
unlink(tmp_file)
expect_equal(getinfo(dtest1, "label"), getinfo(dtest3, "label"))
expect_equal(get_field(dtest1, "label"), get_field(dtest3, "label"))
})

test_that("lgb.Dataset: getinfo", {
dtest <- lgb.Dataset(test_data)
dtest$construct()

set_field(dtest, "label", test_label)
labels <- getinfo(dtest, "label")
expect_equal(test_label, getinfo(dtest, "label"))

expect_true(length(getinfo(dtest, "weight")) == 0L)
expect_true(length(getinfo(dtest, "init_score")) == 0L)

# any other label should error
expect_error(set_field(dtest, "asdf", test_label))
})

test_that("lgb.Dataset: get_field & set_field", {
dtest <- lgb.Dataset(test_data)
dtest$construct()
Expand Down Expand Up @@ -91,8 +74,8 @@ test_that("Dataset$slice() supports passing Dataset attributes through '...'", {
, init_score = init_score
)
dsub1$construct()
expect_null(dtest$getinfo("init_score"), NULL)
expect_identical(dsub1$getinfo("init_score"), init_score)
expect_null(dtest$get_field("init_score"), NULL)
expect_identical(dsub1$get_field("init_score"), init_score)
})

test_that("Dataset$set_reference() on a constructed Dataset fails if raw data has been freed", {
Expand Down