Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Theimplementation ofstatistics.geometric_mean using logarithms requires that all input values must be positive. However, a real geometric mean is defined for all sets ofnon-negative real values. The geo mean of any set of numbers containing zero is itself zero.
fromstatisticsimportgeometric_meangeometric_mean([1.0,2.0,0.0])Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>File"/home/milthorpe/miniconda3/lib/python3.11/statistics.py",line489,ingeometric_meanraiseStatisticsError('geometric mean requires a non-empty dataset 'statistics.StatisticsError:geometricmeanrequiresanon-emptydatasetcontainingpositivenumbers
I believegeometric_mean should return 0 if any of the input values are zero. (It should continue to return aStatisticsError if any of the input values are negative.)
CPython versions tested on:
3.11
Operating systems tested on:
Linux