Skip to content

Commit

Permalink
pylint.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Mar 2, 2023
1 parent 7b06c19 commit 869bceb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python-package/xgboost/collective.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def allreduce(data: np.ndarray, op: Op) -> np.ndarray: # pylint:disable=invalid
if buf.base is data.base:
buf = buf.copy()
if buf.dtype not in DTYPE_ENUM__:
raise Exception(f"data type {buf.dtype} not supported")
raise TypeError(f"data type {buf.dtype} not supported")
_check_call(
_LIB.XGCommunicatorAllreduce(
buf.ctypes.data_as(ctypes.c_void_p),
Expand Down
2 changes: 1 addition & 1 deletion python-package/xgboost/rabit.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def allreduce( # pylint:disable=invalid-name
"""
if prepare_fun is None:
return collective.allreduce(data, collective.Op(op))
raise Exception("preprocessing function is no longer supported")
raise ValueError("preprocessing function is no longer supported")


def version_number() -> int:
Expand Down
5 changes: 3 additions & 2 deletions python-package/xgboost/testing/ranking.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=too-many-locals
"""Tests for learning to rank."""
from types import ModuleType
from typing import Any
Expand All @@ -15,7 +16,7 @@ def run_ranking_qid_df(impl: ModuleType, tree_method: str) -> None:
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import StratifiedGroupKFold, cross_val_score

X, y, q, w = tm.make_ltr(n_samples=128, n_features=2, n_query_groups=8, max_rel=3)
X, y, q, _ = tm.make_ltr(n_samples=128, n_features=2, n_query_groups=8, max_rel=3)

# pack qid into x using dataframe
df = impl.DataFrame(X)
Expand Down Expand Up @@ -45,7 +46,7 @@ def run_ranking_qid_df(impl: ModuleType, tree_method: str) -> None:

# Works with custom metric
def neg_mse(*args: Any, **kwargs: Any) -> float:
return -mean_squared_error(*args, **kwargs)
return -float(mean_squared_error(*args, **kwargs))

ranker = xgb.XGBRanker(n_estimators=3, eval_metric=neg_mse, tree_method=tree_method)
ranker.fit(df, y, eval_set=[(valid_df, y)])
Expand Down

0 comments on commit 869bceb

Please sign in to comment.