Commit 795ff82f authored by Guolin Ke's avatar Guolin Ke
Browse files

[package] fix some type check

parent 6b73b4ae
...@@ -852,7 +852,7 @@ class _InnerDataset(object): ...@@ -852,7 +852,7 @@ class _InnerDataset(object):
Init score for booster Init score for booster
""" """
if score is not None: if score is not None:
score = list_to_1d_numpy(score, name='init score') score = list_to_1d_numpy(score, name='init_score')
self.set_field('init_score', score) self.set_field('init_score', score)
def set_group(self, group): def set_group(self, group):
...@@ -986,7 +986,7 @@ class Dataset(object): ...@@ -986,7 +986,7 @@ class Dataset(object):
Parameters Parameters
---------- ----------
data : string/numpy array/scipy.sparse data : string/numpy array/scipy.sparse
Data source of _InnerDataset. Data source of Dataset.
When data type is string, it represents the path of txt file When data type is string, it represents the path of txt file
label : list or numpy 1-D array, optional label : list or numpy 1-D array, optional
Label of the training data. Label of the training data.
...@@ -1396,6 +1396,8 @@ class Booster(object): ...@@ -1396,6 +1396,8 @@ class Booster(object):
name : String name : String
Name of validation data Name of validation data
""" """
if not isinstance(data, Dataset):
raise TypeError('valid data should be Dataset instance, met {}'.format(type(train_set).__name__))
if data._predictor is not self.__init_predictor: if data._predictor is not self.__init_predictor:
raise LightGBMError("Add validation data failed, you should use same predictor for these data") raise LightGBMError("Add validation data failed, you should use same predictor for these data")
_safe_call(_LIB.LGBM_BoosterAddValidData( _safe_call(_LIB.LGBM_BoosterAddValidData(
...@@ -1447,6 +1449,8 @@ class Booster(object): ...@@ -1447,6 +1449,8 @@ class Booster(object):
"""need reset training data""" """need reset training data"""
if train_set is not None and train_set is not self.train_set: if train_set is not None and train_set is not self.train_set:
if not isinstance(train_set, Dataset):
raise TypeError('Training data should be Dataset instance, met {}'.format(type(train_set).__name__))
if train_set._predictor is not self.__init_predictor: if train_set._predictor is not self.__init_predictor:
raise LightGBMError("Replace training data failed, you should use same predictor for these data") raise LightGBMError("Replace training data failed, you should use same predictor for these data")
self.train_set = train_set self.train_set = train_set
...@@ -1517,7 +1521,7 @@ class Booster(object): ...@@ -1517,7 +1521,7 @@ class Booster(object):
Parameters Parameters
---------- ----------
data : _InnerDataset object data : Dataset object
name : name :
Name of data Name of data
feval : function feval : function
...@@ -1527,8 +1531,8 @@ class Booster(object): ...@@ -1527,8 +1531,8 @@ class Booster(object):
result: list result: list
Evaluation result list. Evaluation result list.
""" """
if not isinstance(data, _InnerDataset): if not isinstance(data, Dataset):
raise TypeError("Can only eval for _InnerDataset instance") raise TypeError("Can only eval for Dataset instance")
data_idx = -1 data_idx = -1
if data is self.train_set: if data is self.train_set:
data_idx = 0 data_idx = 0
......
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