Unverified Commit 16ca335b authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[ci] update pre-commit versions, add some pixi things to config files (#6986)

parent 915c2706
...@@ -466,3 +466,6 @@ dask-worker-space/ ...@@ -466,3 +466,6 @@ dask-worker-space/
# hipify-perl -inplace leaves behind *.prehip files # hipify-perl -inplace leaves behind *.prehip files
*.prehip *.prehip
# pixi environments
.pixi
...@@ -18,13 +18,13 @@ repos: ...@@ -18,13 +18,13 @@ repos:
- id: end-of-file-fixer - id: end-of-file-fixer
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/adrienverge/yamllint - repo: https://github.com/adrienverge/yamllint
rev: v1.35.1 rev: v1.37.1
hooks: hooks:
- id: yamllint - id: yamllint
args: ["--strict"] args: ["--strict"]
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version. # Ruff version.
rev: v0.9.10 rev: v0.12.5
hooks: hooks:
# Run the linter. # Run the linter.
- id: ruff - id: ruff
...@@ -39,13 +39,13 @@ repos: ...@@ -39,13 +39,13 @@ repos:
hooks: hooks:
- id: shellcheck - id: shellcheck
- repo: https://github.com/crate-ci/typos - repo: https://github.com/crate-ci/typos
rev: v1.30.2 rev: v1.34.0
hooks: hooks:
- id: typos - id: typos
args: ["--force-exclude"] args: ["--force-exclude"]
exclude: (\.gitignore$)|(^\.editorconfig$) exclude: (\.gitignore$)|(^\.editorconfig$)
- repo: https://github.com/henryiii/validate-pyproject-schema-store - repo: https://github.com/henryiii/validate-pyproject-schema-store
rev: 2025.03.10 rev: 2025.07.14
hooks: hooks:
- id: validate-pyproject - id: validate-pyproject
files: python-package/pyproject.toml$ files: python-package/pyproject.toml$
{ {
"files": { "files": {
"ignore": [".mypy_cache/"] "ignore": [".mypy_cache/", ".pixi/"]
}, },
"formatter": { "formatter": {
"enabled": true, "enabled": true,
......
...@@ -67,7 +67,7 @@ class IgnoredDirective(Directive): ...@@ -67,7 +67,7 @@ class IgnoredDirective(Directive):
# -- General configuration ------------------------------------------------ # -- General configuration ------------------------------------------------
os.environ["LIGHTGBM_BUILD_DOC"] = "1" os.environ["LIGHTGBM_BUILD_DOC"] = "True"
C_API = os.environ.get("C_API", "").lower().strip() != "no" C_API = os.environ.get("C_API", "").lower().strip() != "no"
RTD = bool(os.environ.get("READTHEDOCS", "")) RTD = bool(os.environ.get("READTHEDOCS", ""))
RTD_VERSION = os.environ.get("READTHEDOCS_VERSION", "stable") RTD_VERSION = os.environ.get("READTHEDOCS_VERSION", "stable")
......
...@@ -287,7 +287,7 @@ def _log_callback(msg: bytes) -> None: ...@@ -287,7 +287,7 @@ def _log_callback(msg: bytes) -> None:
# connect the Python logger to logging in lib_lightgbm # 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 _LIB.LGBM_GetLastError.restype = ctypes.c_char_p
callback = ctypes.CFUNCTYPE(None, ctypes.c_char_p) callback = ctypes.CFUNCTYPE(None, ctypes.c_char_p)
_LIB.callback = callback(_log_callback) # type: ignore[attr-defined] _LIB.callback = callback(_log_callback) # type: ignore[attr-defined]
...@@ -840,7 +840,7 @@ def _data_from_pandas( ...@@ -840,7 +840,7 @@ def _data_from_pandas(
for col, category in zip(cat_cols, pandas_categorical): for col, category in zip(cat_cols, pandas_categorical):
if list(data[col].cat.categories) != list(category): if list(data[col].cat.categories) != list(category):
data[col] = data[col].cat.set_categories(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}) data[cat_cols] = data[cat_cols].apply(lambda x: x.cat.codes).replace({-1: np.nan})
# use cat cols from DataFrame # use cat cols from DataFrame
......
...@@ -74,7 +74,7 @@ class CallbackEnv: ...@@ -74,7 +74,7 @@ class CallbackEnv:
def _is_using_cv(env: CallbackEnv) -> bool: def _is_using_cv(env: CallbackEnv) -> bool:
"""Check if model in callback env is a CVBooster.""" """Check if model in callback env is a CVBooster."""
# this import is here to avoid a circular import # this import is here to avoid a circular import
from .engine import CVBooster from .engine import CVBooster # noqa: PLC0415
return isinstance(env.model, CVBooster) return isinstance(env.model, CVBooster)
......
...@@ -52,7 +52,7 @@ try: ...@@ -52,7 +52,7 @@ try:
# * lightgbm cannot be used with scikit-learn versions older than that # * 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 # * 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 # _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 # because scikit-learn's 'check_fit1d' estimator check sets that expectation that
......
...@@ -769,7 +769,7 @@ def _train( ...@@ -769,7 +769,7 @@ def _train(
) )
raise LightGBMError(msg) 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: else:
_log_info("Finding random open ports for workers") _log_info("Finding random open ports for workers")
worker_to_socket_future, worker_address_to_port = _assign_open_ports_to_workers( worker_to_socket_future, worker_address_to_port = _assign_open_ports_to_workers(
......
...@@ -41,7 +41,7 @@ def _find_lib_path() -> List[str]: ...@@ -41,7 +41,7 @@ def _find_lib_path() -> List[str]:
# we don't need lib_lightgbm while building docs # we don't need lib_lightgbm while building docs
_LIB: ctypes.CDLL _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 from unittest.mock import Mock # isort: skip
_LIB = Mock(ctypes.CDLL) # type: ignore _LIB = Mock(ctypes.CDLL) # type: ignore
......
...@@ -104,7 +104,7 @@ def plot_importance( ...@@ -104,7 +104,7 @@ def plot_importance(
The plot with model's feature importances. The plot with model's feature importances.
""" """
if MATPLOTLIB_INSTALLED: if MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt import matplotlib.pyplot as plt # noqa: PLC0415
else: else:
raise ImportError("You must install matplotlib and restart your session to plot importance.") raise ImportError("You must install matplotlib and restart your session to plot importance.")
...@@ -235,8 +235,8 @@ def plot_split_value_histogram( ...@@ -235,8 +235,8 @@ def plot_split_value_histogram(
The plot with specified model's feature split value histogram. The plot with specified model's feature split value histogram.
""" """
if MATPLOTLIB_INSTALLED: if MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt import matplotlib.pyplot as plt # noqa: PLC0415
from matplotlib.ticker import MaxNLocator from matplotlib.ticker import MaxNLocator # noqa: PLC0415
else: else:
raise ImportError("You must install matplotlib and restart your session to plot split value histogram.") raise ImportError("You must install matplotlib and restart your session to plot split value histogram.")
...@@ -342,7 +342,7 @@ def plot_metric( ...@@ -342,7 +342,7 @@ def plot_metric(
The plot with metric's history over the training. The plot with metric's history over the training.
""" """
if MATPLOTLIB_INSTALLED: if MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt import matplotlib.pyplot as plt # noqa: PLC0415
else: else:
raise ImportError("You must install matplotlib and restart your session to plot metric.") raise ImportError("You must install matplotlib and restart your session to plot metric.")
...@@ -468,7 +468,7 @@ def _to_graphviz( ...@@ -468,7 +468,7 @@ def _to_graphviz(
- https://graphviz.readthedocs.io/en/stable/api.html#digraph - https://graphviz.readthedocs.io/en/stable/api.html#digraph
""" """
if GRAPHVIZ_INSTALLED: if GRAPHVIZ_INSTALLED:
from graphviz import Digraph from graphviz import Digraph # noqa: PLC0415
else: else:
raise ImportError("You must install graphviz and restart your session to plot tree.") raise ImportError("You must install graphviz and restart your session to plot tree.")
...@@ -812,8 +812,8 @@ def plot_tree( ...@@ -812,8 +812,8 @@ def plot_tree(
The plot with single tree. The plot with single tree.
""" """
if MATPLOTLIB_INSTALLED: if MATPLOTLIB_INSTALLED:
import matplotlib.image import matplotlib.image # noqa: PLC0415
import matplotlib.pyplot as plt import matplotlib.pyplot as plt # noqa: PLC0415
else: else:
raise ImportError("You must install matplotlib and restart your session to plot tree.") raise ImportError("You must install matplotlib and restart your session to plot tree.")
......
...@@ -135,7 +135,7 @@ void CUDAColumnData::Init(const int num_columns, ...@@ -135,7 +135,7 @@ void CUDAColumnData::Init(const int num_columns,
} else if (bit_type == 32) { } else if (bit_type == 32) {
InitOneColumnData<false, false, uint32_t>(column_data[column_index], nullptr, &data_by_column_[column_index]); InitOneColumnData<false, false, uint32_t>(column_data[column_index], nullptr, &data_by_column_[column_index]);
} else { } else {
Log::Fatal("Unknow column bit type %d", bit_type); Log::Fatal("Unknown column bit type %d", bit_type);
} }
} else { } else {
// is sparse column // is sparse column
...@@ -146,7 +146,7 @@ void CUDAColumnData::Init(const int num_columns, ...@@ -146,7 +146,7 @@ void CUDAColumnData::Init(const int num_columns,
} else if (bit_type == 32) { } else if (bit_type == 32) {
InitOneColumnData<true, false, uint32_t>(nullptr, column_bin_iterator[column_index], &data_by_column_[column_index]); InitOneColumnData<true, false, uint32_t>(nullptr, column_bin_iterator[column_index], &data_by_column_[column_index]);
} else { } else {
Log::Fatal("Unknow column bit type %d", bit_type); Log::Fatal("Unknown column bit type %d", bit_type);
} }
} }
OMP_LOOP_EX_END(); OMP_LOOP_EX_END();
......
...@@ -105,7 +105,7 @@ void CUDARowData::Init(const Dataset* train_data, TrainingShareStates* train_sha ...@@ -105,7 +105,7 @@ void CUDARowData::Init(const Dataset* train_data, TrainingShareStates* train_sha
&cuda_row_ptr_uint64_t_, &cuda_row_ptr_uint64_t_,
&cuda_partition_ptr_uint64_t_); &cuda_partition_ptr_uint64_t_);
} else { } 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) { } else if (bit_type_ == 16) {
...@@ -136,7 +136,7 @@ void CUDARowData::Init(const Dataset* train_data, TrainingShareStates* train_sha ...@@ -136,7 +136,7 @@ void CUDARowData::Init(const Dataset* train_data, TrainingShareStates* train_sha
&cuda_row_ptr_uint64_t_, &cuda_row_ptr_uint64_t_,
&cuda_partition_ptr_uint64_t_); &cuda_partition_ptr_uint64_t_);
} else { } 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) { } else if (bit_type_ == 32) {
...@@ -167,11 +167,11 @@ void CUDARowData::Init(const Dataset* train_data, TrainingShareStates* train_sha ...@@ -167,11 +167,11 @@ void CUDARowData::Init(const Dataset* train_data, TrainingShareStates* train_sha
&cuda_row_ptr_uint64_t_, &cuda_row_ptr_uint64_t_,
&cuda_partition_ptr_uint64_t_); &cuda_partition_ptr_uint64_t_);
} else { } 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 { } else {
Log::Fatal("Unknow bit type = %d", bit_type_); Log::Fatal("Unknown bit type = %d", bit_type_);
} }
SynchronizeCUDADevice(__FILE__, __LINE__); SynchronizeCUDADevice(__FILE__, __LINE__);
} }
......
...@@ -1730,12 +1730,13 @@ def test_training_succeeds_when_data_is_dataframe_and_label_is_column_array(task ...@@ -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) y_col_array = y.reshape(-1, 1)
params = {"n_estimators": 1, "num_leaves": 3, "random_state": 0} params = {"n_estimators": 1, "num_leaves": 3, "random_state": 0}
model_factory = task_to_model_factory[task] model_factory = task_to_model_factory[task]
with pytest.warns(UserWarning, match="column-vector"):
if task == "ranking": if task == "ranking":
model_1d = model_factory(**params).fit(X, y, group=g) 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) model_2d = model_factory(**params).fit(X, y_col_array, group=g)
else: else:
model_1d = model_factory(**params).fit(X, y) 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) model_2d = model_factory(**params).fit(X, y_col_array)
preds_1d = model_1d.predict(X) preds_1d = model_1d.predict(X)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment