Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TST use global_random_seed in sklearn/utils/tests/test_arrayfuncs.py - #34158

Merged
jeremiedbb merged 2 commits into
scikit-learn:mainfrom
SinhSinhAn:tst/global-random-seed-arrayfuncs
Jun 3, 2026
Merged

TST use global_random_seed in sklearn/utils/tests/test_arrayfuncs.py#34158
jeremiedbb merged 2 commits into
scikit-learn:mainfrom
SinhSinhAn:tst/global-random-seed-arrayfuncs

Conversation

@SinhSinhAn

Copy link
Copy Markdown
Contributor

Reference: #22827.

Convert test_min_pos to use the global_random_seed fixture instead of a hardcoded RandomState(0). The test asserts that min_pos agrees between float32 and float64 on a random input, so it is genuinely independent of the seed and benefits from being exercised across the full seed range.

-def test_min_pos():
+def test_min_pos(global_random_seed):
     # Check that min_pos returns a positive value and that it's consistent
     # between float and double
-    X = np.random.RandomState(0).randn(100)
+    X = np.random.RandomState(global_random_seed).randn(100)

The other two tests in the file (test_min_pos_no_positive, test_all_with_any_reduction_axis_1) use deterministic inputs and don't need a fixture.

Verification

SKLEARN_TESTS_GLOBAL_RANDOM_SEED="all" pytest sklearn/utils/tests/test_arrayfuncs.py — 100 / 100 seeds pass for test_min_pos; 117 / 117 tests pass for the whole file.

Convert `test_min_pos` to use the `global_random_seed` fixture instead
of a hardcoded `RandomState(0)`, so the assertion that `min_pos`
agrees between float32 and float64 is exercised against the full
seed range rather than a single fixed sample.

Verified with `SKLEARN_TESTS_GLOBAL_RANDOM_SEED="all"`: 100 / 100 seeds
pass.

Ref scikit-learn#22827
test_min_pos

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jeremiedbb
jeremiedbb merged commit 6a65d95 into scikit-learn:main Jun 3, 2026
40 of 41 checks passed
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks
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