From 61033ace28fb3958fd263303b9c4e45872f01c66 Mon Sep 17 00:00:00 2001 From: vnherdeiro Date: Wed, 28 Aug 2024 12:36:47 +0100 Subject: [PATCH 1/7] graphivz Tree4.gv Tree4.gv.pdf are no longer persisted --- tests/python_package_test/test_plotting.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/python_package_test/test_plotting.py b/tests/python_package_test/test_plotting.py index 2d68ead6a5ab..93377b0740c0 100644 --- a/tests/python_package_test/test_plotting.py +++ b/tests/python_package_test/test_plotting.py @@ -1,4 +1,7 @@ # coding: utf-8 + +from pathlib import Path + import numpy as np import pandas as pd import pytest @@ -177,7 +180,7 @@ def test_plot_tree(breast_cancer_split): @pytest.mark.skipif(not GRAPHVIZ_INSTALLED, reason="graphviz is not installed") -def test_create_tree_digraph(breast_cancer_split): +def test_create_tree_digraph(tmp_path, breast_cancer_split): X_train, _, y_train, _ = breast_cancer_split constraints = [-1, 1] * int(X_train.shape[1] / 2) @@ -193,6 +196,7 @@ def test_create_tree_digraph(breast_cancer_split): show_info=["split_gain", "internal_value", "internal_weight"], name="Tree4", node_attr={"color": "red"}, + directory=tmp_path ) graph.render(view=False) assert isinstance(graph, graphviz.Digraph) @@ -213,7 +217,7 @@ def test_create_tree_digraph(breast_cancer_split): @pytest.mark.skipif(not GRAPHVIZ_INSTALLED, reason="graphviz is not installed") -def test_tree_with_categories_below_max_category_values(): +def test_tree_with_categories_below_max_category_values(tmp_path: Path): X_train, y_train = _categorical_data(2, 10) params = { "n_estimators": 10, @@ -238,6 +242,7 @@ def test_tree_with_categories_below_max_category_values(): name="Tree4", node_attr={"color": "red"}, max_category_values=10, + directory=tmp_path, ) graph.render(view=False) assert isinstance(graph, graphviz.Digraph) @@ -257,7 +262,7 @@ def test_tree_with_categories_below_max_category_values(): @pytest.mark.skipif(not GRAPHVIZ_INSTALLED, reason="graphviz is not installed") -def test_tree_with_categories_above_max_category_values(): +def test_tree_with_categories_above_max_category_values(tmp_path: Path): X_train, y_train = _categorical_data(20, 30) params = { "n_estimators": 10, @@ -282,6 +287,7 @@ def test_tree_with_categories_above_max_category_values(): name="Tree4", node_attr={"color": "red"}, max_category_values=4, + directory=tmp_path, ) graph.render(view=False) assert isinstance(graph, graphviz.Digraph) From 41c4051e001cddf41a0ce7f19878639edbf410bb Mon Sep 17 00:00:00 2001 From: vnherdeiro Date: Wed, 28 Aug 2024 14:00:54 +0100 Subject: [PATCH 2/7] DAsk test goes to temp folder, no test artefact --- tests/python_package_test/test_dask.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/python_package_test/test_dask.py b/tests/python_package_test/test_dask.py index 37d6db2541f5..caf350239940 100644 --- a/tests/python_package_test/test_dask.py +++ b/tests/python_package_test/test_dask.py @@ -1527,11 +1527,11 @@ def test_predict_with_raw_score(task, output, cluster): assert_eq(raw_predictions, pred_proba_raw) -def test_distributed_quantized_training(cluster): +def test_distributed_quantized_training(tmp_path, cluster): with Client(cluster) as client: X, y, w, _, dX, dy, dw, _ = _create_data(objective="regression", output="array") - np.savetxt("data_dask.csv", np.hstack([np.array([y]).T, X]), fmt="%f,%f,%f,%f,%f") + np.savetxt(tmp_path / "data_dask.csv", np.hstack([y[:, None], X]), fmt="%f,%f,%f,%f,%f") params = { "boosting_type": "gbdt", From df7f55468ab75b596ed55c82d6044978dd057261 Mon Sep 17 00:00:00 2001 From: vnherdeiro Date: Wed, 28 Aug 2024 23:59:55 +0100 Subject: [PATCH 3/7] Update tests/python_package_test/test_plotting.py Co-authored-by: James Lamb --- tests/python_package_test/test_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python_package_test/test_plotting.py b/tests/python_package_test/test_plotting.py index 93377b0740c0..08049a4bdcdd 100644 --- a/tests/python_package_test/test_plotting.py +++ b/tests/python_package_test/test_plotting.py @@ -262,7 +262,7 @@ def test_tree_with_categories_below_max_category_values(tmp_path: Path): @pytest.mark.skipif(not GRAPHVIZ_INSTALLED, reason="graphviz is not installed") -def test_tree_with_categories_above_max_category_values(tmp_path: Path): +def test_tree_with_categories_above_max_category_values(tmp_path): X_train, y_train = _categorical_data(20, 30) params = { "n_estimators": 10, From 4edf45dfe0473ccae78bea92d7a68e2b104657f5 Mon Sep 17 00:00:00 2001 From: vnherdeiro Date: Thu, 29 Aug 2024 00:00:04 +0100 Subject: [PATCH 4/7] Update tests/python_package_test/test_plotting.py Co-authored-by: James Lamb --- tests/python_package_test/test_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python_package_test/test_plotting.py b/tests/python_package_test/test_plotting.py index 08049a4bdcdd..4771d049cc03 100644 --- a/tests/python_package_test/test_plotting.py +++ b/tests/python_package_test/test_plotting.py @@ -217,7 +217,7 @@ def test_create_tree_digraph(tmp_path, breast_cancer_split): @pytest.mark.skipif(not GRAPHVIZ_INSTALLED, reason="graphviz is not installed") -def test_tree_with_categories_below_max_category_values(tmp_path: Path): +def test_tree_with_categories_below_max_category_values(tmp_path): X_train, y_train = _categorical_data(2, 10) params = { "n_estimators": 10, From 31f7c6a3747ca0cbd5e26ba75d302401b46b9eb8 Mon Sep 17 00:00:00 2001 From: vnherdeiro Date: Thu, 29 Aug 2024 00:00:10 +0100 Subject: [PATCH 5/7] Update tests/python_package_test/test_plotting.py Co-authored-by: James Lamb --- tests/python_package_test/test_plotting.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/python_package_test/test_plotting.py b/tests/python_package_test/test_plotting.py index 4771d049cc03..ff8d70fc56c6 100644 --- a/tests/python_package_test/test_plotting.py +++ b/tests/python_package_test/test_plotting.py @@ -1,7 +1,4 @@ # coding: utf-8 - -from pathlib import Path - import numpy as np import pandas as pd import pytest From c4ab1ffc1a6ecc5836e824c60e6dc5d021e7bcaf Mon Sep 17 00:00:00 2001 From: vnherdeiro Date: Thu, 29 Aug 2024 00:26:07 +0100 Subject: [PATCH 6/7] adressing PR comment --- tests/python_package_test/test_dask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python_package_test/test_dask.py b/tests/python_package_test/test_dask.py index caf350239940..247f2eb10a54 100644 --- a/tests/python_package_test/test_dask.py +++ b/tests/python_package_test/test_dask.py @@ -1531,7 +1531,7 @@ def test_distributed_quantized_training(tmp_path, cluster): with Client(cluster) as client: X, y, w, _, dX, dy, dw, _ = _create_data(objective="regression", output="array") - np.savetxt(tmp_path / "data_dask.csv", np.hstack([y[:, None], X]), fmt="%f,%f,%f,%f,%f") + np.savetxt(tmp_path / "data_dask.csv", np.hstack([np.array([y]).T, X]), fmt="%f,%f,%f,%f,%f") params = { "boosting_type": "gbdt", From 484d4f842193b84052fc504941d633d705fe4f68 Mon Sep 17 00:00:00 2001 From: vnherdeiro Date: Fri, 30 Aug 2024 19:54:29 +0100 Subject: [PATCH 7/7] fixed ruff linting --- tests/python_package_test/test_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python_package_test/test_plotting.py b/tests/python_package_test/test_plotting.py index ff8d70fc56c6..9b3385de5eff 100644 --- a/tests/python_package_test/test_plotting.py +++ b/tests/python_package_test/test_plotting.py @@ -193,7 +193,7 @@ def test_create_tree_digraph(tmp_path, breast_cancer_split): show_info=["split_gain", "internal_value", "internal_weight"], name="Tree4", node_attr={"color": "red"}, - directory=tmp_path + directory=tmp_path, ) graph.render(view=False) assert isinstance(graph, graphviz.Digraph)