Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing data warning. #5969

Merged
merged 3 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python-package/xgboost/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@


def _warn_unused_missing(data, missing):
if (not np.isnan(missing)) or (missing is None):
if (missing is not None) and (not np.isnan(missing)):
warnings.warn(
'`missing` is not used for current input data type:' +
str(type(data)))
str(type(data)), UserWarning)


def _check_complex(data):
Expand Down
26 changes: 25 additions & 1 deletion tests/python/test_dmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import xgboost as xgb
import unittest
import scipy.sparse
from scipy.sparse import rand
import pytest
from scipy.sparse import rand, csr_matrix

rng = np.random.RandomState(1)

Expand All @@ -12,6 +13,29 @@


class TestDMatrix(unittest.TestCase):
def test_warn_missing(self):
from xgboost import data
with pytest.warns(UserWarning):
data._warn_unused_missing('uri', 4)

with pytest.warns(None) as record:
data._warn_unused_missing('uri', None)
data._warn_unused_missing('uri', np.nan)

assert len(record) == 0
trivialfis marked this conversation as resolved.
Show resolved Hide resolved

with pytest.warns(None) as record:
x = rng.randn(10, 10)
y = rng.randn(10)

xgb.DMatrix(x, y, missing=4)

assert len(record) == 0

with pytest.warns(UserWarning):
csr = csr_matrix(x)
xgb.DMatrix(csr, y, missing=4)

def test_dmatrix_numpy_init(self):
data = np.random.randn(5, 5)
dm = xgb.DMatrix(data)
Expand Down