Skip to content

Commit 336a77d

Browse files
authored
[python-package] Add unit test for Dataset.set_field and no data (#7036)
1 parent 8946151 commit 336a77d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/python_package_test/test_basic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,3 +1017,16 @@ def test_equal_datasets_from_one_and_several_matrices_w_different_layouts(rng, t
10171017
lgb.Dataset(mat)._dump_text(one_path)
10181018

10191019
assert filecmp.cmp(one_path, several_path)
1020+
1021+
1022+
def test_set_field_none_removes_field(rng):
1023+
X1 = rng.uniform(size=(10, 1))
1024+
d1 = lgb.Dataset(X1).construct()
1025+
weight = rng.uniform(size=10)
1026+
out = d1.set_field("weight", weight)
1027+
assert out is d1
1028+
1029+
np.testing.assert_allclose(d1.get_field("weight"), weight)
1030+
1031+
d1.set_field("weight", None)
1032+
assert d1.get_field("weight") is None

0 commit comments

Comments
 (0)