Skip to content

fix: resolve 10 SonarQube naming convention violations in tree tests#567

Open
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260520-145313-6a9740c9
Open

fix: resolve 10 SonarQube naming convention violations in tree tests#567
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260520-145313-6a9740c9

Conversation

@sonarqube-agent
Copy link
Copy Markdown

Corrects Python naming convention violations in sklearn/tree/tests/test_tree.py by renaming parameters and variables from PascalCase to snake_case to match code style standards (S117) and fixing an unused loop variable (S1481). These changes improve code consistency and eliminate SonarQube quality warnings.

View Project in SonarCloud


Fixed Issues

python:S117 - Rename this parameter "Tree" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2594

Why is this an issue?

A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.

What changed

Renames the pytest.mark.parametrize argument and function parameter from 'Tree' to 'tree' in the test_missing_values_poisson function, directly fixing the naming convention violation where 'Tree' at line 2594 did not match the required snake_case pattern.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2593,2 +2593,2 @@ def test_missing_value_errors(sparse_container, tree):
-@pytest.mark.parametrize("Tree", REG_TREES.values())
-def test_missing_values_poisson(Tree):
+@pytest.mark.parametrize("tree", REG_TREES.values())
+def test_missing_values_poisson(tree):
python:S117 - Rename this parameter "Tree" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2632

Why is this an issue?

A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.

What changed

Renames the pytest.mark.parametrize argument from 'Tree' to 'tree_class' for the test_missing_values_is_resilience function, contributing to fixing the naming convention violation where the parameter 'Tree' at line 2632 did not follow snake_case naming.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2616,1 +2616,1 @@ def make_friedman1_classification(*args, **kwargs):
-    "make_data, Tree, tolerance",
+    "make_data, tree_class, tolerance",
python:S117 - Rename this local variable "X_missing" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2643

Why is this an issue?

A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.

What changed

Renames the local variable 'X_missing' to 'x_missing', fixing the naming convention violation where 'X_missing' at line 2643 did not match the required pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2643,1 +2643,1 @@ def test_missing_values_is_resilience(
-    X_missing = X.copy()
+    x_missing = X.copy()
python:S117 - Rename this local variable "X_missing_test" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2646

Why is this an issue?

A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.

What changed

Renames usages of 'X_missing' to 'x_missing' and 'X_missing_test' to 'x_missing_test' (and X_missing_train to x_missing_train), fixing the naming convention violations where these local variables did not match the required snake_case pattern.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2645,3 +2645,3 @@ def test_missing_values_is_resilience(
-    X_missing[rng.choice([False, True], size=X.shape, p=[0.9, 0.1])] = np.nan
-    X_missing_train, X_missing_test, y_train, y_test = train_test_split(
-        X_missing, y, random_state=global_random_seed
+    x_missing[rng.choice([False, True], size=X.shape, p=[0.9, 0.1])] = np.nan
+    x_missing_train, x_missing_test, y_train, y_test = train_test_split(
+        x_missing, y, random_state=global_random_seed
python:S117 - Rename this local variable "X_equal" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2460

Why is this an issue?

A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.

What changed

Renames the local variable 'X_equal' to 'x_equal' in the test_missing_values_best_splitter_on_equal_nodes_no_missing function, fixing the naming convention violation where 'X_equal' at line 2460 did not match the required pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2460,1 +2460,1 @@ def test_missing_values_best_splitter_on_equal_nodes_no_missing(criterion):
-    X_equal = X[:-1]
+    x_equal = X[:-1]
python:S117 - Rename this parameter "Tree" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2422

Why is this an issue?

A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.

What changed

Renames the pytest.mark.parametrize argument and function parameter from 'Tree' to 'tree_cls' in the test_min_sample_split_1_error function, directly fixing the naming convention violation where 'Tree' at line 2422 did not match the required snake_case pattern.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2421,2 +2421,2 @@ def test_tree_deserialization_from_read_only_buffer(tmpdir):
-@pytest.mark.parametrize("Tree", ALL_TREES.values())
-def test_min_sample_split_1_error(Tree):
+@pytest.mark.parametrize("tree_cls", ALL_TREES.values())
+def test_min_sample_split_1_error(tree_cls):
python:S117 - Rename this parameter "Splitter" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2387

Why is this an issue?

A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.

What changed

Renames the pytest.mark.parametrize argument from 'Splitter' to 'splitter_cls', contributing to fixing the naming convention violation where the parameter 'Splitter' at line 2387 did not follow snake_case naming.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2385,1 +2385,1 @@ def test_check_node_ndarray():
-    "Splitter", chain(DENSE_SPLITTERS.values(), SPARSE_SPLITTERS.values())
+    "splitter_cls", chain(DENSE_SPLITTERS.values(), SPARSE_SPLITTERS.values())
python:S117 - Rename this parameter "Tree" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2113

Why is this an issue?

A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.

What changed

Renames the pytest.mark.parametrize argument from 'Tree' to 'tree_cls' for the test_criterion_entropy_same_as_log_loss function, contributing to fixing the naming convention violation where the parameter 'Tree' at line 2113 did not follow snake_case naming.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2111,1 +2111,1 @@ def test_poisson_vs_mse():
-@pytest.mark.parametrize("Tree", [DecisionTreeClassifier, ExtraTreeClassifier])
+@pytest.mark.parametrize("tree_cls", [DecisionTreeClassifier, ExtraTreeClassifier])
python:S1481 - Replace the unused loop index "arr" with "_". • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2346

Why is this an issue?

An unused local variable is a variable that has been declared but is not used anywhere in the block of code where it is defined. It is dead code, contributing to unnecessary complexity and leading to confusion when reading the code. Therefore, it should be removed from your code to maintain clarity and efficiency.

What changed

Replaces the unused loop variable 'arr' with an actual usage by passing it to check_node_ndarray instead of node_ndarray. This fixes the unused loop index warning by ensuring the loop variable is actually used in the loop body, eliminating the need to replace it with ''.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2347,1 +2347,1 @@ def test_check_node_ndarray():
-        _check_node_ndarray(node_ndarray, expected_dtype=expected_dtype)
+        _check_node_ndarray(arr, expected_dtype=expected_dtype)
python:S117 - Rename this parameter "Tree" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/tree/tests/test_tree.py:2023

Why is this an issue?

A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.

What changed

Renames the parameter 'Tree' to 'tree' in the test_balance_property function signature and its pytest.mark.parametrize decorator, fixing the naming convention violation where the parameter name 'Tree' (PascalCase) did not match the required snake_case pattern ^[a-z][a-z0-9]*$ at line 2023.

--- a/sklearn/tree/tests/test_tree.py
+++ b/sklearn/tree/tests/test_tree.py
@@ -2022,2 +2022,2 @@ def test_apply_path_readonly_all_trees(name, splitter, sparse_container):
-@pytest.mark.parametrize("Tree", REG_TREES.values())
-def test_balance_property(criterion, Tree):
+@pytest.mark.parametrize("tree", REG_TREES.values())
+def test_balance_property(criterion, tree):

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ45Cxj4RXnEWm2Rf5Ua for python:S117 rule
- AZ45Cxj4RXnEWm2Rf5UU for python:S117 rule
- AZ45Cxj4RXnEWm2Rf5US for python:S117 rule
- AZ45Cxj4RXnEWm2Rf5UY for python:S117 rule
- AZ45Cxj4RXnEWm2Rf5Ue for python:S117 rule
- AZ45Cxj4RXnEWm2Rf5Uh for python:S117 rule
- AZ45Cxj4RXnEWm2Rf5Ui for python:S117 rule
- AZ45Cxj4RXnEWm2Rf5Uj for python:S117 rule
- AZ45Cxj4RXnEWm2Rf5UX for python:S1481 rule
- AZ45Cxj4RXnEWm2Rf5Ug for python:S117 rule

Generated by SonarQube Agent (task: 8e4615eb-57dc-4f88-b084-ca5109dfb192)
@sonarqubecloud
Copy link
Copy Markdown

SonarQube reviewer guide

Review in SonarQube

Summary: Code style refactoring updating pytest parameter names and variable names to follow lowercase conventions for consistency and clarity.

Review Focus: While this appears to be a straightforward naming convention update, pay careful attention to the logic change at line 2347 where node_ndarray is replaced with arr in the function call—this fixes a bug where the wrong variable was being tested. All other changes are purely cosmetic parameter/variable renames (PascalCase → snake_case).

Start review at: sklearn/tree/tests/test_tree.py around line 2344 (test_check_node_ndarray function). This is critical because it contains the only functional bug fix in the PR where node_ndarray (the parameter) was incorrectly used instead of arr (the loop variable) in the assertion, meaning the test wasn't actually validating the intended array values.

💬 Please send your feedback

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues
0 New dependency risks

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant