Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,9 @@ dask-worker-space/

# Others
src/main.*.cpp

# Unaltered LightGBM python modules fetched at build time (see python-package/setup.py)
python-package/fairgbm/callback.py
python-package/fairgbm/libpath.py
python-package/fairgbm/plotting.py
python-package/fairgbm/engine.py
16 changes: 8 additions & 8 deletions python-package/fairgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ def list_to_1d_numpy(data, dtype=np.float32, name='list'):
array = data.ravel()
return cast_numpy_1d_array_to_dtype(array, dtype)
elif is_1d_list(data):
return np.array(data, dtype=dtype, copy=False)
return np.asarray(data, dtype=dtype)
elif isinstance(data, pd_Series):
if _get_bad_pandas_dtypes([data.dtypes]):
raise ValueError('Series.dtypes must be int, float or bool')
return np.array(data, dtype=dtype, copy=False) # SparseArray should be supported as well
return np.asarray(data, dtype=dtype) # SparseArray should be supported as well
else:
raise TypeError("Wrong type({0}) for {1}.\n"
"It should be list, numpy 1-D array or pandas Series".format(type(data).__name__, name))
Expand Down Expand Up @@ -456,7 +456,7 @@ def convert_from_sliced_object(data):
def c_float_array(data):
"""Get pointer of float numpy array / list."""
if is_1d_list(data):
data = np.array(data, copy=False)
data = np.asarray(data)
if is_numpy_1d_array(data):
data = convert_from_sliced_object(data)
assert data.flags.c_contiguous
Expand All @@ -477,7 +477,7 @@ def c_float_array(data):
def c_int_array(data):
"""Get pointer of int numpy array / list."""
if is_1d_list(data):
data = np.array(data, copy=False)
data = np.asarray(data)
if is_numpy_1d_array(data):
data = convert_from_sliced_object(data)
assert data.flags.c_contiguous
Expand Down Expand Up @@ -721,7 +721,7 @@ def predict(self, data, start_iteration=0, num_iteration=-1,
lines = f.readlines()
nrow = len(lines)
preds = [float(token) for line in lines for token in line.split('\t')]
preds = np.array(preds, dtype=np.float64, copy=False)
preds = np.asarray(preds, dtype=np.float64)
elif isinstance(data, scipy.sparse.csr_matrix):
preds, nrow = self.__pred_for_csr(data, start_iteration, num_iteration, predict_type)
elif isinstance(data, scipy.sparse.csc_matrix):
Expand Down Expand Up @@ -778,7 +778,7 @@ def __pred_for_np2d(self, mat, start_iteration, num_iteration, predict_type):

def inner_predict(mat, start_iteration, num_iteration, predict_type, preds=None):
if mat.dtype == np.float32 or mat.dtype == np.float64:
data = np.array(mat.reshape(mat.size), dtype=mat.dtype, copy=False)
data = np.asarray(mat.reshape(mat.size), dtype=mat.dtype)
else: # change non-float data to float data, need to copy
data = np.array(mat.reshape(mat.size), dtype=np.float32)
ptr_data, type_ptr_data, _ = c_float_array(data)
Expand Down Expand Up @@ -1312,7 +1312,7 @@ def __init_from_np2d(self, mat, params_str, ref_dataset):

self.handle = ctypes.c_void_p()
if mat.dtype == np.float32 or mat.dtype == np.float64:
data = np.array(mat.reshape(mat.size), dtype=mat.dtype, copy=False)
data = np.asarray(mat.reshape(mat.size), dtype=mat.dtype)
else: # change non-float data to float data, need to copy
data = np.array(mat.reshape(mat.size), dtype=np.float32)

Expand Down Expand Up @@ -1350,7 +1350,7 @@ def __init_from_list_np2d(self, mats, params_str, ref_dataset):
nrow[i] = mat.shape[0]

if mat.dtype == np.float32 or mat.dtype == np.float64:
mats[i] = np.array(mat.reshape(mat.size), dtype=mat.dtype, copy=False)
mats[i] = np.asarray(mat.reshape(mat.size), dtype=mat.dtype)
else: # change non-float data to float data, need to copy
mats[i] = np.array(mat.reshape(mat.size), dtype=np.float32)

Expand Down
241 changes: 0 additions & 241 deletions python-package/fairgbm/callback.py

This file was deleted.

26 changes: 24 additions & 2 deletions python-package/fairgbm/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,30 @@ def _check_sample_weight(sample_weight, X, dtype=None):
LGBMNotFittedError = NotFittedError
_LGBMStratifiedKFold = StratifiedKFold
_LGBMGroupKFold = GroupKFold
_LGBMCheckXY = check_X_y
_LGBMCheckArray = check_array

# scikit-learn >= 1.6 deprecated the ``force_all_finite`` parameter of the
# validation helpers in favour of ``ensure_all_finite`` (removed entirely in
# 1.8). Wrap the validators so FairGBM's ``force_all_finite=...`` call sites
# keep working across scikit-learn versions.
import inspect as _inspect

def _finite_kwarg_compat(_func):
_params = _inspect.signature(_func).parameters
if 'force_all_finite' in _params:
return _func # old scikit-learn: pass through unchanged

def _wrapped(*args, **kwargs):
if 'force_all_finite' in kwargs:
value = kwargs.pop('force_all_finite')
if 'ensure_all_finite' in _params:
kwargs['ensure_all_finite'] = value
# else: neither kwarg supported -> drop it silently
return _func(*args, **kwargs)

return _wrapped

_LGBMCheckXY = _finite_kwarg_compat(check_X_y)
_LGBMCheckArray = _finite_kwarg_compat(check_array)
_LGBMCheckSampleWeight = _check_sample_weight
_LGBMAssertAllFinite = assert_all_finite
_LGBMCheckClassificationTargets = check_classification_targets
Expand Down
Loading
Loading