Skip to content

fix: resolve 10 SonarQube code quality issues in test_dbscan.py#628

Merged
isuruperera merged 1 commit into
mainfrom
remediate-main-20260520-222321-cb1f73ae
May 20, 2026
Merged

fix: resolve 10 SonarQube code quality issues in test_dbscan.py#628
isuruperera merged 1 commit into
mainfrom
remediate-main-20260520-222321-cb1f73ae

Conversation

@sonarqube-agent

Copy link
Copy Markdown

Fixed naming convention violations and unused variable warnings in sklearn/cluster/tests/test_dbscan.py by renaming variables to follow snake_case conventions and replacing unused variables with underscores. These changes align the code with PEP 8 style guidelines and reduce code quality violations.

View Project in SonarCloud


Fixed Issues

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

Location: sklearn/cluster/tests/test_dbscan.py:139

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_copy' to 'x_copy' in test_dbscan_input_not_modified_precomputed_sparse_nodiag (line 139), making it conform to the snake_case naming convention.

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -139,1 +139,1 @@ def test_dbscan_input_not_modified_precomputed_sparse_nodiag(csr_container):
-    X_copy = X.copy()
+    x_copy = X.copy()
python:S117 - Rename this local variable "X_" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_dbscan.py:153

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 loop variable 'X_' to 'x_' in test_dbscan_no_core_samples (line 153), making it conform to the snake_case naming convention (^[a-z][a-z0-9]*$). All usages of the variable within the loop body are also updated.

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -153,3 +153,3 @@ def test_dbscan_no_core_samples(csr_container):
-    for X_ in [X, csr_container(X)]:
-        db = DBSCAN(min_samples=6).fit(X_)
-        assert_array_equal(db.components_, np.empty((0, X_.shape[1])))
+    for x_ in [X, csr_container(X)]:
+        db = DBSCAN(min_samples=6).fit(x_)
+        assert_array_equal(db.components_, np.empty((0, x_.shape[1])))
python:S1481 - Replace the unused local variable "core_samples" with "_". • MINORView issue

Location: sklearn/cluster/tests/test_dbscan.py:32

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 local variable 'core_samples' with '' in the tuple unpacking of the dbscan() return value in test_dbscan_similarity. This fixes the unused local variable warning at line 32, since '' is an accepted convention for intentionally ignored values.

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -32,1 +32,1 @@ def test_dbscan_similarity():
-    core_samples, labels = dbscan(
+    _, labels = dbscan(
python:S1481 - Replace the unused local variable "core_samples" with "_". • MINORView issue

Location: sklearn/cluster/tests/test_dbscan.py:56

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 local variable 'core_samples' with '' in the tuple unpacking of the dbscan() return value in test_dbscan_feature. This fixes the unused local variable warning at line 56, since '' is the conventional name for intentionally discarded values.

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -56,1 +56,1 @@ def test_dbscan_feature():
-    core_samples, labels = dbscan(X, metric=metric, eps=eps, min_samples=min_samples)
+    _, labels = dbscan(X, metric=metric, eps=eps, min_samples=min_samples)
python:S117 - Rename this local variable "D_sparse" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_dbscan.py:82

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 'D_sparse' to 'd_sparse' in test_dbscan_sparse_precomputed, making it conform to the snake_case naming convention (^[a-z][a-z0-9]*$). This fixes the naming convention violation at line 82.

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -82,1 +82,1 @@ def test_dbscan_sparse_precomputed(include_self):
-    D_sparse = nn.radius_neighbors_graph(X=X_, mode="distance")
+    d_sparse = nn.radius_neighbors_graph(X=X_, mode="distance")
python:S117 - Rename this local variable "D_sparse" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_dbscan.py:98

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 'D_sparse' to 'd_sparse' in test_dbscan_sparse_precomputed_different_eps (first occurrence at line 98), making it conform to the snake_case naming convention. Also updates its usage in the subsequent dbscan() call.

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -98,2 +98,2 @@ def test_dbscan_sparse_precomputed_different_eps():
-    D_sparse = nn.radius_neighbors_graph(X, mode="distance")
-    dbscan_lower = dbscan(D_sparse, eps=lower_eps, metric="precomputed")
+    d_sparse = nn.radius_neighbors_graph(X, mode="distance")
+    dbscan_lower = dbscan(d_sparse, eps=lower_eps, metric="precomputed")
python:S1481 - Replace the unused local variable "core_samples" with "_". • MINORView issue

Location: sklearn/cluster/tests/test_dbscan.py:170

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 local variable 'core_samples' with '_' in the tuple unpacking of the dbscan() return value in test_dbscan_callable. This fixes the unused local variable warning at line 170.

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -170,1 +170,1 @@ def test_dbscan_callable():
-    core_samples, labels = dbscan(
+    _, labels = dbscan(
python:S1481 - Replace the unused local variable "core_samples" with "_". • MINORView issue

Location: sklearn/cluster/tests/test_dbscan.py:252

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 local variable 'core_samples' with '_' in the tuple unpacking of the dbscan() return value in test_dbscan_balltree. This fixes the unused local variable warning at line 252.

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -252,1 +252,1 @@ def test_dbscan_balltree():
-    core_samples, labels = dbscan(
+    _, labels = dbscan(
python:S117 - Rename this local variable "X_copy" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_dbscan.py:116

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_copy' to 'x_copy' in test_dbscan_input_not_modified (line 116), making it conform to the snake_case naming convention (^[a-z][a-z0-9]*$).

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -116,1 +116,1 @@ def test_dbscan_input_not_modified(metric, csr_container):
-    X_copy = X.copy()
+    x_copy = X.copy()
python:S117 - Rename this local variable "X_repeated" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_dbscan.py:347

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_repeated' to 'x_repeated' in test_weighted_dbscan (line 347), making it conform to the snake_case naming convention (^[a-z][a-z0-9]*$). All usages of the variable are also updated.

--- a/sklearn/cluster/tests/test_dbscan.py
+++ b/sklearn/cluster/tests/test_dbscan.py
@@ -347,3 +347,3 @@ def test_weighted_dbscan(global_random_seed):
-    X_repeated = np.repeat(X, sample_weight, axis=0)
-    core_repeated, label_repeated = dbscan(X_repeated)
-    core_repeated_mask = np.zeros(X_repeated.shape[0], dtype=bool)
+    x_repeated = np.repeat(X, sample_weight, axis=0)
+    core_repeated, label_repeated = dbscan(x_repeated)
+    core_repeated_mask = np.zeros(x_repeated.shape[0], dtype=bool)

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ45Cwh-RXnEWm2Rf5HD for python:S1481 rule
- AZ45Cwh-RXnEWm2Rf5HL for python:S117 rule
- AZ45Cwh-RXnEWm2Rf5HE for python:S1481 rule
- AZ45Cwh-RXnEWm2Rf5HJ for python:S117 rule
- AZ45Cwh-RXnEWm2Rf5HG for python:S117 rule
- AZ45Cwh-RXnEWm2Rf5HN for python:S1481 rule
- AZ45Cwh-RXnEWm2Rf5HP for python:S117 rule
- AZ45Cwh-RXnEWm2Rf5HH for python:S117 rule
- AZ45Cwh-RXnEWm2Rf5HO for python:S1481 rule
- AZ45Cwh-RXnEWm2Rf5HF for python:S117 rule

Generated by SonarQube Agent (task: 6eea4337-78f3-4081-92a1-692033b8784a)
@sonarqubecloud

Copy link
Copy Markdown

@isuruperera isuruperera merged commit 347166d into main May 20, 2026
11 checks passed
@isuruperera isuruperera deleted the remediate-main-20260520-222321-cb1f73ae branch May 20, 2026 22:28
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.

2 participants