Skip to content

Commit

Permalink
[R] Use NA_real_ to initialize handle (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
randxie authored and guolinke committed Mar 4, 2018
1 parent 98c6efe commit b6db7e2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R-package/R/lgb.Dataset.R
Expand Up @@ -167,7 +167,7 @@ Dataset <- R6Class(
if (!is.null(private$reference)) {
ref_handle <- private$reference$.__enclos_env__$private$get_handle()
}
handle <- 0.0
handle <- NA_real_

# Not subsetting
if (is.null(private$used_indices)) {
Expand Down
2 changes: 1 addition & 1 deletion R-package/R/utils.R
Expand Up @@ -7,7 +7,7 @@ lgb.is.Dataset <- function(x) {
}

lgb.is.null.handle <- function(x) {
is.null(x) || x == 0.0
is.null(x) || is.na(x)
}

lgb.encode.char <- function(arr, len) {
Expand Down
16 changes: 16 additions & 0 deletions R-package/tests/testthat/test_dataset.R
Expand Up @@ -26,6 +26,8 @@ test_that("lgb.Dataset: basic construction, saving, loading", {

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

setinfo(dtest, 'label', test_label)
labels <- getinfo(dtest, 'label')
expect_equal(test_label, getinfo(dtest, 'label'))
Expand Down Expand Up @@ -66,3 +68,17 @@ test_that("lgb.Dataset: nrow is correct for a very sparse matrix", {
dtest <- lgb.Dataset(x)
expect_equal(dim(dtest), dim(x))
})

test_that("lgb.Dataset: Dataset should be able to construct from matrix and return non-null handle", {
rawData <- matrix(runif(1000),ncol=10)
handle <- NA_real_
ref_handle <- NULL
handle <- lightgbm:::lgb.call("LGBM_DatasetCreateFromMat_R"
, ret = handle
, rawData
, nrow(rawData)
, ncol(rawData)
, lightgbm:::lgb.params2str(params=list())
, ref_handle)
expect_false(is.na(handle))
})

0 comments on commit b6db7e2

Please sign in to comment.