[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-25 Thread Iza Romanowska
Iza Romanowska added the comment: Many thanks for patching it! Much appreciated. -- ___ Python tracker ___ ___ Python-bugs-list ma

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: Thanks for the suggestions. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: -Python 3.7, Python 3.8 ___ Python tracker

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 041d8b48a2e59fa642b2c5124d78086baf74e339 by Raymond Hettinger in branch 'master': bpo-38881: choices() raises ValueError when all weights are zero (GH-17362) https://github.com/python/cpython/commit/041d8b48a2e59fa642b2c5124d78086baf74e339

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-23 Thread Mark Dickinson
Mark Dickinson added the comment: Either raising, or treating a zero-weight-sum as undefined behaviour and documenting that the sum of the weights should be positive sounds fine to me. -1 on the suggestion to (deliberately, by documented design) choose at random in this case. Mathematically,

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-22 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +16847 stage: -> patch review pull_request: https://github.com/python/cpython/pull/17362 ___ Python tracker __

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-22 Thread Tim Peters
Tim Peters added the comment: There are a number of "obvious" properties that should obtain, given the intended meaning of weights: - An input with weight 0 should never be returned. - The distribution shouldn't be affected by adding a new input with weight 0. - The distribution shouldn't b

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-22 Thread Iza Romanowska
Iza Romanowska added the comment: Hi, Many thanks for engaging with this. I agree that we should very clearly separate negative weights from zero weights. A negative number is illegal and that's the end of it. However, a zero weight is not illegal, e.g., [0, 0, 0, 0.1] is a legal sequence

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: xtreak, the other discussion isn't similar at all. The OP is proposing that weights all equal to zero be a well-defined way to specify an equiprobable selection. That is a completely new proposal which is easy to implement, but doesn't make much sense t

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-22 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: IIUC, there was a similar discussion on negative weights and all weights being zero to raise ValueError at https://bugs.python.org/issue18844#msg196252 -- nosy: +xtreak ___ Python tracker

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-22 Thread Iza Romanowska
Iza Romanowska added the comment: Dear Raymond, I understand that passing all zero weights may look nonsensical but random.choices is an implementation of the roulette wheel which is widely used across different scientific disciplines and the situation of passing all zeros is completely pl

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-21 Thread Mark Dickinson
Change by Mark Dickinson : -- nosy: +mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://m

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: Alternatively, we could raise an exception if the weight total isn't positive. Am not sure that has any real worth, but it could be done with only a small additional cost to the critical path. -- ___ Python tr

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: > When zero weights are given, the last element of a sequence > is always chosen. Given non-sensical input, that behavior is as reasonable as any other (fwiw, the same is also observed with all negative weights, even if the negative weights are unequal).

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-21 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +tim.peters ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://ma

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-21 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: htt

[issue38881] unexpected behaviour of random.choices with zero weights

2019-11-21 Thread Iza Romanowska
New submission from Iza Romanowska : Hi, When zero weights are given, the last element of a sequence is always chosen. Example: hits= [] for i in range(100): hits.append(random.choices(["A","B","C","D"], [0, 0, 0, 0])[0]) print (set(hits)) >> {'D'} I guess that most users would expect