Skip to content

Commit

Permalink
a little bit more efficient checks
Browse files Browse the repository at this point in the history
  • Loading branch information
StrikerRUS committed May 19, 2018
1 parent 386e122 commit 36c7dde
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def __init_from_np2d(self, mat, params_str, ref_dataset, categorical_indices=Non
"""
if len(mat.shape) != 2:
raise ValueError('Input numpy.ndarray must be 2 dimensional')
if categorical_indices is not None and (mat[:, list(categorical_indices)] > MAX_INT32).any():
if categorical_indices is not None and mat[:, list(categorical_indices)].max() > MAX_INT32:
raise ValueError('Values of categorical features must be smaller than {0}'.format(MAX_INT32))

self.handle = ctypes.c_void_p()
Expand All @@ -784,7 +784,7 @@ def __init_from_csr(self, csr, params_str, ref_dataset, categorical_indices=None
"""
if len(csr.indices) != len(csr.data):
raise ValueError('Length mismatch: {} vs {}'.format(len(csr.indices), len(csr.data)))
if categorical_indices is not None and (csr[:, list(categorical_indices)] > MAX_INT32).nnz:
if categorical_indices is not None and csr[:, list(categorical_indices)].max() > MAX_INT32:
raise ValueError('Values of categorical features must be smaller than {0}'.format(MAX_INT32))

self.handle = ctypes.c_void_p()
Expand All @@ -810,7 +810,7 @@ def __init_from_csc(self, csc, params_str, ref_dataset, categorical_indices=None
"""
if len(csc.indices) != len(csc.data):
raise ValueError('Length mismatch: {} vs {}'.format(len(csc.indices), len(csc.data)))
if categorical_indices is not None and (csc[:, list(categorical_indices)] > MAX_INT32).nnz:
if categorical_indices is not None and csc[:, list(categorical_indices)].max() > MAX_INT32:
raise ValueError('Values of categorical features must be smaller than {0}'.format(MAX_INT32))

self.handle = ctypes.c_void_p()
Expand Down

0 comments on commit 36c7dde

Please sign in to comment.