Unverified Commit 46d29e8a authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[R-package] remove Dataset `getinfo()` (#4864)

* [R-package] remove Dataset getinfo()

* fix docs
parent a91e4b2d
......@@ -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)
......
......@@ -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
......@@ -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}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lgb.Dataset.R
\name{getinfo}
\alias{getinfo}
\alias{getinfo.lgb.Dataset}
\title{Get information of an \code{lgb.Dataset} object}
\usage{
getinfo(dataset, ...)
\method{getinfo}{lgb.Dataset}(dataset, name, ...)
}
\arguments{
\item{dataset}{Object of class \code{lgb.Dataset}}
\item{...}{other parameters (ignored)}
\item{name}{the name of the information field to get (see details)}
}
\value{
info data
}
\description{
Get one attribute of a \code{lgb.Dataset}
}
\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))
}
}
......@@ -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
......@@ -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()
......@@ -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", {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment