Skip to content

Conversation

j-bowhay
Copy link
Member

@j-bowhay j-bowhay commented Nov 6, 2024

Transitions interpolate.barycentric_interpolator according to SPEC007.

@github-actions github-actions bot added scipy.optimize scipy.interpolate maintenance Items related to regular maintenance tasks labels Nov 6, 2024
@j-bowhay j-bowhay requested a review from mdhaber November 6, 2024 02:27
@j-bowhay
Copy link
Member Author

j-bowhay commented Nov 7, 2024

CI failure looks unrelated

@lucascolley lucascolley changed the title MAINT: interpolate.BarycentricInterpolator: transition to Generator (SPEC 7) API: interpolate.BarycentricInterpolator: transition to Generator (SPEC 7) Nov 7, 2024
@lucascolley lucascolley added this to the 1.15.0 milestone Nov 7, 2024
@lucascolley
Copy link
Member

Could you post on the forum? Either for this change or for adopting SPEC7 project-wide

Copy link
Member

@ev-br ev-br left a comment

Choose a reason for hiding this comment

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

LGTM modulo two nits and a general question:

So the random_state= kwarg is going to be removed at some point, across the whole scipy codebase I presume. Is there a timeline already? Would be nice to have it spelled out explicitly somewhere. Backwards compat break procedures and all that. This is of course not blocking for this PR.

P.S. I was today's year old to first see an __init__ with a decorator :-). If it works, it does I suppose.

@mdhaber
Copy link
Contributor

mdhaber commented Nov 7, 2024

Would be nice to have it spelled out explicitly somewhere. Backwards compat break procedures and all that.

It is spelled out by the SPEC except the duration of SciPy's deprecation cycle being two releases long. For us, that means:

  • for two releases, no warnings
  • then we turn on warnings in the decorator and wait two more releases
  • then we remove the decorators and all old random_state/seed validation. Whatever the user passed for rng gets passed into rng = np.random.default_rng(rng) for validation/standardization.

@mdhaber
Copy link
Contributor

mdhaber commented Nov 8, 2024

Interesting. Applying the decorator to the class looks like it almost worked, but the decorator appears not to preserve a __code__ attribute. (IIUC functools.__wraps__ doesn't get everything right.) If we find a solution for this, it would be good to update SPEC 7 accordingly.

The other failures are gh-21831 and gh-21828.

@mdhaber
Copy link
Contributor

mdhaber commented Nov 9, 2024

gh-21833 shows a few other classes with initializers that accept seed or random_state, but they have other issues that will require more work than simply applying the decorator.

  • BootstrapMethod and PermutationMethod expose an attribute random_state, so applying the decorator is not enough.
  • The QMC classes accept seed but they have their own check_random_state function that behaves differently from everything else; it passes RandomStates through, but it uses default_rng on everything else. Rather than further generalize the decorator, I think we'll just copy-paste.

With that in mind, it might not be worth the time to generalize the decorator to replace the documentation here. If you edit the documentation manually, would putting the decorator back on the __init__ method fix the remaining error, do you think?

@j-bowhay
Copy link
Member Author

gh-21833 shows a few other classes with initializers that accept seed or random_state, but they have other issues that will require more work than simply applying the decorator.

  • BootstrapMethod and PermutationMethod expose an attribute random_state, so applying the decorator is not enough.
  • The QMC classes accept seed but they have their own check_random_state function that behaves differently from everything else; it passes RandomStates through, but it uses default_rng on everything else. Rather than further generalize the decorator, I think we'll just copy-paste.

With that in mind, it might not be worth the time to generalize the decorator to replace the documentation here. If you edit the documentation manually, would putting the decorator back on the __init__ method fix the remaining error, do you think?

Sounds reasonable, done

@mdhaber
Copy link
Contributor

mdhaber commented Nov 11, 2024

Failures are unrelated; saw those in gh-21867.

[skip ci]

Co-authored-by: Jake Bowhay <60778417+j-bowhay@users.noreply.github.com>
Copy link
Contributor

@mdhaber mdhaber left a comment

Choose a reason for hiding this comment

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

@j-bowhay This looks pretty good, but there are no uses of rng in the tests - were the tests not seeded before? I guess that hasn't bitten us with random failures, but do you agree it would be good to include it (at least to make sure it's working)?

@j-bowhay
Copy link
Member Author

@j-bowhay This looks pretty good, but there are no uses of rng in the tests - were the tests not seeded before? I guess that hasn't bitten us with random failures, but do you agree it would be good to include it (at least to make sure it's working)?

The permutation is to prevent underflow/overflow during the computation, the seeding shouldn't impact the results as basically any permutation will do but I will add it to a test as I agree it would be good to have for coverage

@mdhaber mdhaber merged commit ea53bf7 into scipy:main Nov 12, 2024
34 of 37 checks passed
@mdhaber mdhaber added needs-release-note a maintainer should add a release note written by a reviewer/author to the wiki and removed needs-release-note a maintainer should add a release note written by a reviewer/author to the wiki labels Nov 12, 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.interpolate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants