Skip to content

Commit

Permalink
Lazy import cuDF and Dask (#6522)
Browse files Browse the repository at this point in the history
* Lazy import cuDF

* Lazy import Dask

Co-authored-by: PSEUDOTENSOR / Jonathan McKinney <pseudotensor@gmail.com>

* Fix lint

Co-authored-by: PSEUDOTENSOR / Jonathan McKinney <pseudotensor@gmail.com>
  • Loading branch information
hcho3 and pseudotensor authored Dec 17, 2020
1 parent ad1a527 commit 125b3c0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
11 changes: 3 additions & 8 deletions python-package/xgboost/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ def lazy_isinstance(instance, module, name):
pandas_concat = None
PANDAS_INSTALLED = False

# cudf
try:
from cudf import concat as CUDF_concat
except ImportError:
CUDF_concat = None

# sklearn
try:
from sklearn.base import BaseEstimator
Expand Down Expand Up @@ -104,9 +98,10 @@ def from_json(self, doc):

# dask
try:
import dask
import pkg_resources
pkg_resources.get_distribution('dask')
DASK_INSTALLED = True
except ImportError:
except pkg_resources.DistributionNotFound:
dask = None
DASK_INSTALLED = False

Expand Down
2 changes: 1 addition & 1 deletion python-package/xgboost/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from .compat import LazyLoader
from .compat import sparse, scipy_sparse
from .compat import PANDAS_INSTALLED, DataFrame, Series, pandas_concat
from .compat import CUDF_concat
from .compat import lazy_isinstance

from .core import DMatrix, DeviceQuantileDMatrix, Booster, _expect, DataIter
Expand Down Expand Up @@ -121,6 +120,7 @@ def concat(value): # pylint: disable=too-many-return-statements
return pandas_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
return CUDF_concat(value, axis=0)
if lazy_isinstance(value[0], 'cupy.core.core', 'ndarray'):
import cupy # pylint: disable=import-error
Expand Down

0 comments on commit 125b3c0

Please sign in to comment.