Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,6 @@ dask-worker-space/

# hipify-perl -inplace leaves behind *.prehip files
*.prehip

# pixi environments
.pixi
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
rev: v1.37.1
hooks:
- id: yamllint
args: ["--strict"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.10
rev: v0.12.5
hooks:
# Run the linter.
- id: ruff
Expand All @@ -39,13 +39,13 @@ repos:
hooks:
- id: shellcheck
- repo: https://github.com/crate-ci/typos
rev: v1.30.2
rev: v1.34.0
hooks:
- id: typos
args: ["--force-exclude"]
exclude: (\.gitignore$)|(^\.editorconfig$)
- repo: https://github.com/henryiii/validate-pyproject-schema-store
rev: 2025.03.10
rev: 2025.07.14
hooks:
- id: validate-pyproject
files: python-package/pyproject.toml$
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": {
"ignore": [".mypy_cache/"]
"ignore": [".mypy_cache/", ".pixi/"]
},
"formatter": {
"enabled": true,
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def run(self) -> List:

# -- General configuration ------------------------------------------------

os.environ["LIGHTGBM_BUILD_DOC"] = "1"
os.environ["LIGHTGBM_BUILD_DOC"] = "True"
C_API = os.environ.get("C_API", "").lower().strip() != "no"
RTD = bool(os.environ.get("READTHEDOCS", ""))
RTD_VERSION = os.environ.get("READTHEDOCS_VERSION", "stable")
Expand Down
4 changes: 2 additions & 2 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def _log_callback(msg: bytes) -> None:


# connect the Python logger to logging in lib_lightgbm
if not environ.get("LIGHTGBM_BUILD_DOC", False):
if environ.get("LIGHTGBM_BUILD_DOC", "False") != "True":
_LIB.LGBM_GetLastError.restype = ctypes.c_char_p
callback = ctypes.CFUNCTYPE(None, ctypes.c_char_p)
_LIB.callback = callback(_log_callback) # type: ignore[attr-defined]
Expand Down Expand Up @@ -840,7 +840,7 @@ def _data_from_pandas(
for col, category in zip(cat_cols, pandas_categorical):
if list(data[col].cat.categories) != list(category):
data[col] = data[col].cat.set_categories(category)
if len(cat_cols): # cat_cols is list
if cat_cols: # cat_cols is list
data[cat_cols] = data[cat_cols].apply(lambda x: x.cat.codes).replace({-1: np.nan})

# use cat cols from DataFrame
Expand Down
2 changes: 1 addition & 1 deletion python-package/lightgbm/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CallbackEnv:
def _is_using_cv(env: CallbackEnv) -> bool:
"""Check if model in callback env is a CVBooster."""
# this import is here to avoid a circular import
from .engine import CVBooster
from .engine import CVBooster # noqa: PLC0415

return isinstance(env.model, CVBooster)

Expand Down
2 changes: 1 addition & 1 deletion python-package/lightgbm/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def validate_data(
# * lightgbm cannot be used with scikit-learn versions older than that
# * this validate_data() re-implementation will not be called in scikit-learn>=1.6
#
from sklearn.utils.validation import _num_features
from sklearn.utils.validation import _num_features # noqa: PLC0415

# _num_features() raises a TypeError on 1-dimensional input. That's a problem
# because scikit-learn's 'check_fit1d' estimator check sets that expectation that
Expand Down
2 changes: 1 addition & 1 deletion python-package/lightgbm/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def _train(
)
raise LightGBMError(msg)

worker_address_to_port = {address: local_listen_port for address in worker_addresses}
worker_address_to_port = dict.fromkeys(worker_addresses, local_listen_port)
else:
_log_info("Finding random open ports for workers")
worker_to_socket_future, worker_address_to_port = _assign_open_ports_to_workers(
Expand Down
2 changes: 1 addition & 1 deletion python-package/lightgbm/libpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _find_lib_path() -> List[str]:

# we don't need lib_lightgbm while building docs
_LIB: ctypes.CDLL
if environ.get("LIGHTGBM_BUILD_DOC", False):
if environ.get("LIGHTGBM_BUILD_DOC", "False") == "True":
from unittest.mock import Mock # isort: skip

_LIB = Mock(ctypes.CDLL) # type: ignore
Expand Down
14 changes: 7 additions & 7 deletions python-package/lightgbm/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def plot_importance(
The plot with model's feature importances.
"""
if MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt # noqa: PLC0415
else:
raise ImportError("You must install matplotlib and restart your session to plot importance.")

Expand Down Expand Up @@ -235,8 +235,8 @@ def plot_split_value_histogram(
The plot with specified model's feature split value histogram.
"""
if MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
import matplotlib.pyplot as plt # noqa: PLC0415
from matplotlib.ticker import MaxNLocator # noqa: PLC0415
else:
raise ImportError("You must install matplotlib and restart your session to plot split value histogram.")

Expand Down Expand Up @@ -342,7 +342,7 @@ def plot_metric(
The plot with metric's history over the training.
"""
if MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt # noqa: PLC0415
else:
raise ImportError("You must install matplotlib and restart your session to plot metric.")

Expand Down Expand Up @@ -468,7 +468,7 @@ def _to_graphviz(
- https://graphviz.readthedocs.io/en/stable/api.html#digraph
"""
if GRAPHVIZ_INSTALLED:
from graphviz import Digraph
from graphviz import Digraph # noqa: PLC0415
else:
raise ImportError("You must install graphviz and restart your session to plot tree.")

Expand Down Expand Up @@ -812,8 +812,8 @@ def plot_tree(
The plot with single tree.
"""
if MATPLOTLIB_INSTALLED:
import matplotlib.image
import matplotlib.pyplot as plt
import matplotlib.image # noqa: PLC0415
import matplotlib.pyplot as plt # noqa: PLC0415
else:
raise ImportError("You must install matplotlib and restart your session to plot tree.")

Expand Down
4 changes: 2 additions & 2 deletions src/io/cuda/cuda_column_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void CUDAColumnData::Init(const int num_columns,
} else if (bit_type == 32) {
InitOneColumnData<false, false, uint32_t>(column_data[column_index], nullptr, &data_by_column_[column_index]);
} else {
Log::Fatal("Unknow column bit type %d", bit_type);
Log::Fatal("Unknown column bit type %d", bit_type);
}
} else {
// is sparse column
Expand All @@ -146,7 +146,7 @@ void CUDAColumnData::Init(const int num_columns,
} else if (bit_type == 32) {
InitOneColumnData<true, false, uint32_t>(nullptr, column_bin_iterator[column_index], &data_by_column_[column_index]);
} else {
Log::Fatal("Unknow column bit type %d", bit_type);
Log::Fatal("Unknown column bit type %d", bit_type);
}
}
OMP_LOOP_EX_END();
Expand Down
8 changes: 4 additions & 4 deletions src/io/cuda/cuda_row_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void CUDARowData::Init(const Dataset* train_data, TrainingShareStates* train_sha
&cuda_row_ptr_uint64_t_,
&cuda_partition_ptr_uint64_t_);
} else {
Log::Fatal("Unknow data ptr bit type %d", row_ptr_bit_type_);
Log::Fatal("Unknown data ptr bit type %d", row_ptr_bit_type_);
}
}
} else if (bit_type_ == 16) {
Expand Down Expand Up @@ -136,7 +136,7 @@ void CUDARowData::Init(const Dataset* train_data, TrainingShareStates* train_sha
&cuda_row_ptr_uint64_t_,
&cuda_partition_ptr_uint64_t_);
} else {
Log::Fatal("Unknow data ptr bit type %d", row_ptr_bit_type_);
Log::Fatal("Unknown data ptr bit type %d", row_ptr_bit_type_);
}
}
} else if (bit_type_ == 32) {
Expand Down Expand Up @@ -167,11 +167,11 @@ void CUDARowData::Init(const Dataset* train_data, TrainingShareStates* train_sha
&cuda_row_ptr_uint64_t_,
&cuda_partition_ptr_uint64_t_);
} else {
Log::Fatal("Unknow data ptr bit type %d", row_ptr_bit_type_);
Log::Fatal("Unknown data ptr bit type %d", row_ptr_bit_type_);
}
}
} else {
Log::Fatal("Unknow bit type = %d", bit_type_);
Log::Fatal("Unknown bit type = %d", bit_type_);
}
SynchronizeCUDADevice(__FILE__, __LINE__);
}
Expand Down
11 changes: 6 additions & 5 deletions tests/python_package_test/test_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,12 +1730,13 @@ def test_training_succeeds_when_data_is_dataframe_and_label_is_column_array(task
y_col_array = y.reshape(-1, 1)
params = {"n_estimators": 1, "num_leaves": 3, "random_state": 0}
model_factory = task_to_model_factory[task]
with pytest.warns(UserWarning, match="column-vector"):
if task == "ranking":
model_1d = model_factory(**params).fit(X, y, group=g)
if task == "ranking":
model_1d = model_factory(**params).fit(X, y, group=g)
with pytest.warns(UserWarning, match="column-vector"):
model_2d = model_factory(**params).fit(X, y_col_array, group=g)
else:
model_1d = model_factory(**params).fit(X, y)
else:
model_1d = model_factory(**params).fit(X, y)
with pytest.warns(UserWarning, match="column-vector"):
model_2d = model_factory(**params).fit(X, y_col_array)

preds_1d = model_1d.predict(X)
Expand Down
Loading