Skip to content

fix: Apply Python naming conventions to _nmf.py parameters and variables#637

Merged
isuruperera merged 1 commit into
mainfrom
remediate-main-20260520-223643-dff34fe5
May 21, 2026
Merged

fix: Apply Python naming conventions to _nmf.py parameters and variables#637
isuruperera merged 1 commit into
mainfrom
remediate-main-20260520-223643-dff34fe5

Conversation

@sonarqube-agent

Copy link
Copy Markdown

Rename 6 function parameters and 4 local variables in sklearn/decomposition/_nmf.py to comply with Python naming conventions (lowercase with underscores). This resolves 10 SonarQube S117 issues where identifiers contained uppercase letters that violated the required pattern ^[a-z][a-z0-9]*$.

View Project in SonarCloud


Fixed Issues

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

Location: sklearn/decomposition/_nmf.py:630

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 function parameters from uppercase/mixed-case names (W, H, l1_reg_H, l2_reg_H, A, B) to lowercase equivalents (w, h, l1_reg_h, l2_reg_h, a, b) in the _multiplicative_update_h function signature. This directly fixes the naming convention violations for parameters W, H, l1_reg_H, l2_reg_H, A, and B that don't match the required pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -630,1 +630,1 @@ def _multiplicative_update_h(
-    X, W, H, beta_loss, l1_reg_H, l2_reg_H, gamma, A=None, B=None, rho=None
+    X, w, h, beta_loss, l1_reg_h, l2_reg_h, gamma, a=None, b=None, rho=None
python:S117 - Rename this parameter "H" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/decomposition/_nmf.py:630

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 function parameters from uppercase/mixed-case names (W, H, l1_reg_H, l2_reg_H, A, B) to lowercase equivalents (w, h, l1_reg_h, l2_reg_h, a, b) in the _multiplicative_update_h function signature. This directly fixes the naming convention violations for parameters W, H, l1_reg_H, l2_reg_H, A, and B that don't match the required pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -630,1 +630,1 @@ def _multiplicative_update_h(
-    X, W, H, beta_loss, l1_reg_H, l2_reg_H, gamma, A=None, B=None, rho=None
+    X, w, h, beta_loss, l1_reg_h, l2_reg_h, gamma, a=None, b=None, rho=None
python:S117 - Rename this parameter "W" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/decomposition/_nmf.py:630

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 function parameters from uppercase/mixed-case names (W, H, l1_reg_H, l2_reg_H, A, B) to lowercase equivalents (w, h, l1_reg_h, l2_reg_h, a, b) in the _multiplicative_update_h function signature. This directly fixes the naming convention violations for parameters W, H, l1_reg_H, l2_reg_H, A, and B that don't match the required pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -630,1 +630,1 @@ def _multiplicative_update_h(
-    X, W, H, beta_loss, l1_reg_H, l2_reg_H, gamma, A=None, B=None, rho=None
+    X, w, h, beta_loss, l1_reg_h, l2_reg_h, gamma, a=None, b=None, rho=None
python:S117 - Rename this parameter "l1_reg_H" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/decomposition/_nmf.py:630

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 function parameters from uppercase/mixed-case names (W, H, l1_reg_H, l2_reg_H, A, B) to lowercase equivalents (w, h, l1_reg_h, l2_reg_h, a, b) in the _multiplicative_update_h function signature. This directly fixes the naming convention violations for parameters W, H, l1_reg_H, l2_reg_H, A, and B that don't match the required pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -630,1 +630,1 @@ def _multiplicative_update_h(
-    X, W, H, beta_loss, l1_reg_H, l2_reg_H, gamma, A=None, B=None, rho=None
+    X, w, h, beta_loss, l1_reg_h, l2_reg_h, gamma, a=None, b=None, rho=None
python:S117 - Rename this parameter "A" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/decomposition/_nmf.py:630

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 function parameters from uppercase/mixed-case names (W, H, l1_reg_H, l2_reg_H, A, B) to lowercase equivalents (w, h, l1_reg_h, l2_reg_h, a, b) in the _multiplicative_update_h function signature. This directly fixes the naming convention violations for parameters W, H, l1_reg_H, l2_reg_H, A, and B that don't match the required pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -630,1 +630,1 @@ def _multiplicative_update_h(
-    X, W, H, beta_loss, l1_reg_H, l2_reg_H, gamma, A=None, B=None, rho=None
+    X, w, h, beta_loss, l1_reg_h, l2_reg_h, gamma, a=None, b=None, rho=None
python:S117 - Rename this parameter "B" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/decomposition/_nmf.py:630

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 function parameters from uppercase/mixed-case names (W, H, l1_reg_H, l2_reg_H, A, B) to lowercase equivalents (w, h, l1_reg_h, l2_reg_h, a, b) in the _multiplicative_update_h function signature. This directly fixes the naming convention violations for parameters W, H, l1_reg_H, l2_reg_H, A, and B that don't match the required pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -630,1 +630,1 @@ def _multiplicative_update_h(
-    X, W, H, beta_loss, l1_reg_H, l2_reg_H, gamma, A=None, B=None, rho=None
+    X, w, h, beta_loss, l1_reg_h, l2_reg_h, gamma, a=None, b=None, rho=None
python:S117 - Rename this local variable "WH_safe_X" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/decomposition/_nmf.py:639

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 WH_safe_X to wh_safe_x, fixing the naming convention violation where the variable name contained uppercase letters and didn't match the required pattern ^[a-z][a-z0-9]*$.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -639,1 +639,1 @@ def _multiplicative_update_h(
-        WH_safe_X = _special_sparse_dot(W, H, X)
+        wh_safe_x = _special_sparse_dot(w, h, X)
python:S117 - Rename this local variable "WH_safe_X_data" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/decomposition/_nmf.py:641

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 local variables WH_safe_X_data to wh_safe_x_data and X_data to x_data in the sparse branch, fixing naming convention violations where these variable names contained uppercase letters.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -641,2 +641,2 @@ def _multiplicative_update_h(
-            WH_safe_X_data = WH_safe_X.data
-            X_data = X.data
+            wh_safe_x_data = wh_safe_x.data
+            x_data = X.data
python:S117 - Rename this local variable "X_data" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/decomposition/_nmf.py:642

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 local variables WH_safe_X_data to wh_safe_x_data and X_data to x_data in the sparse branch, fixing naming convention violations where these variable names contained uppercase letters.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -641,2 +641,2 @@ def _multiplicative_update_h(
-            WH_safe_X_data = WH_safe_X.data
-            X_data = X.data
+            wh_safe_x_data = wh_safe_x.data
+            x_data = X.data
python:S117 - Rename this local variable "W_sum" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINORView issue

Location: sklearn/decomposition/_nmf.py:674

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 local variable W_sum to w_sum and updates usages of the renamed parameter w (formerly W), fixing the naming convention violation where W_sum contained uppercase letters and didn't match the required pattern.

--- a/sklearn/decomposition/_nmf.py
+++ b/sklearn/decomposition/_nmf.py
@@ -674,3 +674,3 @@ def _multiplicative_update_h(
-            W_sum = np.sum(W, axis=0)  # shape(n_components, )
-            W_sum[W_sum == 0] = 1.0
-            denominator = W_sum[:, np.newaxis]
+            w_sum = np.sum(w, axis=0)  # shape(n_components, )
+            w_sum[w_sum == 0] = 1.0
+            denominator = w_sum[:, np.newaxis]

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ45CvQfRXnEWm2Rf4x1 for python:S117 rule
- AZ45CvQfRXnEWm2Rf4x0 for python:S117 rule
- AZ45CvQfRXnEWm2Rf4x9 for python:S117 rule
- AZ45CvQfRXnEWm2Rf4x- for python:S117 rule
- AZ45CvQfRXnEWm2Rf4xy for python:S117 rule
- AZ45CvQfRXnEWm2Rf4xz for python:S117 rule
- AZ45CvQfRXnEWm2Rf4x2 for python:S117 rule
- AZ45CvQfRXnEWm2Rf4x3 for python:S117 rule
- AZ45CvQfRXnEWm2Rf4x7 for python:S117 rule
- AZ45CvQfRXnEWm2Rf4x5 for python:S117 rule

Generated by SonarQube Agent (task: 71eee368-5fe4-4d0d-aa94-15fb43a9079b)
@sonarqubecloud

Copy link
Copy Markdown

SonarQube reviewer guide

Review in SonarQube

Summary: Standardize variable naming conventions in _multiplicative_update_h() function by converting uppercase matrix names to lowercase and adjusting parameter names to follow PEP 8 style guidelines.

Review Focus: This is a large refactoring with widespread variable renames (W→w, H→h, A→a, B→b, etc.). Pay close attention to:

  • Ensure all call sites have been updated with the new parameter names (l1_reg_h, l2_reg_h, a, b)
  • Verify the logic remains unchanged—this should be a pure refactoring with no behavioral modifications
  • Check for any missed renames that could cause runtime errors

Start review at: sklearn/decomposition/_nmf.py lines 851 and 2100 (the call sites). These are critical because incorrect parameter names here will cause the PR to fail at runtime, whereas internal variable renames within the function are lower risk.

💬 Please send your feedback

Quality Gate Failed Quality Gate failed

Failed conditions
27.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@isuruperera isuruperera merged commit 36efccc into main May 21, 2026
10 of 11 checks passed
@isuruperera isuruperera deleted the remediate-main-20260520-223643-dff34fe5 branch May 21, 2026 05:08
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