fix: replace deprecated numpy.random.RandomState with Generator API#635
Merged
Merged
Conversation
Fixed issues: - AZ45CwrgRXnEWm2Rf5JB for python:S6711 rule - AZ45CwrgRXnEWm2Rf5I_ for python:S6711 rule - AZ45CwrgRXnEWm2Rf5JH for python:S6711 rule - AZ45CwrgRXnEWm2Rf5I8 for python:S6711 rule - AZ45CwrgRXnEWm2Rf5I4 for python:S6711 rule - AZ45CwrgRXnEWm2Rf5JE for python:S6711 rule - AZ45CwrgRXnEWm2Rf5I6 for python:S6711 rule - AZ45CwrgRXnEWm2Rf5JC for python:S6711 rule - AZ45CwrgRXnEWm2Rf5I3 for python:S6711 rule - AZ45CwrgRXnEWm2Rf5I1 for python:S6711 rule Generated by SonarQube Agent (task: f53c07ae-503d-4c5d-90c2-ba487ef07b33)
SonarQube reviewer guide
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




This PR resolves 10 SonarQube S6711 issues in the hierarchical clustering tests by replacing all legacy numpy.random.RandomState calls with the modern numpy.random.default_rng API. This modernization improves code quality and aligns with current NumPy best practices for random number generation.
View Project in SonarCloud
Fixed Issues
python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:185Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(global_random_seed)call at line 185 with the modernnp.random.default_rng(global_random_seed), switching from the deprecated RandomState to the recommended Generator API. This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 185.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:277Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(global_random_seed)call at line 277 with the modernnp.random.default_rng(global_random_seed). This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 277.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:328Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(global_random_seed)call at line 328 with the modernnp.random.default_rng(global_random_seed). This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 328.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:367Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(global_random_seed)call at line 367 with the modernnp.random.default_rng(global_random_seed). This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 367.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:466Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(global_random_seed)call at line 466 with the modernnp.random.default_rng(global_random_seed). This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 466.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:270Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(0)call at line 270 withnp.random.default_rng(0), and updates the associatedrng.randn(50, 100)call torng.standard_normal((50, 100)). This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 270.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:396Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(seed=1)call at line 396 with the modernnp.random.default_rng(seed=1). This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 396.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:157Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(0)call at line 157 with the modernnp.random.default_rng(0), switching from the deprecated RandomState to the recommended Generator API. This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 157.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:104Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(0)call at line 104 with the modernnp.random.default_rng(0), and updates the associatedrng.randn(50, 100)call torng.standard_normal((50, 100))to use the new Generator API. This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 104.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
sklearn/cluster/tests/test_hierarchical.py:128Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(0)call at line 128 with the modernnp.random.default_rng(0), switching from the deprecated RandomState to the recommended Generator API. This directly fixes the static analysis warning about using legacy numpy.random.RandomState at line 128.SonarQube Remediation Agent uses AI. Check for mistakes.