BUG: random: Fix handling of a=0 for numpy.random.weibull.#12372
BUG: random: Fix handling of a=0 for numpy.random.weibull.#12372charris merged 2 commits intonumpy:masterfrom
Conversation
Before this fix, np.random.weibull(a=0) often returned inf (and in theory could have returned 1). It should only return 0. Closes numpygh-12371.
|
|
||
| double rk_weibull(rk_state *state, double a) | ||
| { | ||
| if (a == 0.0) { |
There was a problem hiding this comment.
What happens if a<0? The documentation says "Should be greater than 0". Is that accurate, or should it be changed to "Must be greater than 0" and we should error for negative values (raise an error in the pyx file)?
There was a problem hiding this comment.
Negative values are handled in RandomState.weibull in mtrand.pyx, so the C function is never called with negative values. For example,
In [39]: np.random.weibull(a=-0.0)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-39-ee6de7ad2cfe> in <module>()
----> 1 np.random.weibull(a=-0.0)
mtrand.pyx in mtrand.RandomState.weibull()
ValueError: a < 0
There was a problem hiding this comment.
I guess "Should be greater than zero" should have been changed to "Must be nonnegative" back when the code was changed to allow a=0. I can change that now.
There was a problem hiding this comment.
I just pushed an update to the docstring.
|
LGTM. |
|
I don't know what happened on that one test run on Travis CI that failed. Something killed the test script? |
|
@WarrenWeckesser Travis times out pretty often these days, although I don't recall it dying in the middle of running the tests before. Seems like it should be unrelated to this PR in any case. Restarted just for the heck of it. |
|
Thanks Warren. |
Before this fix,
np.random.weibull(a=0)often returned inf (andin theory could have returned 1). It should only return 0.
Closes gh-12371.