Skip to content

Commit

Permalink
fix the error message for get_field
Browse files Browse the repository at this point in the history
  • Loading branch information
guolinke committed Dec 22, 2017
1 parent b30beb9 commit 9ee1075
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions R-package/R/lgb.Dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,10 @@ Dataset <- R6Class(
}

# Check for info name and handle
if (is.null(private$info[[name]]) && !lgb.is.null.handle(private$handle)) {

if (is.null(private$info[[name]])) {
if (lgb.is.null.handle(private$handle)){
stop("Cannot perform getinfo before construct Dataset.")
}
# Get field size of info
info_len <- 0L
info_len <- lgb.call("LGBM_DatasetGetFieldSize_R",
Expand Down
10 changes: 5 additions & 5 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ def get_field(self, field_name):
A numpy array with information from the Dataset.
"""
if self.handle is None:
raise Exception("Cannot get %s before construct dataset" % field_name)
raise Exception("Cannot get %s before construct Dataset" % field_name)
tmp_out_len = ctypes.c_int()
out_type = ctypes.c_int()
ret = ctypes.POINTER(ctypes.c_void_p)()
Expand Down Expand Up @@ -1144,7 +1144,7 @@ def get_label(self):
label : numpy array
The label information from the Dataset.
"""
if self.label is None and self.handle is not None:
if self.label is None:
self.label = self.get_field('label')
return self.label

Expand All @@ -1156,7 +1156,7 @@ def get_weight(self):
weight : numpy array
Weight for each data point from the Dataset.
"""
if self.weight is None and self.handle is not None:
if self.weight is None:
self.weight = self.get_field('weight')
return self.weight

Expand All @@ -1168,7 +1168,7 @@ def get_init_score(self):
init_score : numpy array
Init score of Booster.
"""
if self.init_score is None and self.handle is not None:
if self.init_score is None:
self.init_score = self.get_field('init_score')
return self.init_score

Expand All @@ -1180,7 +1180,7 @@ def get_group(self):
group : numpy array
Group size of each group.
"""
if self.group is None and self.handle is not None:
if self.group is None:
self.group = self.get_field('group')
if self.group is not None:
# group data from LightGBM is boundaries data, need to convert to group size
Expand Down

0 comments on commit 9ee1075

Please sign in to comment.