From fd722d60cdc06a3fd49c3284ae86e71e38cbe798 Mon Sep 17 00:00:00 2001 From: Sam Wilkinson Date: Fri, 14 Dec 2018 06:26:11 -0500 Subject: [PATCH] Deprecation warning for lists passed into DMatrix (#3970) * Ensure lists cannot be passed into DMatrix The documentation does not include lists as an allowed type for the data inputted into DMatrix. Despite this, a list can be passed in without an error. This change would prevent a list form being passed in directly. --- python-package/xgboost/core.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python-package/xgboost/core.py b/python-package/xgboost/core.py index 60ba97a40..cde339bb8 100644 --- a/python-package/xgboost/core.py +++ b/python-package/xgboost/core.py @@ -14,6 +14,7 @@ import ctypes import os import re import sys +import warnings import numpy as np import scipy.sparse @@ -381,6 +382,10 @@ class DMatrix(object): label = _maybe_dt_array(label) weight = _maybe_dt_array(weight) + if isinstance(data, list): + warnings.warn('Initializing DMatrix from List is deprecated.', + DeprecationWarning) + if isinstance(data, STRING_TYPES): self.handle = ctypes.c_void_p() _check_call(_LIB.XGDMatrixCreateFromFile(c_str(data),