Skip to content

Conversation

j-bowhay
Copy link
Member

Towards #21833

@j-bowhay
Copy link
Member Author

test_kmeans2_kpp_low_dim and test_kmeans2_kpp_high_dim still set the global state as I couldn't work out how to get the test to pass using default_rng

@lucascolley lucascolley added the maintenance Items related to regular maintenance tasks label Nov 13, 2024
@andyfaff
Copy link
Contributor

test_kmeans2_kpp_low_dim and test_kmeans2_kpp_high_dim I couldn't work out how to get the test to pass using default_rng

Yes, this kind of thing is annoying!

Possible ameliorations:

  • instead of setting global state use seed=np.random.RandomState(42) and pass that instance to kmeans2. This postpones the effort until the deprecation period is over.
  • fiddle with default_rng seed until tests pass.
  • delve into the original reported issue that caused the test to be added and code to be changed, understand the problem, see if the fix is correct, see if the test uses random number generation appropriately, etc.

I think this process is revealing several locations of where the original fixes/tests (probably latter) weren't thought through correctly - they simply shouldn't rely on seeds being certain values.

@j-bowhay j-bowhay mentioned this pull request Nov 13, 2024
50 tasks
@mdhaber
Copy link
Contributor

mdhaber commented Nov 13, 2024

fiddle with default_rng seed until tests pass.

Done.

  • Applies the _transition_to_rng decorator
    • Passes correct old_name to decorator factory (was seed here)
    • Passes correct position_num to decorator factory (keyword only)
  • replaces old keyword in signature with rng
  • replaces documentation of old keyword with final documentation recommended by SPEC 7
  • replaces most uses of old keyword in tests / other functions with rng / Generator
  • notes remaining uses of old keyword (left to test backward compatibility during transition)
  • check that decorator has replaced documentation correctly

e.g. from kmeans2:
image

@mdhaber mdhaber merged commit c3da43f into scipy:main Nov 13, 2024
31 of 37 checks passed
@mdhaber mdhaber added the needs-release-note a maintainer should add a release note written by a reviewer/author to the wiki label Nov 13, 2024
@j-bowhay j-bowhay added this to the 1.15.0 milestone Nov 13, 2024
@mdhaber mdhaber removed the needs-release-note a maintainer should add a release note written by a reviewer/author to the wiki label Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.cluster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants