Define lazy isinstance for Python compat. (#5364)
* Avoid importing datatable. * Fix #5363.
This commit is contained in:
@@ -36,6 +36,11 @@ def captured_output():
|
||||
|
||||
|
||||
class TestBasic(unittest.TestCase):
|
||||
def test_compat(self):
|
||||
from xgboost.compat import lazy_isinstance
|
||||
a = np.array([1, 2, 3])
|
||||
assert lazy_isinstance(a, 'numpy', 'ndarray')
|
||||
assert not lazy_isinstance(a, 'numpy', 'dataframe')
|
||||
|
||||
def test_basic(self):
|
||||
dtrain = xgb.DMatrix(dpath + 'agaricus.txt.train')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# coding: utf-8
|
||||
from xgboost.compat import SKLEARN_INSTALLED, PANDAS_INSTALLED, DT_INSTALLED
|
||||
from xgboost.compat import SKLEARN_INSTALLED, PANDAS_INSTALLED
|
||||
from xgboost.compat import CUDF_INSTALLED, DASK_INSTALLED
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ def no_pandas():
|
||||
|
||||
|
||||
def no_dt():
|
||||
return {'condition': not DT_INSTALLED,
|
||||
import importlib.util
|
||||
spec = importlib.util.find_spec('datatable')
|
||||
return {'condition': spec is None,
|
||||
'reason': 'Datatable is not installed.'}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user