From 36c7ddec075320350a68cdef7086f335aafae4bf Mon Sep 17 00:00:00 2001 From: StrikerRUS Date: Sat, 19 May 2018 16:39:18 +0300 Subject: [PATCH] a little bit more efficient checks --- python-package/lightgbm/basic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python-package/lightgbm/basic.py b/python-package/lightgbm/basic.py index 0ddfab7cfa72..bb1c314963f3 100644 --- a/python-package/lightgbm/basic.py +++ b/python-package/lightgbm/basic.py @@ -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() @@ -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() @@ -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()