This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fix random.gammavariate bug #527139
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: mwh, rhettinger, sjmachin, tim.peters
Priority: normal Keywords: patch

Created on 2002-03-13 12:15 by sjmachin, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
random.dif sjmachin, 2002-03-13 12:15 patch to fix bug #527139
random2.dif sjmachin, 2002-03-18 12:57 v2 of patch for bug #527139
Messages (14)
msg39220 - (view) Author: John Machin (sjmachin) Date: 2002-03-13 12:15
random.gammavariate() doesn't work for gamma < 0.5

See detailed comment on bug # 527139
msg39221 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2002-03-16 16:53
Logged In: YES 
user_id=6656

Tim, do you think this should go into 2.2.1?
msg39222 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-03-16 17:38
Logged In: YES 
user_id=31435

Possibly, depending on whether it belongs in 2.3 -- I'm 
spread too thin to review it now.
msg39223 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-03-17 19:42
Logged In: YES 
user_id=31435

Michael, this definitely doesn't belong in 2.2.1 as-is, 
because it removes a currently-exported name (buggy or not, 
sensible or not, somebody may be using random.stdgamma now 
and be happy with it).

John, if you're going to remove stdgamma, you need also to 
remove its (string) name from the module's __all__ list 
(right before the _verify() function).
msg39224 - (view) Author: John Machin (sjmachin) Date: 2002-03-17 20:46
Logged In: YES 
user_id=480138

OK; I understand the problems with the patch. Not sure 
about the way forward -- shall I prepare a patch that just 
fixes gammavariate() and leaves stdgamma() there (with 
warning in the comments: deprecated? will be removed in 
2.x?)? Do you want it real soon now (for 2.2.1)?

msg39225 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-03-18 05:32
Logged In: YES 
user_id=31435

John, if I were you <wink> I'd leave stdgamma alone, except 
for adding this code to its start:

import warnings
warnings.warn("The stdgamma function is deprecated; "
              "use gammavariate() instead",
              DeprecationWarning)

Then we can remove stdgamma in 2.4.  2.2.1 will probably go 
out on Monday night, so it would be nice to get this done 
before then.  OTOH, I expect there will be a 2.2.2 later, 
so not a tragedy if it's not.
msg39226 - (view) Author: John Machin (sjmachin) Date: 2002-03-18 12:57
Logged In: YES 
user_id=480138

Patch file random2.dif uploaded.
stdgamma() deprecated as per TP suggestion.
msg39227 - (view) Author: John Machin (sjmachin) Date: 2002-03-18 13:05
Logged In: YES 
user_id=480138

Attached is test script test_gamma.py. Passing test means: 
eye-balling of relative "errors" reveals no nasties for at 
least alpha >= 0.1

Note that Python's gammavariate() is not very accurate at 
all for alpha < 0.1 approx. However neither are another two 
methods that I tried (details in the file). I'll leave it 
at that -- evidently alpha < 1.0 is "rare and difficult" 
according to Marsaglia & Tsang.
msg39228 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2002-03-18 13:08
Logged In: YES 
user_id=6656

I'm afraid this isn't going to make 2.2.1c1.

I'll try to consider it before 2.2.1 final, but I'd want to
be very certain about things before applying it there.
msg39229 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-05-14 00:29
Logged In: YES 
user_id=80475

John, I had fixed the original bug report without knowing 
that this patch existed.  Your patch would've saved me the 
time to figure-out what was wrong :(

My patch took the minimal intervention approach (touching 
the fewest lines) to fix the docs and allow the code to 
work for alpha>0 without changing the user interface or 
affecting existing code.

The commit is already in the CVS.  Is there anything else 
important that needs to be accomplished?  The module is in 
dire need of docstrings.  Also, is it important to 
deprecate stdgamma?

P.S.  I did run my own eyeball test for means and variances 
for alphas including .01 .1 .2 ... 8.  Everything is 
working fine now.
msg39230 - (view) Author: John Machin (sjmachin) Date: 2002-05-14 01:08
Logged In: YES 
user_id=480138

Raymond, If you had read the copious notes that I posted on the original bug 
report, you would have seen that I had (a)figured out what was wrong and (b) 
promised a patch.

stdgamma with those extra arguments is an 
abomination and should have never been there in the first place.
msg39231 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-05-14 02:30
Logged In: YES 
user_id=80475

The tone sounds angry so I apologize for stepping on your 
toes.

The good news is that my patch is essentially a subset of 
yours (a subset that fixed the docs and the original bug).  
Code improvements like deprecating stdgamma or improving 
the docstrings are still possible.  If you post any further 
patches, I'll help them along as much as I can.  As it 
stands, the module leaves much to be desired.
msg39232 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-05-14 03:36
Logged In: YES 
user_id=31435

I'm all in favor of the only two people who have 
volunteered two seconds to look at this code in two years 
making up and getting on with it.  John, is there something 
you object to in what Raymond committed (not the process, 
but the result)?  Raymond, would you add the 
DeprecationWarning for stdgamma?  We still need at least a 
full release cycle to deprecate anything.

Heh.  You probably thought this would be less contentious 
than championing PEPs <wink>.
msg39233 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-05-14 07:03
Logged In: YES 
user_id=80475

Done.  Put in John's patch as random.py 1.30 and 1.26.6.3.
John to close patch if all issues are resolved.
Peace and love to all.
History
Date User Action Args
2022-04-10 16:05:05adminsetgithub: 36253
2002-03-13 12:15:01sjmachincreate