* [python-package] fix plot_importance() crash when model has 0 splits
* address review: use load_breast_cancer + min_data_in_bin
---------
Co-authored-by: Juan Flores <juanf-0gravity@users.noreply.github.com>
Co-authored-by: James Lamb <jaylamb20@gmail.com>
The y-coordinate passed to matplotlib's ax.text() was a numpy signedinteger from
np.arange(), but matplotlib's type stubs expect a Python float. This cast follows
the existing pattern in engine.py where float() is used to convert numpy values.
Co-authored-by: James Lamb <jaylamb20@gmail.com>
* [python-package] Add return type annotations to predict methods in sklearn module
Add return type annotations to LGBMModel.predict, LGBMClassifier.predict, and LGBMClassifier.predict_proba methods. The predict_proba method requires an isinstance assertion for type narrowing in the binary classification branch, since predict() returns a union type but only returns np.ndarray when pred_contrib=False. This follows the existing error message pattern used in _get_label_from_constructed_dataset and similar helper functions.
Fixes: https://github.com/microsoft/LightGBM/issues/3867
* [python-package] Add shared _LGBM_PredictReturnType type alias for predict methods
Add _LGBM_PredictReturnType type alias in basic.py and use it in _InnerPredictor.predict(),
Booster.predict(), LGBMModel.predict(), LGBMClassifier.predict(), and LGBMClassifier.predict_proba().
Also add assert isinstance() with error message in predict_proba() for type narrowing when
returning binary classification results.
This keeps the return type DRY and ensures consistency across the codebase.
* Update python-package/lightgbm/basic.py
---------
Co-authored-by: James Lamb <jaylamb20@gmail.com>
* [python-package] add Literal type annotation for order variable in _np2d_to_np1d
The order variable was inferred as str but numpy.asarray expects Literal['K', 'A', 'C', 'F']. Added explicit Literal["C", "F"] type annotation before the conditional assignment. This resolves the mypy call-overload error for np.asarray at line 201.
[python-package] Add DTypeLike annotation to fix dtype assignment type in _np2d_to_np1d
Add type annotation for dtype variable to resolve mypy assignment error.
This follows the existing pattern used elsewhere in basic.py (lines 337, 364, 463, 800, 2795).
Co-authored-by: James Lamb <jaylamb20@gmail.com>
The numpy stubs define arange with positional-only parameters so keyword
arguments start=, stop=, step= do not match any overload. Changed to
positional arguments np.arange(_MAX_INT32, nrow, _MAX_INT32) which matches
the numpy stubs correctly and resolves the mypy call-overload errors.
Co-authored-by: James Lamb <jaylamb20@gmail.com>
Change _is_pyarrow_table() return type from bool to TypeGuard[pa_Table] to enable mypy type narrowing at all call sites. This follows the existing pattern used by _is_pyarrow_array() and allows mypy to recognize data.column_names as valid when extracting feature names from PyArrow tables.
Fixes: https://github.com/microsoft/LightGBM/issues/3867
Co-authored-by: James Lamb <jaylamb20@gmail.com>
* [docs] [python-package] document how to run Python tests
* refer to installation instructions
---------
Co-authored-by: Nikita Titov <nekit94-08@mail.ru>