[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: Thanks for the PR and for filing the issue. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset b0dfc7581697f20385813582de7e92ba6ba0105f by Ram Rachum in branch 'master': bpo-41773: Raise exception for non-finite weights in random.choices(). (GH-22441) https://github.com/python/cpython/commit/b0dfc7581697f20385813582de7e92ba6ba0105f

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-28 Thread Ram Rachum
Change by Ram Rachum : -- keywords: +patch pull_requests: +21470 stage: resolved -> patch review pull_request: https://github.com/python/cpython/pull/22441 ___ Python tracker _

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-28 Thread Ram Rachum
Ram Rachum added the comment: Sounds good, I'm on it. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: htt

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: I've discussed this with other developers and now agree that a test should be added. While the current code's handing of Inf or NaN is correct in a technical sense, it is neither intuitive or useful. Even though it will have a small time cost for the com

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-13 Thread Ram Rachum
Ram Rachum added the comment: Thanks for your time, and I accept your decision here. I'd appreciate it though if you wouldn't use the term "made up issue" on something that happened to me a couple of days ago. Our opposing positions each have their pros and cons, and it makes sense to me tha

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-13 Thread Raymond Hettinger
Raymond Hettinger added the comment: > A user reading that error message could understand that it's > okay for weights to be negative as long as the total isn't, > which as far as I understand isn't true. This seems like another made up issue. One could also argue the opposite case that i

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-13 Thread Ram Rachum
Ram Rachum added the comment: Yes, but the docs say that the weights are assumed to be nonnegative. I'm assuming the check is done on total because it'd be expensive to do it on each item. A user reading that error message could understand that it's okay for weights to be negative as long as

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-13 Thread Raymond Hettinger
Raymond Hettinger added the comment: > 'All weights must be positive or zero' would be more accurate. That's not what the test checks. It literally checks for "total <= 0.0". -- ___ Python tracker

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-13 Thread Ram Rachum
Ram Rachum added the comment: Speaking of that check, the error message is 'Total of weights must be greater than zero', which is a bit misleading. 'All weights must be positive or zero' would be more accurate. Would you like a PR for that? -- ___

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-12 Thread Ram Rachum
Ram Rachum added the comment: I disagree, especially the bit about slowing down the function, since you're checking the total, not every element. Like the check for negative numbers that you do on line 493. But it's your call. -- ___ Python tracke

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: In general NaNs wreak havoc on any function that uses comparisons: >>> max(10, nan) 10 >>> max(nan, 10) nan It isn't the responsibility of the functions to test for NaNs. Likewise, it would not make sense to document the NaN behavior in e

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: Sorry, I don't see the point in cluttering the documentation or over-specifying the function for these non-sensensical toy experiments. AFAICT, no actual problem exists in practice. Also, we don't want to slow down the function by running scans for inf

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-12 Thread Ram Rachum
New submission from Ram Rachum : I was recently tripped up by a bug caused by passing infinite weights to random.choices. I toyed around with that function, and it seemed that when it's given weights that include infinity or NaN, it selects a specific element, always without being random. Tha

[issue41773] Clarify handling of infinity and nan in random.choices

2020-09-12 Thread Ram Rachum
Change by Ram Rachum : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pyth