FIX Param validation Interval error for large integers#26648
FIX Param validation Interval error for large integers#26648jeremiedbb merged 7 commits intoscikit-learn:mainfrom
Conversation
thomasjpfan
left a comment
There was a problem hiding this comment.
Thank you for the PR @naoise-h !
jeremiedbb
left a comment
There was a problem hiding this comment.
Thanks for the PR @naoise-h. This is the appropriate fix imo.
|
out of curiosity, what is the parameter that you want to set to such a big int ? |
Linting PassedAll linting checks passed. Your pull request is in excellent shape! ☀️ |
I was trying to seed a |
There was a problem hiding this comment.
LGTM as well. @jeremiedbb why is this marked "no changelog needed"? Wasn't this bug already there in 1.2?
jeremiedbb
left a comment
There was a problem hiding this comment.
Let's not wait for the refactoring of utils to merge this one. Thanks @naoise-h.
…26648) Co-authored-by: jeremie du boisberranger <jeremiedbb@yahoo.fr>
…26648) Co-authored-by: jeremie du boisberranger <jeremiedbb@yahoo.fr>
At present, param validation on
Intervalreturns a TypeError when provided with a large integer (greater than 64 bits). This is because of thenp.isnancall, which attempts to convert to a Numpy integer, of which no type exists greater than 64 bits. This issue came to light when trying to usenumpy.SeedSequence().entropy(a 128-bit integer) as arandom_stateseed.What does this implement/fix? Explain your changes.
A TypeError is raised unexpectedly:
Instead of calling
np.isnan()on the value alone, it now first checks if the value is an integer (since integers cannot benan). Tests have been added to check it works with large integers (including integers larger than those representible by a float, approx2**1024and larger).After these changes, we have the following output, as expected:
Any other comments?
math.isnaninstead, which raises anOverflowErrorwhen conversion to float fails._NanConstraintwill also throw anOverflowErrorif provided with a large integer (> 2**1024), but its only use is withinMissingValueswhich already has an Integral class check