Define lazy isinstance for Python compat. (#5364)

* Avoid importing datatable.
* Fix #5363.
This commit is contained in:
Jiaming Yuan
2020-02-26 14:23:33 +08:00
committed by GitHub
parent 0fd455e162
commit a461a9a90a
4 changed files with 23 additions and 28 deletions

View File

@@ -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')

View File

@@ -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.'}