Chore: remove unaltered python - #59
Draft
TaiPee wants to merge 3 commits into
Draft
Conversation
Remove callback.py, libpath.py, plotting.py and engine.py, which are byte-identical to upstream LightGBM v3.2.1 (engine.py differs only in docstrings). Restore them at build time via a FetchContent-style overlay in setup.py that shallow-clones LightGBM v3.2.1 and copies the modules into the fairgbm package, mirroring the C++ overlay in PR #58. The overlay also rewrites np.array(..., copy=False) to np.asarray(...) in the fetched files so they build against NumPy >= 2.0. The four files are git-ignored so build-time copies are never committed.
scikit-learn 1.6 deprecated the force_all_finite parameter of check_X_y/check_array in favour of ensure_all_finite (removed entirely in 1.8). Wrap these validators in compat.py to translate the kwarg based on the installed signature, keeping FairGBM compatible across scikit-learn versions.
NumPy 2.0 makes np.array(obj, copy=False) raise when a copy is unavoidable. Replace the affected calls in basic.py with np.asarray(...), which preserves copy-if-needed behaviour on both NumPy 1.x and 2.x.
reluzita
approved these changes
Jul 20, 2026
TaiPee
marked this pull request as draft
July 29, 2026 15:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Slim the FairGBM Python package by removing unaltered upstream files
Goal
Make the FairGBM Python package a lighter, easier-to-maintain fork of LightGBM —
mirroring what PR #58 did for the C++ sources. Instead of vendoring a full copy of
LightGBM's Python modules, we keep only the files FairGBM actually modifies and fetch
the untouched ones from pristine upstream at build time. This makes it trivial to see
exactly what FairGBM changes relative to upstream.
As a prerequisite for validating the change against a modern environment, this PR also
fixes two compatibility issues (scikit-learn ≥ 1.6 and NumPy ≥ 2.0) that otherwise block
a fresh install.
Thinking behind the changes
Which files are safe to remove?
I compared every file in
python-package/fairgbm/against a pristine checkout ofLightGBM v3.2.1 (the same upstream version pinned by the C++ overlay in PR #58,
confirmed by comparing
basic.py/engine.py/dask.pyagainst v3.2.1 vs v3.3.x).callback.pylibpath.pyplotting.pyengine.pybasic.py,sklearn.py,compat.py,dask.py,__init__.py,setup.py,MANIFEST.inThese four modules use only relative imports and contain no
lightgbmstring references,so upstream's copies drop into the
fairgbmpackage verbatim — no content rewriting needed.How to remove them without breaking imports
Unlike the C++ side (compiled), the Python package is imported directly, and the removed
modules are imported by
__init__.py,engine.py, andbasic.py. So they cannot simplybe deleted. The solution does the following at build time,
setup.pyshallow-clones LightGBM v3.2.1 and copies the modules into the package before packaging.
MANIFEST.in(recursive-include fairgbm ... *.py) andinclude_package_data=Truethenbundle them into the wheel/sdist automatically. Published wheels/sdists are unaffected and
need no network — only a build from a raw git checkout fetches upstream, the same trade-off
PR #58 introduces for C++.
Why the compatibility fixes are included
Simulating a fresh-user install on a current toolchain (Python 3.12, NumPy 2.1, pandas 2.2,
scikit-learn 1.8) surfaced two blockers unrelated to the file removal but required for the
package to work at all today:
force_all_finite→ensure_all_finite(removed in 1.8),breaking
FairGBMClassifier.fit().np.array(obj, copy=False)to raise instead of copying when acopy is unavoidable, breaking data ingestion and cross-validation.
The NumPy fix has to be applied both to first-party code (
basic.py) and to the fetchedupstream
engine.py; the latter is patched by the overlay so it stays out of git whilestill producing working code.
What changed
Three commits:
build(python-package): slim fork by fetching unaltered upstream modulescallback.py,libpath.py,plotting.py,engine.py(−1,522 lines).overlay_upstream_python_files()tosetup.py: shallow + sparse clone ofLightGBM
v3.2.1, copies the four modules intofairgbm/. Idempotent and offline-safe(skips the fetch when the files are already present, e.g. in a published sdist).
np.array(..., copy=False)→np.asarray(...)in the fetchedfiles for NumPy ≥ 2.0 compatibility.
fix(python-package): support scikit-learn >= 1.6 validation kwargscheck_X_y/check_arrayincompat.pyto translateforce_all_finite→ensure_all_finitebased on the installed scikit-learn signature (works across versions).fix(python-package): NumPy >= 2.0 compatibility in array handlingnp.array(..., copy=False)calls inbasic.pywithnp.asarray(...),preserving copy-if-needed behaviour on both NumPy 1.x and 2.x.
Testing
Validated end-to-end from a clean checkout (artifacts removed,
pip uninstall), simulatinga new user:
pip install ./python-packagecompiled the C++ library and built/installed the wheel(CMake 4.3.1, g++ 11.4, Python 3.12.5).
callback.py,libpath.py,plotting.py,engine.py, andlib_lightgbm.so, and that the overlaidengine.pyis NumPy-2-safe.FairGBMClassifier.fit/predict_proba) passes.tests/python_package_test/suite: 118 passed, 11 skipped, 0 failed.(Skips are optional-dependency tests —
aequitas,dask— viapytest.importorskip.)Notes / follow-ups
LightGBM v3.2.1 (mirrors PR Remove all unaltered C++ code #58). Published artifacts are unaffected.
UPSTREAM_LIGHTGBM_TAGmust stay in sync with the C++FetchContentpin(
v3.2.1); it is kept in a single constant.Worth validating the combined C++ + Python build in CI once both land.