Skip to content

TST use global_random_seed in sklearn/utils/tests/test_stats.py #30857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 10, 2025

Conversation

Rishab260
Copy link
Contributor

Reference Issues/PRs

towards #22827

What does this implement/fix? Explain your changes.

I added the global_random_seed fixture to the following tests:-

  • test_weighted_percentile_2d
  • test_weighted_median_equal_weights
  • test_averaged_weighted_percentile
  • test_weighted_median_integer_weights

Any other comments?

Feedback and guidance is highly appreciated. Looking forward to contributing to this project more and more in the coming days. Thanks in advance!

Copy link

github-actions bot commented Feb 19, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: e9274f3. Link to the linter CI: here

Copy link
Contributor

@OmarManzoor OmarManzoor left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @Rishab260

Please also add a commit with all global seeds for the respective tests on this PR too.

Rishab260 and others added 4 commits March 2, 2025 14:45
test_averaged_weighted_percentile
test_weighted_median_equal_weights
test_weighted_median_integer_weights
test_weighted_percentile_2d
test_averaged_weighted_percentile
test_weighted_median_equal_weights
test_weighted_median_integer_weights
test_weighted_percentile_2d
@Rishab260
Copy link
Contributor Author

Currently blocked by

FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[9] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[15] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[21] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[23] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[32] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[40] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[56] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[61] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[62] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[77] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[81] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[83] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[90] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[91] - AssertionError
FAILED sklearn/utils/tests/test_stats.py::test_weighted_median_integer_weights[95] - AssertionError

Will fix this ASAP.

test_averaged_weighted_percentile
test_weighted_median_equal_weights
test_weighted_median_integer_weights
test_weighted_percentile_2d
@Rishab260 Rishab260 requested a review from OmarManzoor March 3, 2025 15:45
Copy link
Contributor

@OmarManzoor OmarManzoor left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @Rishab260

Comment on lines 105 to 106
x = rng.randint(20, size=1000)
weights = rng.choice(5, size=1000)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would size=100 work or does that still fail? I think 1000 is fine anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, Size 100 failed, we can probably relax the tolerance but since size 1000 worked, I went with that one.

Copy link
Member

Choose a reason for hiding this comment

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

The test was not correct. It is not equivalent to np.median when the number of effective samples is even. _averaged_weighted_percentile should be equivalent instead. I modified the test accordingly.

test_averaged_weighted_percentile
test_weighted_median_equal_weights
test_weighted_median_integer_weights
test_weighted_percentile_2d
test_weighted_percentile_array_api_consistency
test_weighted_percentile_nan_filtered
test_weighted_percentile_like_numpy_quantile
test_weighted_percentile_like_numpy_nanquantile
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @Rishab260

@jeremiedbb jeremiedbb enabled auto-merge (squash) April 10, 2025 09:55
@jeremiedbb jeremiedbb merged commit 16effb9 into scikit-learn:main Apr 10, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants