Unverified Commit 336a77df authored by Thomas J. Fan's avatar Thomas J. Fan Committed by GitHub
Browse files

[python-package] Add unit test for Dataset.set_field and no data (#7036)

parent 89461519
......@@ -1017,3 +1017,16 @@ def test_equal_datasets_from_one_and_several_matrices_w_different_layouts(rng, t
lgb.Dataset(mat)._dump_text(one_path)
assert filecmp.cmp(one_path, several_path)
def test_set_field_none_removes_field(rng):
X1 = rng.uniform(size=(10, 1))
d1 = lgb.Dataset(X1).construct()
weight = rng.uniform(size=10)
out = d1.set_field("weight", weight)
assert out is d1
np.testing.assert_allclose(d1.get_field("weight"), weight)
d1.set_field("weight", None)
assert d1.get_field("weight") is None
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment