diff --git a/.ci/test.sh b/.ci/test.sh index cc8831f94c09..82c159064a33 100755 --- a/.ci/test.sh +++ b/.ci/test.sh @@ -146,8 +146,8 @@ if [[ $TASK == "check-docs" ]] || [[ $TASK == "check-links" ]]; then make -C docs html || exit 1 if [[ $TASK == "check-links" ]]; then # check docs for broken links - pip install linkchecker - linkchecker --config=.linkcheckerrc ./docs/_build/html/*.html || exit 1 + pip install 'linkchecker>=10.5.0' + linkchecker --config=./docs/.linkcheckerrc ./docs/_build/html/*.html || exit 1 exit 0 fi # check the consistency of parameters' descriptions and other stuff diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b334db19b8e7..0edab8df1be6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,15 +17,9 @@ repos: hooks: - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/isort - rev: 5.13.2 - hooks: - - id: isort - name: isort (python) - args: ["--settings-path", "python-package/pyproject.toml"] - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.7.0 + rev: v0.8.3 hooks: # Run the linter. - id: ruff @@ -40,7 +34,7 @@ repos: hooks: - id: shellcheck - repo: https://github.com/crate-ci/typos - rev: v1.23.2 + rev: v1.28.3 hooks: - id: typos args: ["--force-exclude"] diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 3a111e10898e..40424840c82d 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -69,15 +69,17 @@ jobs: # check disk usage print-diagnostics # remove old containers, container images, volumes - # ref: https://stackoverflow.com/a/32723127/3986677) + # ref: https://stackoverflow.com/a/32723127/3986677 + # ref: https://depot.dev/blog/docker-clear-cache#removing-everything-with-docker-system-prune echo "---- running 'docker system prune' ----" /tmp/docker system prune \ --all \ --force \ + --volumes \ --filter until=720h # check disk usage again print-diagnostics - displayName: clean + displayName: Clean ########################################### - job: Linux ########################################### diff --git a/R-package/tests/testthat/test_basic.R b/R-package/tests/testthat/test_basic.R index 7310815c4a6d..06d35a146d66 100644 --- a/R-package/tests/testthat/test_basic.R +++ b/R-package/tests/testthat/test_basic.R @@ -2345,7 +2345,7 @@ test_that("early stopping works with lgb.cv()", { # never changes, its first iteration was the best oone expect_equal(bst$best_iter, 1L) - # best_score should be taken from the first metri + # best_score should be taken from the first metric expect_equal(bst$best_score, 0.2) # early stopping should have happened, since constant_metric was the first diff --git a/docs/.linkcheckerrc b/docs/.linkcheckerrc index 003d8699a875..a4707aa536ea 100644 --- a/docs/.linkcheckerrc +++ b/docs/.linkcheckerrc @@ -1,9 +1,9 @@ [checking] -maxrequestspersecond=1 +maxrequestspersecond=0.1 recursionlevel=1 anchors=1 sslverify=0 -threads=1 +threads=4 [filtering] ignore= diff --git a/examples/python-guide/notebooks/interactive_plot_example.ipynb b/examples/python-guide/notebooks/interactive_plot_example.ipynb index cc8efa2c187b..a8abdf325d9d 100644 --- a/examples/python-guide/notebooks/interactive_plot_example.ipynb +++ b/examples/python-guide/notebooks/interactive_plot_example.ipynb @@ -30,7 +30,7 @@ "try:\n", " # To enable interactive mode you should install ipywidgets\n", " # https://github.com/jupyter-widgets/ipywidgets\n", - " from ipywidgets import interact, SelectMultiple\n", + " from ipywidgets import SelectMultiple, interact\n", "\n", " INTERACTIVE = True\n", "except ImportError:\n", diff --git a/python-package/lightgbm/basic.py b/python-package/lightgbm/basic.py index 1db55385af1b..e06290dc1c5f 100644 --- a/python-package/lightgbm/basic.py +++ b/python-package/lightgbm/basic.py @@ -1291,10 +1291,7 @@ def __inner_predict_np2d( predict_type: int, preds: Optional[np.ndarray], ) -> Tuple[np.ndarray, int]: - if mat.dtype == np.float32 or mat.dtype == np.float64: - 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) + data, layout = _np2d_to_np1d(mat) ptr_data, type_ptr_data, _ = _c_float_array(data) n_preds = self.__get_num_preds( start_iteration=start_iteration, @@ -1314,7 +1311,7 @@ def __inner_predict_np2d( ctypes.c_int(type_ptr_data), ctypes.c_int32(mat.shape[0]), ctypes.c_int32(mat.shape[1]), - ctypes.c_int(_C_API_IS_ROW_MAJOR), + ctypes.c_int(layout), ctypes.c_int(predict_type), ctypes.c_int(start_iteration), ctypes.c_int(num_iteration), @@ -2507,13 +2504,13 @@ def _compare_params_for_warning( compare_result : bool Returns whether two dictionaries with params are equal. """ - for k in other_params: + for k, v in other_params.items(): if k not in ignore_keys: - if k not in params or params[k] != other_params[k]: + if k not in params or params[k] != v: return False - for k in params: + for k, v in params.items(): if k not in ignore_keys: - if k not in other_params or params[k] != other_params[k]: + if k not in other_params or v != other_params[k]: return False return True diff --git a/python-package/pyproject.toml b/python-package/pyproject.toml index 19866e01202b..8fcc85814db5 100644 --- a/python-package/pyproject.toml +++ b/python-package/pyproject.toml @@ -84,17 +84,6 @@ minimum-version = "build-system.requires" # end:build-system -[tool.isort] -include_trailing_comma = true -line_length = 120 -# "vertical hanging indent", to match what ruff-format does -# ref: https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html#3-vertical-hanging-indent -multi_line_output = 3 -skip_glob = [ - "*/external_libs/*", - "*/lightgbm-python/*", -] - [tool.mypy] disallow_untyped_defs = true exclude = 'build/*|compile/*|docs/*|examples/*|external_libs/*|lightgbm-python/*|tests/*' @@ -140,7 +129,7 @@ ignore = [ "PLR1714", # (pylint) Magic value used in comparison "PLR2004", - # (pylint) for loop veriable overwritten by assignment target + # (pylint) for loop variable overwritten by assignment target "PLW2901", # (pylint) use 'elif' instead of 'else' then 'if', to reduce indentation "PLR5501" @@ -152,10 +141,12 @@ select = [ "C4", # pydocstyle "D", - # pycodestyle + # pycodestyle (errors) "E", # pyflakes "F", + # isort + "I", # NumPy-specific rules "NPY", # pylint @@ -166,11 +157,13 @@ select = [ "SIM401", # flake8-print "T", + # pycodestyle (warnings) + "W", ] [tool.ruff.lint.per-file-ignores] "docs/conf.py" = [ - # (flake8-bugbear) raise exceptions with "raise ... from errr" + # (flake8-bugbear) raise exceptions with "raise ... from err" "B904", # (flake8-print) flake8-print "T" @@ -196,3 +189,6 @@ select = [ [tool.ruff.lint.pydocstyle] convention = "numpy" + +[tool.ruff.lint.isort] +known-first-party = ["lightgbm"] diff --git a/src/objective/rank_objective.hpp b/src/objective/rank_objective.hpp index ba8496ec4864..8227c7b65658 100644 --- a/src/objective/rank_objective.hpp +++ b/src/objective/rank_objective.hpp @@ -204,7 +204,7 @@ class LambdarankNDCG : public RankingObjective { } const double worst_score = score[sorted_idx[worst_idx]]; double sum_lambdas = 0.0; - // start accmulate lambdas by pairs that contain at least one document above truncation level + // start accumulate lambdas by pairs that contain at least one document above truncation level for (data_size_t i = 0; i < cnt - 1 && i < truncation_level_; ++i) { if (score[sorted_idx[i]] == kMinScore) { continue; } for (data_size_t j = i + 1; j < cnt; ++j) { diff --git a/src/treelearner/kernels/histogram_16_64_256.cu b/src/treelearner/kernels/histogram_16_64_256.cu index 59662fb19d55..9d8427a6f9a8 100644 --- a/src/treelearner/kernels/histogram_16_64_256.cu +++ b/src/treelearner/kernels/histogram_16_64_256.cu @@ -150,7 +150,7 @@ __global__ void KERNEL_NAME(const uchar* feature_data_base, // size of threads that process this feature4 const unsigned int subglobal_size = lsize * (1 << power_feature_workgroups); - // equavalent thread ID in this subgroup for this feature4 + // equivalent thread ID in this subgroup for this feature4 const unsigned int subglobal_tid = gtid - feature_id * subglobal_size; diff --git a/tests/python_package_test/test_engine.py b/tests/python_package_test/test_engine.py index cb2e893c9612..05afddb77c77 100644 --- a/tests/python_package_test/test_engine.py +++ b/tests/python_package_test/test_engine.py @@ -4611,3 +4611,18 @@ def test_bagging_by_query_in_lambdarank(): ndcg_score_no_bagging_by_query = gbm_no_bagging_by_query.best_score["valid_0"]["ndcg@5"] assert ndcg_score_bagging_by_query >= ndcg_score - 0.1 assert ndcg_score_no_bagging_by_query >= ndcg_score - 0.1 + + +def test_equal_predict_from_row_major_and_col_major_data(): + X_row, y = make_synthetic_regression() + assert X_row.flags["C_CONTIGUOUS"] and not X_row.flags["F_CONTIGUOUS"] + ds = lgb.Dataset(X_row, y) + params = {"num_leaves": 8, "verbose": -1} + bst = lgb.train(params, ds, num_boost_round=5) + preds_row = bst.predict(X_row) + + X_col = np.asfortranarray(X_row) + assert X_col.flags["F_CONTIGUOUS"] and not X_col.flags["C_CONTIGUOUS"] + preds_col = bst.predict(X_col) + + np.testing.assert_allclose(preds_row, preds_col)