B f%% @s4dddddddddd d d g Zd d lZd d lZd d lZd dlmZd dlmZd dlm Z d dl m Z m Z Gddde Zd4ddZddZddZddZddZddZdd Zd!d"Zd5d$d%Zd&d Zd'd Zd(dZd)dZd*dZd6d,dZd-d Zd7d.d/Zd8d0dZ d9d1dZ!d:d2dZ"d;d3dZ#d S)<StatisticsErrorpstdev pvariancestdevvariancemedian median_low median_highmedian_groupedmeanmode harmonic_meanN)Fraction)Decimal)groupby) bisect_left bisect_rightc@s eZdZdS)rN)__name__ __module__ __qualname__rr-/opt/alt/python37/lib/python3.7/statistics.pyrbsc Csd}t|\}}||i}|j}ttt|}xRt|tD]D\}} t||}x0tt| D]"\}}|d7}||d|||<qVWq8Wd|kr|d} ntddt| D} || |fS)Nr css|]\}}t||VqdS)N)r).0dnrrr sz_sum..) _exact_ratioget_coerceinttypermapsumsorteditems) datastartcountrrZpartialsZ partials_getTtypvaluestotalrrr_sumhs$  r-cCs(y|Stk r"t|SXdS)N)Z is_finiteAttributeErrormathZisfinite)xrrr _isfinitesr1cCs||kr |S|tks|tkr |S|tkr,|St||r:|St||rH|St|trV|St|trd|St|tr|t|tr||St|trt|tr|Sd}t||j|jfdS)Nz"don't know how to coerce %s and %s)r bool issubclassrfloat TypeErrorr)r)Smsgrrrrs(     rc Csydt|tkst|tkr"|Sy |j|jfStk r`y|Stk rZYnXYnXWnttfk r|dfSXd}t | t|j dS)Nz0can't convert type '{}' to numerator/denominator) r!r4ras_integer_ratio numerator denominatorr. OverflowError ValueErrorr5formatr)r0r7rrrrs  rcCsjt||kr|St|tr(|jdkr(t}y||Stk rdt|tr^||j||jSYnXdS)Nr)r!r3r r:r4r5rr9)valuer)rrr_converts  r?cCs`tt|}|s|S|dd}x4tdt|D]"}||d|kr6|d|}Pq6W|S)Nr r) collectionsCounteriter most_commonrangelen)r&tableZmaxfreqirrr_countss  rHcCs.t||}|t|kr&|||kr&|StdS)N)rrEr<)ar0rGrrr _find_lteqs rJcCs>t|||d}|t|dkr6||d|kr6|dStdS)N)lor)rrEr<)rIlr0rGrrr _find_rteqs rMnegative valueccs(x"|D]}|dkrt||VqWdS)Nr )r)r+errmsgr0rrr _fail_negs rPcCsHt||krt|}t|}|dkr,tdt|\}}}t|||S)Nrz%mean requires at least one data point)rBlistrErr-r?)r&rr)r,r(rrrr "s cCst||krt|}d}t|}|dkr2tdn<|dkrn|d}t|tjtfrf|dkrbt||Stdy"t ddt ||D\}}}Wnt k rdSXt |||S)Nz.harmonic mean does not support negative valuesrz.harmonic_mean requires at least one data pointr zunsupported typecss|]}d|VqdS)rNr)rr0rrrrcsz harmonic_mean..) rBrQrEr isinstancenumbersZRealrr5r-rPZeroDivisionErrorr?)r&rOrr0r)r,r(rrrr <s$  "cCs\t|}t|}|dkr td|ddkr8||dS|d}||d||dSdS)Nr zno median for empty datar)r$rEr)r&rrGrrrrks   cCsLt|}t|}|dkr td|ddkr8||dS||ddSdS)Nr zno median for empty datarUr)r$rEr)r&rrrrrs   cCs,t|}t|}|dkr td||dS)Nr zno median for empty datarU)r$rEr)r&rrrrrs rc Cst|}t|}|dkr"tdn|dkr2|dS||d}x*||fD]}t|ttfrHtd|qHWy||d}Wn(tk rt|t|d}YnXt||}t |||}|}||d} |||d|| S)Nr zno median for empty datarrUzexpected number but got %r) r$rErrRstrbytesr5r4rJrM) r&intervalrr0objLl1l2Zcffrrrr s&     cCsBt|}t|dkr |ddS|r6tdt|ntddS)Nrr z.no unique mode; found %d equally common valueszno mode for empty data)rHrEr)r&rFrrrr s  csddkrt|tfdd|D\}}}tfdd|D\}}}||dt|8}||fS)Nc3s|]}|dVqdS)rUNr)rr0)crrrsz_ss..c3s|]}|VqdS)Nr)rr0)r^rrrsrU)r r-rE)r&r^r)r,r(UZtotal2Zcount2r)r^r_ss s r`cCsLt||krt|}t|}|dkr,tdt||\}}t||d|S)NrUz*variance requires at least two data pointsr)rBrQrErr`r?)r&xbarrr)ssrrrr!s& cCsHt||krt|}t|}|dkr,tdt||\}}t|||S)Nrz*pvariance requires at least one data point)rBrQrErr`r?)r&murr)rbrrrrPs' cCs2t||}y|Stk r,t|SXdS)N)rsqrtr.r/)r&ravarrrrrs cCs2t||}y|Stk r,t|SXdS)N)rrdr.r/)r&rcrerrrrs )r )rN)r)N)N)N)N)N)$__all__r@r/rSZ fractionsrZdecimalr itertoolsrZbisectrrr<rr-r1rrr?rHrJrMrPr r rrrr r r`rrrrrrrrOs@     :  / 7*  / 0