Skip to content

fix: enforce snake_case naming convention in test_k_means.py#639

Open
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260601-010120-4bac939a
Open

fix: enforce snake_case naming convention in test_k_means.py#639
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260601-010120-4bac939a

Conversation

@sonarqube-agent

Copy link
Copy Markdown

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Renames 5 variables and parameters in test_k_means.py to comply with Python naming conventions (snake_case pattern). These changes fix SonarQube issues S117 and improve code consistency with scikit-learn's style guidelines.

View Project in SonarCloud


Fixed Issues

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_k_means.py:1078

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_sparse' to 'x_sparse' at its assignment. This directly fixes the naming convention violation where the local variable 'X_sparse' did not match the required snake_case pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/cluster/tests/test_k_means.py
+++ b/sklearn/cluster/tests/test_k_means.py
@@ -1078,1 +1078,1 @@ def test_inertia(dtype, global_random_seed):
-    X_sparse = _sparse_random_array(
+    x_sparse = _sparse_random_array(
python:S117 - Rename this parameter "X_csr" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_k_means.py:694

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

Updates the pytest parametrize decorator to use 'x_csr' instead of 'X_csr', which is needed to align the parameter name with the snake_case convention. This supports the fix for the parameter naming violation where 'X_csr' does not match the expected pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/cluster/tests/test_k_means.py
+++ b/sklearn/cluster/tests/test_k_means.py
@@ -689,1 +689,1 @@ def test_dense_sparse(Estimator, X_csr, global_random_seed):
-@pytest.mark.parametrize("X_csr", X_as_any_csr)
+@pytest.mark.parametrize("x_csr", X_as_any_csr)
python:S117 - Rename this parameter "Klass" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_k_means.py:1118

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 'Klass' to 'klass' in both the pytest parametrize decorator and the function signature, and updates its usage in the function body. This directly fixes the naming convention violation where the parameter 'Klass' did not match the required snake_case pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/cluster/tests/test_k_means.py
+++ b/sklearn/cluster/tests/test_k_means.py
@@ -1117,3 +1117,3 @@ def test_inertia(dtype, global_random_seed):
-@pytest.mark.parametrize("Klass, default_n_init", [(KMeans, 10), (MiniBatchKMeans, 3)])
-def test_n_init_auto(Klass, default_n_init):
-    est = Klass(n_init="auto", init="k-means++")
+@pytest.mark.parametrize("klass, default_n_init", [(KMeans, 10), (MiniBatchKMeans, 3)])
+def test_n_init_auto(klass, default_n_init):
+    est = klass(n_init="auto", init="k-means++")
python:S117 - Rename this parameter "Estimator" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_k_means.py:1129

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 'Estimator' to 'estimator' in both the pytest parametrize decorator and the function signature of test_sample_weight_unchanged. This directly fixes the naming convention violation where the parameter 'Estimator' did not match the required snake_case pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/cluster/tests/test_k_means.py
+++ b/sklearn/cluster/tests/test_k_means.py
@@ -1128,2 +1128,2 @@ def test_n_init_auto(Klass, default_n_init):
-@pytest.mark.parametrize("Estimator", [KMeans, MiniBatchKMeans])
-def test_sample_weight_unchanged(Estimator):
+@pytest.mark.parametrize("estimator", [KMeans, MiniBatchKMeans])
+def test_sample_weight_unchanged(estimator):
python:S117 - Rename this parameter "Estimator" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/cluster/tests/test_k_means.py:1165

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

Updates the pytest parametrize decorator to use 'estimator' instead of 'Estimator' for the test_wrong_params function. This supports the fix for the parameter naming violation where 'Estimator' does not match the expected snake_case pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/cluster/tests/test_k_means.py
+++ b/sklearn/cluster/tests/test_k_means.py
@@ -1138,1 +1138,1 @@ def test_sample_weight_unchanged(Estimator):
-@pytest.mark.parametrize("Estimator", [KMeans, MiniBatchKMeans])
+@pytest.mark.parametrize("estimator", [KMeans, MiniBatchKMeans])

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ45CwkaRXnEWm2Rf5H_ for python:S117 rule
- AZ45CwkaRXnEWm2Rf5IX for python:S117 rule
- AZ45CwkaRXnEWm2Rf5IT for python:S117 rule
- AZ45CwkaRXnEWm2Rf5IW for python:S117 rule
- AZ45CwkaRXnEWm2Rf5IV for python:S117 rule

Generated by SonarQube Agent (task: da91e9d3-0ecc-4681-83de-0f911404ae24)
@sonarqubecloud

sonarqubecloud Bot commented Jun 1, 2026

Copy link
Copy Markdown

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