Skip to content

fix: resolve 10 SonarQube issues in test_hdbscan.py#629

Merged
isuruperera merged 1 commit into
mainfrom
remediate-main-20260520-222345-ddaede02
May 20, 2026
Merged

fix: resolve 10 SonarQube issues in test_hdbscan.py#629
isuruperera merged 1 commit into
mainfrom
remediate-main-20260520-222345-ddaede02

Conversation

@sonarqube-agent

Copy link
Copy Markdown

This PR fixes 10 SonarQube code quality issues in the HDBSCAN test file. The changes include renaming 8 local variables to comply with Python's snake_case naming convention (e.g., X_dist → x_dist, D_original → d_original) and removing 2 unnecessary list() calls that added performance overhead. These fixes improve code consistency and maintainability without altering any test functionality.

View Project in SonarCloud


Fixed Issues

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

Location: sklearn/cluster/tests/test_hdbscan.py:565

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_dist to x_dist at line 565 in test_hdbscan_error_precomputed_and_store_centers, making it conform to the snake_case naming convention. This directly fixes the naming convention violation for X_dist.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -565,1 +565,1 @@ def test_hdbscan_error_precomputed_and_store_centers(store_centers):
-    X_dist = euclidean_distances(X)
+    x_dist = euclidean_distances(X)
python:S117 - Rename this local variable "_X_sparse" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_hdbscan.py:278

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 _X_sparse to _x_sparse and X_sparse to x_sparse at lines 278-280 in test_hdbscan_sparse, making both conform to the snake_case naming convention. This directly fixes the naming convention violations for both _X_sparse and X_sparse.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -278,3 +278,3 @@ def test_hdbscan_sparse(csr_container):
-    _X_sparse = csr_container(X)
-    X_sparse = _X_sparse.copy()
-    sparse_labels = HDBSCAN(copy=False).fit(X_sparse).labels_
+    _x_sparse = csr_container(X)
+    x_sparse = _x_sparse.copy()
+    sparse_labels = HDBSCAN(copy=False).fit(x_sparse).labels_
python:S117 - Rename this local variable "X_sparse" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_hdbscan.py:279

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 _X_sparse to _x_sparse and X_sparse to x_sparse at lines 278-280 in test_hdbscan_sparse, making both conform to the snake_case naming convention. This directly fixes the naming convention violations for both _X_sparse and X_sparse.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -278,3 +278,3 @@ def test_hdbscan_sparse(csr_container):
-    _X_sparse = csr_container(X)
-    X_sparse = _X_sparse.copy()
-    sparse_labels = HDBSCAN(copy=False).fit(X_sparse).labels_
+    _x_sparse = csr_container(X)
+    x_sparse = _x_sparse.copy()
+    sparse_labels = HDBSCAN(copy=False).fit(x_sparse).labels_
python:S117 - Rename this local variable "X_dense" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_hdbscan.py:286

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_dense to x_dense at line 286 in test_hdbscan_sparse, making it conform to the snake_case naming convention. This directly fixes the naming convention violation for X_dense.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -286,3 +286,3 @@ def test_hdbscan_sparse(csr_container):
-        X_dense = X.copy()
-        X_dense[0, 0] = outlier_val
-        dense_labels = HDBSCAN(copy=False).fit(X_dense).labels_
+        x_dense = X.copy()
+        x_dense[0, 0] = outlier_val
+        dense_labels = HDBSCAN(copy=False).fit(x_dense).labels_
python:S117 - Rename this local variable "X_outlier" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_hdbscan.py:63

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_outlier to x_outlier at line 63 in test_outlier_data, making it conform to the snake_case naming convention (regex ^[_a-z][a-z0-9_]*$). This directly fixes the naming convention violation for X_outlier in that function.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -63,4 +63,4 @@ def test_outlier_data(outlier_type):
-    X_outlier = X.copy()
-    X_outlier[0] = [outlier, 1]
-    X_outlier[5] = [outlier, outlier]
-    model = HDBSCAN(copy=False).fit(X_outlier)
+    x_outlier = X.copy()
+    x_outlier[0] = [outlier, 1]
+    x_outlier[5] = [outlier, outlier]
+    model = HDBSCAN(copy=False).fit(x_outlier)
python:S117 - Rename this local variable "D_original" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_hdbscan.py:85

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_original to d_original at line 85 in test_hdbscan_distance_matrix, making it conform to the snake_case naming convention. This directly fixes the naming convention violation for D_original.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -85,1 +85,1 @@ def test_hdbscan_distance_matrix():
-    D_original = D.copy()
+    d_original = D.copy()
python:S117 - Rename this local variable "X_outlier" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_hdbscan.py:196

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_outlier to x_outlier at line 196 in test_dbscan_clustering_outlier_data, making it conform to the snake_case naming convention. This directly fixes the naming convention violation for X_outlier in that function.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -196,5 +196,5 @@ def test_dbscan_clustering_outlier_data(cut_distance):
-    X_outlier = X.copy()
-    X_outlier[0] = [np.inf, 1]
-    X_outlier[2] = [1, np.nan]
-    X_outlier[5] = [np.inf, np.nan]
-    model = HDBSCAN(copy=False).fit(X_outlier)
+    x_outlier = X.copy()
+    x_outlier[0] = [np.inf, 1]
+    x_outlier[2] = [1, np.nan]
+    x_outlier[5] = [np.inf, np.nan]
+    model = HDBSCAN(copy=False).fit(x_outlier)
python:S117 - Rename this local variable "X_nan" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_hdbscan.py:468

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_nan to x_nan at line 468 in test_hdbscan_precomputed_dense_nan, making it conform to the snake_case naming convention. This directly fixes the naming convention violation for X_nan.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -468,2 +468,2 @@ def test_hdbscan_precomputed_dense_nan():
-    X_nan = X.copy()
-    X_nan[0, 0] = np.nan
+    x_nan = X.copy()
+    x_nan[0, 0] = np.nan
python:S7504 - Remove this unnecessary `list()` call on an already iterable object. • MINORView issue

Location: sklearn/cluster/tests/test_hdbscan.py:508

Why is this an issue?

When iterating over an already iterable object with a for loop or a comprehension, wrapping it with list() adds meaningless clutter that doesn’t provide any functional value. Additionally, it creates unnecessary overhead by generating an intermediate list in memory, which inefficiently consumes memory and can degrade performance, especially with large data structures. Iterating directly over the original object is cleaner and more efficient.

What changed

Removes the unnecessary list() wrapper around set(y) in two dict comprehensions at lines 508-509. Since set is already iterable, wrapping it with list() creates unnecessary overhead. This directly fixes both instances of the unnecessary list() call on an already iterable object.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -508,2 +508,2 @@ def test_labelling_distinct(global_random_seed, allow_single_cluster, epsilon):
-    first_with_label = {_y: np.where(y == _y)[0][0] for _y in list(set(y))}
-    y_to_labels = {_y: labels[first_with_label[_y]] for _y in list(set(y))}
+    first_with_label = {_y: np.where(y == _y)[0][0] for _y in set(y)}
+    y_to_labels = {_y: labels[first_with_label[_y]] for _y in set(y)}
python:S7504 - Remove this unnecessary `list()` call on an already iterable object. • MINORView issue

Location: sklearn/cluster/tests/test_hdbscan.py:509

Why is this an issue?

When iterating over an already iterable object with a for loop or a comprehension, wrapping it with list() adds meaningless clutter that doesn’t provide any functional value. Additionally, it creates unnecessary overhead by generating an intermediate list in memory, which inefficiently consumes memory and can degrade performance, especially with large data structures. Iterating directly over the original object is cleaner and more efficient.

What changed

Removes the unnecessary list() wrapper around set(y) in two dict comprehensions at lines 508-509. Since set is already iterable, wrapping it with list() creates unnecessary overhead. This directly fixes both instances of the unnecessary list() call on an already iterable object.

--- a/sklearn/cluster/tests/test_hdbscan.py
+++ b/sklearn/cluster/tests/test_hdbscan.py
@@ -508,2 +508,2 @@ def test_labelling_distinct(global_random_seed, allow_single_cluster, epsilon):
-    first_with_label = {_y: np.where(y == _y)[0][0] for _y in list(set(y))}
-    y_to_labels = {_y: labels[first_with_label[_y]] for _y in list(set(y))}
+    first_with_label = {_y: np.where(y == _y)[0][0] for _y in set(y)}
+    y_to_labels = {_y: labels[first_with_label[_y]] for _y in set(y)}

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ45Cwo-RXnEWm2Rf5Ih for python:S117 rule
- AZ45Cwo-RXnEWm2Rf5Ig for python:S117 rule
- AZ45Cwo9RXnEWm2Rf5If for python:S117 rule
- AZ45Cwo-RXnEWm2Rf5Ik for python:S117 rule
- AZ45Cwo-RXnEWm2Rf5Ij for python:S117 rule
- AZ45Cwo-RXnEWm2Rf5Ii for python:S117 rule
- AZ45Cwo-RXnEWm2Rf5Ip for python:S7504 rule
- AZ45Cwo-RXnEWm2Rf5Iq for python:S7504 rule
- AZ45Cwo-RXnEWm2Rf5In for python:S117 rule
- AZ45Cwo-RXnEWm2Rf5Ir for python:S117 rule

Generated by SonarQube Agent (task: 1ec47e9e-ef26-482a-9ca2-b8b8b4aa13e8)
@sonarqubecloud

Copy link
Copy Markdown

SonarQube reviewer guide

Review in SonarQube

Summary: Standardize variable naming conventions in HDBSCAN tests by converting PascalCase variable names to snake_case for consistency with Python style guidelines.

Review Focus: This is a pure refactoring change with no functional modifications. Verify that all variable renames are consistent across each test function and that no references were missed. Pay attention to the dictionary comprehensions at lines 508-509 where list(set(y)) was simplified to set(y) — ensure this semantic change is intentional and doesn't affect test behavior.

Start review at: sklearn/cluster/tests/test_hdbscan.py. This is the only file modified, containing multiple test functions with systematic variable name updates. Focus on confirming rename consistency and the intentional simplification of the set operations.

💬 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

@isuruperera isuruperera merged commit 43cec1d into main May 20, 2026
11 checks passed
@isuruperera isuruperera deleted the remediate-main-20260520-222345-ddaede02 branch May 20, 2026 22:29
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