Skip to content

Commit

Permalink
Ensure lists cannot be passed into DMatrix
Browse files Browse the repository at this point in the history
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.

I experienced an issue where passing in a list vs a np.array resulted in different predictions (sometimes over 10% relative difference) for the same data. Though these differences were infrequent (~1.5% of cases tested), in certain applications this could cause serious issues.
  • Loading branch information
scwilkinson authored Dec 5, 2018
1 parent 48dddfd commit ce1bbf4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion python-package/xgboost/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ def __init__(self, data, label=None, missing=None,
label = _maybe_dt_array(label)
weight = _maybe_dt_array(weight)

if isinstance(data, STRING_TYPES):
if isinstance(data, list):
raise TypeError('can not initialize DMatrix from list)
elif isinstance(data, STRING_TYPES):
self.handle = ctypes.c_void_p()
_check_call(_LIB.XGDMatrixCreateFromFile(c_str(data),
ctypes.c_int(silent),
Expand Down

0 comments on commit ce1bbf4

Please sign in to comment.