[issue31689] random.choices does not work with negative weights

2019-07-18 Thread Aldwin Pollefeyt
Aldwin Pollefeyt added the comment: issue37624: not adding an extra O(n) step to check for unusual inputs with undefined meaning -- that would just impair the normal use cases for near zero benefit. -- nosy: +aldwinaldwin ___ Python tracker

[issue31689] random.choices does not work with negative weights

2019-03-01 Thread Ted Whalen
Ted Whalen added the comment: I think this should be reopened, as the behavior doesn't always raise an error, and, in fact, does something very unexpected: Python 3.7.2 (default, Jan 13 2019, 12:50:01) [Clang 10.0.0 (clang-1000.11.45.5)] on darwin Type "help", "copyright", "credits" or "licen

[issue31689] random.choices does not work with negative weights

2018-08-06 Thread David Kopec
David Kopec added the comment: It's not a bug, but I agree with Allen that it could use a much more clear error message. I think his proposed ValueError makes a lot more sense than just raising an IndexError as currently occurs. This will help people debug their programs who don't even reali

[issue31689] random.choices does not work with negative weights

2017-10-04 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker ___ ___ Pyth

[issue31689] random.choices does not work with negative weights

2017-10-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: I'm content with the current exception. -- assignee: -> rhettinger ___ Python tracker ___ ___

[issue31689] random.choices does not work with negative weights

2017-10-04 Thread Allen Riddell
Allen Riddell added the comment: Upon some reflection, I think raising a ValueError is the right thing to do. Negative weights don't have an obvious interpretation. -- ___ Python tracker

[issue31689] random.choices does not work with negative weights

2017-10-04 Thread Mark Dickinson
Mark Dickinson added the comment: @ariddell: What behaviour did you want to see here? It wouldn't have occurred to me to even try using `random.choices` with negative weights; forcing the weights to be nonnegative (with strictly positive sum) sounds like a natural restriction. -- nos

[issue31689] random.choices does not work with negative weights

2017-10-04 Thread Allen Riddell
New submission from Allen Riddell : Code to reproduce problem: population = list(range(10)) weights = list(-1 * w for w in range(10)) [random.choices(population, weights) for _ in range(1000)] will raise IndexError: 358 bisect = _bisect.bisect 359 total = cum_weights[-1