[R-package] remove unused code checking has_header in Dataset() (fixes #4553) (#4554)

This commit is contained in:
James Lamb 2021-08-25 21:07:25 +01:00 коммит произвёл GitHub
Родитель bd28a3649a
Коммит f5925c3f69
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 42 добавлений и 10 удалений

Просмотреть файл

@ -171,16 +171,6 @@ Dataset <- R6::R6Class(
}
# Check has header or not
has_header <- FALSE
if (!is.null(private$params$has_header) || !is.null(private$params$header)) {
params_has_header <- tolower(as.character(private$params$has_header)) == "true"
params_header <- tolower(as.character(private$params$header)) == "true"
if (params_has_header || params_header) {
has_header <- TRUE
}
}
# Generate parameter str
params_str <- lgb.params2str(params = private$params)

Просмотреть файл

@ -310,3 +310,45 @@ test_that("lgb.Dataset: should be able to use and retrieve long feature names",
expect_equal(col_names[1L], long_name)
expect_equal(nchar(col_names[1L]), 1000L)
})
test_that("lgb.Dataset: should be able to create a Dataset from a text file with a header", {
train_file <- tempfile(pattern = "train_", fileext = ".csv")
write.table(
data.frame(y = rnorm(100L), x1 = rnorm(100L), x2 = rnorm(100L))
, file = train_file
, sep = ","
, col.names = TRUE
, row.names = FALSE
, quote = FALSE
)
dtrain <- lgb.Dataset(
data = train_file
, params = list(header = TRUE)
)
dtrain$construct()
expect_identical(dtrain$get_colnames(), c("x1", "x2"))
expect_identical(dtrain$get_params(), list(header = TRUE))
expect_identical(dtrain$dim(), c(100L, 2L))
})
test_that("lgb.Dataset: should be able to create a Dataset from a text file without a header", {
train_file <- tempfile(pattern = "train_", fileext = ".csv")
write.table(
data.frame(y = rnorm(100L), x1 = rnorm(100L), x2 = rnorm(100L))
, file = train_file
, sep = ","
, col.names = FALSE
, row.names = FALSE
, quote = FALSE
)
dtrain <- lgb.Dataset(
data = train_file
, params = list(header = FALSE)
)
dtrain$construct()
expect_identical(dtrain$get_colnames(), c("Column_0", "Column_1"))
expect_identical(dtrain$get_params(), list(header = FALSE))
expect_identical(dtrain$dim(), c(100L, 2L))
})