Skip to content

Commit

Permalink
[dask] Refactor for learning to rank. (#11012)
Browse files Browse the repository at this point in the history
- Move data handling code into an independent module.
- Move ranking tests into an independent module.
- Use global pylint disable for import error.
- Remove the old ranking demo.
  • Loading branch information
trivialfis authored Nov 22, 2024
1 parent 2e189a8 commit e988b7c
Show file tree
Hide file tree
Showing 28 changed files with 389 additions and 544 deletions.
41 changes: 0 additions & 41 deletions demo/rank/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions demo/rank/mq2008.conf

This file was deleted.

41 changes: 0 additions & 41 deletions demo/rank/rank.py

This file was deleted.

35 changes: 0 additions & 35 deletions demo/rank/rank_sklearn.py

This file was deleted.

4 changes: 0 additions & 4 deletions demo/rank/runexp.sh

This file was deleted.

41 changes: 0 additions & 41 deletions demo/rank/trans_data.py

This file was deleted.

16 changes: 0 additions & 16 deletions demo/rank/wgetdata.sh

This file was deleted.

3 changes: 2 additions & 1 deletion python-package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers = [
"License :: OSI Approved :: Apache Software License",
"Development Status :: 5 - Production/Stable",
"Operating System :: OS Independent",
"Typing :: Typed",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
Expand Down Expand Up @@ -59,10 +60,10 @@ follow_imports = "silent"
ignore = ["tests"]
extension-pkg-whitelist = ["numpy"]
disable = [
"import-error",
"attribute-defined-outside-init",
"import-outside-toplevel",
"too-many-nested-blocks",
"unexpected-special-method-signature",
"unsubscriptable-object",
"useless-object-inheritance"
]
Expand Down
15 changes: 7 additions & 8 deletions python-package/xgboost/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ def lazy_isinstance(instance: Any, module: str, name: str) -> bool:

# pandas
try:
from pandas import DataFrame, MultiIndex, Series
from pandas import concat as pandas_concat
from pandas import DataFrame, Series

PANDAS_INSTALLED = True
except ImportError:
MultiIndex = object
DataFrame = object
Series = object
pandas_concat = None
PANDAS_INSTALLED = False


Expand Down Expand Up @@ -106,7 +103,7 @@ def import_cupy() -> types.ModuleType:
if not is_cupy_available():
raise ImportError("`cupy` is required for handling CUDA buffer.")

import cupy # pylint: disable=import-error
import cupy

return cupy

Expand All @@ -132,17 +129,19 @@ def concat(value: Sequence[_T]) -> _T: # pylint: disable=too-many-return-statem
# other sparse format will be converted to CSR.
return scipy_sparse.vstack(value, format="csr")
if PANDAS_INSTALLED and isinstance(value[0], (DataFrame, Series)):
return pandas_concat(value, axis=0)
from pandas import concat as pd_concat

return pd_concat(value, axis=0)
if lazy_isinstance(value[0], "cudf.core.dataframe", "DataFrame") or lazy_isinstance(
value[0], "cudf.core.series", "Series"
):
from cudf import concat as CUDF_concat # pylint: disable=import-error
from cudf import concat as CUDF_concat

return CUDF_concat(value, axis=0)
from .data import _is_cupy_alike

if _is_cupy_alike(value[0]):
import cupy # pylint: disable=import-error
import cupy

# pylint: disable=c-extension-no-member,no-member
d = cupy.cuda.runtime.getDevice()
Expand Down
Loading

0 comments on commit e988b7c

Please sign in to comment.