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

[ci] prevent train.binary.bin and lgb_train_data.bin files being left behind after testing #6606

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions tests/c_api_test/test_.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def free_dataset(handle):
LIB.LGBM_DatasetFree(handle)


def test_dataset():
def test_dataset(tmp_path):
binary_example_dir = Path(__file__).absolute().parents[2] / "examples" / "binary_classification"
train = load_from_file(binary_example_dir / "binary.train", None)
test = load_from_mat(binary_example_dir / "binary.test", train)
Expand All @@ -169,9 +169,10 @@ def test_dataset():
free_dataset(test)
test = load_from_csc(binary_example_dir / "binary.test", train)
free_dataset(test)
save_to_binary(train, "train.binary.bin")
train_binary = str(tmp_path / "train.binary.bin")
save_to_binary(train, train_binary)
free_dataset(train)
train = load_from_file("train.binary.bin", None)
train = load_from_file(train_binary, None)
free_dataset(train)


Expand Down
13 changes: 7 additions & 6 deletions tests/python_package_test/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ def train_and_get_predictions(features, labels):
np.testing.assert_allclose(origin_pred, sliced_pred)


def test_init_with_subset(rng):
def test_init_with_subset(tmp_path, rng):
data = rng.uniform(size=(50, 2))
y = [1] * 25 + [0] * 25
lgb_train = lgb.Dataset(data, y, free_raw_data=False)
Expand All @@ -2035,16 +2035,17 @@ def test_init_with_subset(rng):
assert lgb_train.get_data().shape[0] == 50
assert subset_data_1.get_data().shape[0] == 30
assert subset_data_2.get_data().shape[0] == 20
lgb_train.save_binary("lgb_train_data.bin")
lgb_train_from_file = lgb.Dataset("lgb_train_data.bin", free_raw_data=False)
lgb_train_data = str(tmp_path / "lgb_train_data.bin")
lgb_train.save_binary(lgb_train_data)
lgb_train_from_file = lgb.Dataset(lgb_train_data, free_raw_data=False)
subset_data_3 = lgb_train_from_file.subset(subset_index_1)
subset_data_4 = lgb_train_from_file.subset(subset_index_2)
init_gbm_2 = lgb.train(params=params, train_set=subset_data_3, num_boost_round=10, keep_training_booster=True)
with np.testing.assert_raises_regex(lgb.basic.LightGBMError, "Unknown format of training data"):
lgb.train(params=params, train_set=subset_data_4, num_boost_round=10, init_model=init_gbm_2)
assert lgb_train_from_file.get_data() == "lgb_train_data.bin"
assert subset_data_3.get_data() == "lgb_train_data.bin"
assert subset_data_4.get_data() == "lgb_train_data.bin"
assert lgb_train_from_file.get_data() == lgb_train_data
assert subset_data_3.get_data() == lgb_train_data
assert subset_data_4.get_data() == lgb_train_data


def test_training_on_constructed_subset_without_params(rng):
Expand Down
Loading