
    Viu                     ~   S r SSKJr  SSKrSSKJrJr   " S S\5      r " S S\5      r	SS	 jr
S
 r\" \	R                  R                  5       5       H_  u  rr\" \\5      (       d  M  \S;   a  M  \S;   a  M&  \" \5      r\R$                  R                   \l         \\" 5       \'   \" \	S\-   5        Ma     CCCSS jrg)aE  ``statsutils`` provides tools aimed primarily at descriptive
statistics for data analysis, such as :func:`mean` (average),
:func:`median`, :func:`variance`, and many others,

The :class:`Stats` type provides all the main functionality of the
``statsutils`` module. A :class:`Stats` object wraps a given dataset,
providing all statistical measures as property attributes. These
attributes cache their results, which allows efficient computation of
multiple measures, as many measures rely on other measures. For
example, relative standard deviation (:attr:`Stats.rel_std_dev`)
relies on both the mean and standard deviation. The Stats object
caches those results so no rework is done.

The :class:`Stats` type's attributes have module-level counterparts for
convenience when the computation reuse advantages do not apply.

>>> stats = Stats(range(42))
>>> stats.mean
20.5
>>> mean(range(42))
20.5

Statistics is a large field, and ``statsutils`` is focused on a few
basic techniques that are useful in software. The following is a brief
introduction to those techniques. For a more in-depth introduction,
`Statistics for Software
<https://www.paypal-engineering.com/2016/04/11/statistics-for-software/>`_,
an article I wrote on the topic. It introduces key terminology vital
to effective usage of statistics.

Statistical moments
-------------------

Python programmers are probably familiar with the concept of the
*mean* or *average*, which gives a rough quantitiative middle value by
which a sample can be can be generalized. However, the mean is just
the first of four `moment`_-based measures by which a sample or
distribution can be measured.

The four `Standardized moments`_ are:

  1. `Mean`_ - :func:`mean` - theoretical middle value
  2. `Variance`_ - :func:`variance` - width of value dispersion
  3. `Skewness`_ - :func:`skewness` - symmetry of distribution
  4. `Kurtosis`_ - :func:`kurtosis` - "peakiness" or "long-tailed"-ness

For more information check out `the Moment article on Wikipedia`_.

.. _moment: https://en.wikipedia.org/wiki/Moment_(mathematics)
.. _Standardized moments: https://en.wikipedia.org/wiki/Standardized_moment
.. _Mean: https://en.wikipedia.org/wiki/Mean
.. _Variance: https://en.wikipedia.org/wiki/Variance
.. _Skewness: https://en.wikipedia.org/wiki/Skewness
.. _Kurtosis: https://en.wikipedia.org/wiki/Kurtosis
.. _the Moment article on Wikipedia: https://en.wikipedia.org/wiki/Moment_(mathematics)

Keep in mind that while these moments can give a bit more insight into
the shape and distribution of data, they do not guarantee a complete
picture. Wildly different datasets can have the same values for all
four moments, so generalize wisely.

Robust statistics
-----------------

Moment-based statistics are notorious for being easily skewed by
outliers. The whole field of robust statistics aims to mitigate this
dilemma. ``statsutils`` also includes several robust statistical methods:

  * `Median`_ - The middle value of a sorted dataset
  * `Trimean`_ - Another robust measure of the data's central tendency
  * `Median Absolute Deviation`_ (MAD) - A robust measure of
    variability, a natural counterpart to :func:`variance`.
  * `Trimming`_ - Reducing a dataset to only the middle majority of
    data is a simple way of making other estimators more robust.

.. _Median: https://en.wikipedia.org/wiki/Median
.. _Trimean: https://en.wikipedia.org/wiki/Trimean
.. _Median Absolute Deviation: https://en.wikipedia.org/wiki/Median_absolute_deviation
.. _Trimming: https://en.wikipedia.org/wiki/Trimmed_estimator


Online and Offline Statistics
-----------------------------

Unrelated to computer networking, `online`_ statistics involve
calculating statistics in a `streaming`_ fashion, without all the data
being available. The :class:`Stats` type is meant for the more
traditional offline statistics when all the data is available. For
pure-Python online statistics accumulators, look at the `Lithoxyl`_
system instrumentation package.

.. _Online: https://en.wikipedia.org/wiki/Online_algorithm
.. _streaming: https://en.wikipedia.org/wiki/Streaming_algorithm
.. _Lithoxyl: https://github.com/mahmoud/lithoxyl

    )print_functionN)floorceilc                   $    \ rS rSrS rSS jrSrg)_StatsProperty   c                     Xl         X l        SU-   U l        UR                  =(       d    SnUR	                  S5      u  n  nX@l        g )N_ z>>>)namefuncinternal_name__doc__	partition)selfr   r   docpre_doctest_docr
   s         e/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/boltons/statsutils.py__init___StatsProperty.__init__   s@    		 4Zll b #e 4A&    Nc                    Uc  U $ UR                   (       d  UR                  $  [        XR                  5      $ ! [         a=    [        XR                  U R                  U5      5        [        XR                  5      s $ f = fN)datadefaultgetattrr   AttributeErrorsetattrr   )r   objobjtypes      r   __get___StatsProperty.__get__   sk    ;Kxx;;	43 2 233 	4C++TYYs^<3 2 233	4s   9 AB ?B )r   r   r   r   r   )__name__
__module____qualname____firstlineno__r   r!   __static_attributes__ r   r   r   r      s    '	4r   r   c                      \ rS rSrSrS/S jrS rS rS rS r	S r
\" S	\
5      rS
 r\" S\5      rS r\" S\5      rS r\" S\5      rS r\" S\5      rS r\" S\5      rS r\" S\5      rS r\" S\5      rS r\" S\5      rS r\" S\5      r\rS r \" S\ 5      r!S r"\" S\"5      r#S  r$\" S!\$5      r%S" r&\" S#\&5      r'\(S$ 5       r)S% r*S& r+S0S' jr,S( r-S1S* jr.S2S+ jr/S2S, jr0S3S- jr1S.r2g))4Stats   a  The ``Stats`` type is used to represent a group of unordered
statistical datapoints for calculations such as mean, median, and
variance.

Args:

    data (list): List or other iterable containing numeric values.
    default (float): A value to be returned when a given
        statistical measure is not defined. 0.0 by default, but
        ``float('nan')`` is appropriate for stricter applications.
    use_copy (bool): By default Stats objects copy the initial
        data into a new list to avoid issues with
        modifications. Pass ``False`` to disable this behavior.
    is_sorted (bool): Presorted data can skip an extra sorting
        step for a little speed boost. Defaults to False.

c           
         X0l         X@l        U(       a  [        U5      U l        OXl        X l        U R
                  n[        U 5       Vs/ s H&  n[        [        XVS 5      [        5      (       d  M$  UPM(     snU l
        SU l        g s  snf )Nr   )	_use_copy
_is_sortedlistr   r   	__class__dir
isinstancer   r   _prop_attr_names_pearson_precision)r   r   r   use_copy	is_sortedclsas          r   r   Stats.__init__   su    !#T
DIInn,/I !@Iq$.wst/D/=%? "#I !@ #$!@s   
#B1Bc                 ,    [        U R                  5      $ r   lenr   r   s    r   __len__Stats.__len__   s    499~r   c                 ,    [        U R                  5      $ r   )iterr   r=   s    r   __iter__Stats.__iter__   s    DIIr   c                     U R                   (       d  [        U R                  5      $ U R                  (       d  U R                  R	                  5         U R                  $ )a  When using a copy of the data, it's better to have that copy be
sorted, but we do it lazily using this method, in case no
sorted measures are used. I.e., if median is never called,
sorting would be a waste.

When not using a copy, it's presumed that all optimizations
are on the user.
)r-   sortedr   r.   sortr=   s    r   _get_sorted_dataStats._get_sorted_data   s9     ~~$))$$IINNyyr   c                     U R                    H@  n[        U R                  U5      R                  n[	        X5      (       d  M5  [        X5        MB     g)a\  ``Stats`` objects automatically cache intermediary calculations
that can be reused. For instance, accessing the ``std_dev``
attribute after the ``variance`` attribute will be
significantly faster for medium-to-large datasets.

If you modify the object by adding additional data points,
call this function to have the cached statistics recomputed.

N)r3   r   r0   r   hasattrdelattr)r   	attr_names     r   clear_cacheStats.clear_cache   sE     ..I	:HHI4++D$	 /
 	r   c                 ,    [        U R                  5      $ )zThe number of items in this Stats object. Returns the same as
:func:`len` on a Stats object, but provided for pandas terminology
parallelism.

>>> Stats(range(20)).count
20
r;   r=   s    r   _calc_countStats._calc_count   s     499~r   countc                 Z    [        U R                  S5      [        U R                  5      -  $ )z
The arithmetic mean, or "average". Sum of the values divided by
the number of values.

>>> mean(range(20))
9.5
>>> mean(list(range(19)) + [949])  # 949 is an arbitrary outlier
56.0
        )sumr   r<   r=   s    r   
_calc_meanStats._calc_mean   s"     499c"S^33r   meanc                 l    U R                   (       a  U R                  S   $ [        U R                  5      $ )zD
The maximum value present in the data.

>>> Stats([2, 1, 3]).max
3
)r.   r   maxr=   s    r   	_calc_maxStats._calc_max   s'     ??99R= 499~r   r[   c                 l    U R                   (       a  U R                  S   $ [        U R                  5      $ )zD
The minimum value present in the data.

>>> Stats([2, 1, 3]).min
1
r   )r.   r   minr=   s    r   	_calc_minStats._calc_min	  s'     ??99Q<499~r   r_   c                 B    U R                  U R                  5       S5      $ )a5  
The median is either the middle value or the average of the two
middle values of a sample. Compared to the mean, it's generally
more resilient to the presence of outliers in the sample.

>>> median([2, 1, 3])
2
>>> median(range(97))
48
>>> median(list(range(96)) + [1066])  # 1066 is an arbitrary outlier
48
      ?)_get_quantilerG   r=   s    r   _calc_medianStats._calc_median  s      !!$"7"7"93??r   medianc                 H    U R                  S5      U R                  S5      -
  $ )a   Inter-quartile range (IQR) is the difference between the 75th
percentile and 25th percentile. IQR is a robust measure of
dispersion, like standard deviation, but safer to compare
between datasets, as it is less influenced by outliers.

>>> iqr([1, 2, 3, 4, 5])
2
>>> iqr(range(1001))
500
      ?      ?)get_quantiler=   s    r   	_calc_iqrStats._calc_iqr%  s%       &):):4)@@@r   iqrc                 t   ^ ^ T R                  5       mU U4S jnU" S5      SU" S5      -  -   U" S5      -   S-  $ )a  The trimean is a robust measure of central tendency, like the
median, that takes the weighted average of the median and the
upper and lower quartiles.

>>> trimean([2, 1, 3])
2.0
>>> trimean(range(97))
48.0
>>> trimean(list(range(96)) + [1066])  # 1066 is an arbitrary outlier
48.0

c                 (   > TR                  TU 5      $ r   )rd   )qr   sorted_datas    r   <lambda>%Stats._calc_trimean.<locals>.<lambda>A  s    t))+q9r   rj      rc   ri   g      @)rG   )r   gqrr   s   ` @r   _calc_trimeanStats._calc_trimean3  s=     ++-94A3K(2d83s::r   trimeanc                 6    [        U R                  S5      5      $ )zyVariance is the average of the squares of the difference between
each value and the mean.

>>> variance(range(97))
784.0
ru   )rX   _get_pow_diffsr=   s    r   _calc_varianceStats._calc_varianceE  s     D''*++r   variancec                      U R                   S-  $ )zNStandard deviation. Square root of the variance.

>>> std_dev(range(97))
28.0
rc   )r~   r=   s    r   _calc_std_devStats._calc_std_devQ  s     }}##r   std_devc           	          [        U R                  5      n[        [        U5      5      n[        U Vs/ s H  n[	        X#-
  5      PM     sn5      $ s  snf )zMedian Absolute Deviation is a robust measure of statistical
dispersion: http://en.wikipedia.org/wiki/Median_absolute_deviation

>>> median_abs_dev(range(97))
24.0
)rE   r   floatrg   abs)r   sorted_valsxvs       r   _calc_median_abs_devStats._calc_median_abs_dev[  sD     TYY'&%&;7;as15z;7887s   Amedian_abs_devc                 p    [        U R                  5      nU(       a  U R                  U-  $ U R                  $ )zStandard deviation divided by the absolute value of the average.

http://en.wikipedia.org/wiki/Relative_standard_deviation

>>> print('%1.3f' % rel_std_dev(range(97)))
0.583
)r   rX   r   r   )r   abs_means     r   _calc_rel_std_devStats._calc_rel_std_devj  s-     tyy><<(**<<r   rel_std_devc                     U R                   U R                  p![        U5      S:  a>  US:  a8  [        U R	                  S5      5      [        [        U5      S-
  US-  -  5      -  $ U R                  $ )a  Indicates the asymmetry of a curve. Positive values mean the bulk
of the values are on the left side of the average and vice versa.

http://en.wikipedia.org/wiki/Skewness

See the module docstring for more about statistical moments.

>>> skewness(range(97))  # symmetrical around 48.0
0.0
>>> left_skewed = skewness(list(range(97)) + list(range(10)))
>>> right_skewed = skewness(list(range(97)) + list(range(87, 97)))
>>> round(left_skewed, 3), round(right_skewed, 3)
(0.114, -0.114)
   r      )r   r   r<   rU   r{   r   r   r   r   s_devs      r   _calc_skewnessStats._calc_skewnessz  sf      iiet9q=UQY++A./3t9q=UaZ89: ; <<r   skewnessc                     U R                   U R                  p![        U5      S:  a>  US:  a8  [        U R	                  S5      5      [        [        U5      S-
  US-  -  5      -  $ g)a  Indicates how much data is in the tails of the distribution. The
result is always positive, with the normal "bell-curve"
distribution having a kurtosis of 3.

http://en.wikipedia.org/wiki/Kurtosis

See the module docstring for more about statistical moments.

>>> kurtosis(range(9))
1.99125

With a kurtosis of 1.99125, [0, 1, 2, 3, 4, 5, 6, 7, 8] is more
centrally distributed than the normal curve.
r   r      rT   )r   r   r<   rU   r{   r   r   s      r   _calc_kurtosisStats._calc_kurtosis  s_      iiet9q=UQY++A./3t9q=UaZ89: ; r   kurtosisc                 Z   U R                   nU R                  nU R                  nUS-  nUS-  nSU-  SU-  -
  nX%S-   -  nSU-  SU-  -
  S-
  n[        Xq5      S:X  a  [        XQ5      S:X  a  gUS:  a  gUS:  a  gO%[        X5      S:X  a  gUS-  SU-  U-  -  n	U	S:  a  g	[	        S
5      e)Ng       @      ?r   r   ru      r      r   zmissed a spot)r4   r   r   roundRuntimeError)
r   	precisionr   r   beta1beta2c0c1c2ks
             r   _calc_pearson_typeStats._calc_pearson_type  s    ++	====C3 %iAI&#%iAI&*1$U&!+19QY 2!Q&a1r6B;'A1u?++r   pearson_typec                     U [        U 5      p2US-  US-
  -  n[        [        U5      5      [        [        U5      5      peXV:X  a  X%   $ X%   Xd-
  -  X&   XE-
  -  -   $ )Nr   r   )r<   intr   r   )rr   rq   r   nidxidx_fidx_cs          r   rd   Stats._get_quantile  sa    s;/a#gQ5:DIu>;u{+s{0KLLr   c                     [        U5      nSUs=::  a  S::  d  O  [        SU-  5      eU R                  (       d  U R                  $ U R	                  U R                  5       U5      $ )a  Get a quantile from the dataset. Quantiles are floating point
values between ``0.0`` and ``1.0``, with ``0.0`` representing
the minimum value in the dataset and ``1.0`` representing the
maximum. ``0.5`` represents the median:

>>> Stats(range(100)).get_quantile(0.5)
49.5
rT   r   z&expected q between 0.0 and 1.0, not %r)r   
ValueErrorr   r   rd   rG   )r   rq   s     r   rk   Stats.get_quantile  sV     !Ha3EIJJ<<!!$"7"7"91==r   c                     U R                   nU R                  S:X  a&  X:X  a  gX:  a  [        S5      $ X:  a  [        S5      $ [        U5      U-
  U R                  -  $ )zGet the z-score for *value* in the group. If the standard deviation
is 0, 0 inf or -inf will be returned to indicate whether the value is
equal to, greater than or below the group's mean.
r   infz-inf)rX   r   r   )r   valuerX   s      r   
get_zscoreStats.get_zscore  sW    
 yy<<1}|U|#|V}$et#t||33r   c                     [        U5      nSUs=::  a  S:  d  O  [        SU-  5      e[        U R                  5      n[	        X2-  5      nUS:X  a  gU R                  5       XD*  U l        U R                  5         g)aW  A utility function used to cut a proportion of values off each end
of a list of values. This has the effect of limiting the
effect of outliers.

Args:
    amount (float): A value between 0.0 and 0.5 to trim off of
        each side of the data.

.. note:

    This operation modifies the data in-place. It does not
    make or return a copy.

rT   rc   z+expected amount between 0.0 and 0.5, not %rN)r   r   r<   r   r   rG   rM   )r   amounttrimsize	size_diffs        r   trim_relativeStats.trim_relative  sy     V}d S J#$ % %499~$	))+IjA	r   c                 h    U R                   nU R                   Vs/ s H
  o3U-
  U-  PM     sn$ s  snf )z>
A utility function used for calculating statistical moments.
)rX   r   )r   powermr   s       r   r{   Stats._get_pow_diffs
  s0     II*.))4)QQ5 )444s   /Nc           	         U R                   (       d  S/$ U R                   n[        U5      [        U5      [        U5      penUS:  a9  U(       d  UnXe-
  [	        U5      -  n[        U5       Vs/ s H	  oXx-  -   PM     n	nOUc  U R                  S5      U R                  S5      pSX-
  -  US-  -  n[        S[        [        Xe-
  U-  5      5      5      n[        US-   5       Vs/ s H	  oXx-  -   PM     n	nU	 Vs/ s H  oU:  d  M
  UPM     n	nO/Xe-
  [	        U5      -  n[        U5       Vs/ s H	  oXx-  -   PM     n	nU(       a  U	R                  [	        U5      5        U	$ s  snf s  snf s  snf s  snf )NrT   r   rj   ri   ru   gUUUUUU?r   )
r   r<   r_   r[   r   rangerk   r   r   append)r   rR   with_maxr   len_datamin_datamax_datadxibinsq25q75	bin_countbs                 r   _get_bin_boundsStats._get_bin_bounds  s[   yy5Lyy'*4y#d)SYHa< %u5B16u>A'D>D]((.0A0A$0GciH$9:BAs4)<(B#CDEI16y1}1EF1EA'1EDF#4t!8|AtD4D%u5B16u>A'D>KKh( ? G4 ?s   -E"$E':	E,E,-E1c           	         [        UR                  SS5      5      nU(       a  [        SUR                  5       -  5      eU(       d  U R	                  5       nO [        U5      nU R	                  U5      nSU-  nU Vs/ s H  n[        Xv-  5      U-  PM     nn[        [        U5      5      nU R                   Vs/ s H  n[        R                  " X5      S-
  PM     n	n0 n
U	 H  n X==   S-  ss'   M     [        U5       VVs/ s H  u  pXzR!                  US5      4PM     nnnU$ ! [         af     U Vs/ s H  n[        U5      PM     Os  snf nnO! [         a    [        SU-  5      ef = fU R                  US   :  a  U R                  /U-   n GN%f = fs  snf s  snf ! [         a    SX'    M  f = fs  snnf )a  Produces a list of ``(bin, count)`` pairs comprising a histogram of
the Stats object's data, using fixed-width bins. See
:meth:`Stats.format_histogram` for more details.

Args:
    bins (int): maximum number of bins, or list of
        floating-point bin boundaries. Defaults to the output of
        Freedman's algorithm.
    bin_digits (int): Number of digits used to round down the
        bin boundaries. Defaults to 1.

The output of this method can be stored and/or modified, and
then passed to :func:`statsutils.format_histogram_counts` to
achieve the same text formatting as the
:meth:`~Stats.format_histogram` method. This can be useful for
snapshotting over time.

bin_digitsr   z unexpected keyword arguments: %rzGbins expected integer bin count or list of float bin boundaries, not %rr   g      $@)r   pop	TypeErrorkeysr   r   	Exceptionr   r_   r   rE   setr   bisectKeyError	enumerateget)r   r   kwr   r   r   round_factorr   didxs	count_mapr   r   
bin_countss                 r   get_histogram_countsStats.get_histogram_counts-  s   $ a01
>JKK'')D7I	 ++I6 z)@DE1a&',6Ec$i 48II>Iqd&*I>	C#!#  <ET?K?41q--1-.?
K5  -P.23dE!Hd3D3D  P$ &HJN&O P PP 88d1g% HH:,D- F ?
  #!"	# LsZ   D* =F;#F"(F'F<*
F5E9EEFE00&FF'F98F9c                     UR                  SS5      nUR                  SS5      nU R                  " SSU0UD6n[        UUUS9$ )a+  Produces a textual histogram of the data, using fixed-width bins,
allowing for simple visualization, even in console environments.

>>> data = list(range(20)) + list(range(5, 15)) + [10]
>>> print(Stats(data).format_histogram(width=30))
 0.0:  5 #########
 4.4:  8 ###############
 8.9: 11 ####################
13.3:  5 #########
17.8:  2 ####

In this histogram, five values are between 0.0 and 4.4, eight
are between 4.4 and 8.9, and two values lie between 17.8 and
the max.

You can specify the number of bins, or provide a list of
bin boundaries themselves. If no bins are provided, as in the
example above, `Freedman's algorithm`_ for bin selection is
used.

Args:
    bins (int): Maximum number of bins for the
        histogram. Also accepts a list of floating-point
        bin boundaries. If the minimum boundary is still
        greater than the minimum value in the data, that
        boundary will be implicitly added. Defaults to the bin
        boundaries returned by `Freedman's algorithm`_.
    bin_digits (int): Number of digits to round each bin
        to. Note that bins are always rounded down to avoid
        clipping any data. Defaults to 1.
    width (int): integer number of columns in the longest line
       in the histogram. Defaults to console width on Python
       3.3+, or 80 if that is not available.
    format_bin (callable): Called on each bin to create a
       label for the final output. Use this function to add
       units, such as "ms" for milliseconds.

Should you want something more programmatically reusable, see
the :meth:`~Stats.get_histogram_counts` method, the output of
is used by format_histogram. The :meth:`~Stats.describe`
method is another useful summarization method, albeit less
visual.

.. _Freedman's algorithm: https://en.wikipedia.org/wiki/Freedman%E2%80%93Diaconis_rule
widthN
format_binr   )r   r   r(   )r   r   format_histogram_counts)r   r   r   r   r   r   s         r   format_histogramStats.format_histogramd  sR    \ w%VVL$/
..?D?B?
&z-22<> 	>r   c           	      t   Uc  SnOUS;  a  [        SU-  5      eU=(       d    / SQn/ nU H0  nU R                  U5      nUR                  [        U5      U45        M2     SU R                  4SU R
                  4SU R                  4SU R                  4S	U R                  4/nUR                  U5        UR                  S
U R                  45        US:X  a  [        U5      nU$ US:X  a  UnU$ US:X  a>  SR                  U VV	s/ s H  u  pUS-   R                  S5      < U	< 3PM!     sn	n5      nW$ s  sn	nf )a  Provides standard summary statistics for the data in the Stats
object, in one of several convenient formats.

Args:
    quantiles (list): A list of numeric values to use as
        quantiles in the resulting summary. All values must be
        0.0-1.0, with 0.5 representing the median. Defaults to
        ``[0.25, 0.5, 0.75]``, representing the standard
        quartiles.
    format (str): Controls the return type of the function,
        with one of three valid values: ``"dict"`` gives back
        a :class:`dict` with the appropriate keys and
        values. ``"list"`` is a list of key-value pairs in an
        order suitable to pass to an OrderedDict or HTML
        table. ``"text"`` converts the values to text suitable
        for printing, as seen below.

Here is the information returned by a default ``describe``, as
presented in the ``"text"`` format:

>>> stats = Stats(range(1, 8))
>>> print(stats.describe(format='text'))
count:    7
mean:     4.0
std_dev:  2.0
mad:      2.0
min:      1
0.25:     2.5
0.5:      4
0.75:     5.5
max:      7

For more advanced descriptive statistics, check out my blog
post on the topic `Statistics for Software
<https://www.paypal-engineering.com/2016/04/11/statistics-for-software/>`_.

dict)r   r/   textzIinvalid format for describe, expected one of "dict"/"list"/"text", not %r)rj   rc   ri   rR   rX   r   madr_   r[   r/   r   
:
   )r   rk   r   strrR   rX   r   r   r_   extendr[   r   joinljust)
r   	quantilesformatq_itemsrq   q_valitemsretlabelvals
             r   describeStats.describe  s\   L >F33 M%& ' ' 2!2	A%%a(ENNCFE?+  4::&$))$T\\*""	$ 	WeTXX&'Vu+C 
 vC 
 v))/46/4 ).':':2'>D/46 7C
6s   &D4
)r.   r4   r3   r-   r   r   )rT   TF)g333333?)NFr   NN)3r#   r$   r%   r&   r   r   r>   rB   rG   rM   rP   r   rR   rV   rX   r\   r[   r`   r_   re   rg   rl   rn   rw   ry   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodrd   rk   r   r   r{   r   r   r   r  r'   r(   r   r   r*   r*      st   "$" 7K0E
4 &*-D	 	
*C	 	
*C@ Hl3FA 	
*C;  Y6G	, j.9H$ Y6G9 $$46JKN
C  !0ABK , j.9H, j.9H,8 ".2DELM M> 44585n3>jAr   r*   c                 2    [        U 5      R                  XS9$ )a  A convenience function to get standard summary statistics useful
for describing most data. See :meth:`Stats.describe` for more
details.

>>> print(describe(range(7), format='text'))
count:    7
mean:     3.0
std_dev:  2.0
mad:      2.0
min:      0
0.25:     1.5
0.5:      3
0.75:     4.5
max:      6

See :meth:`Stats.format_histogram` for another very useful
summarization that uses textual visualization.
)r   r   )r*   r  )r   r   r   s      r   r  r    s    & ;)CCr   c                    ^  SU 4S jjnU$ )Nc                 ,   > [        [        XSS9T5      $ )NF)r   r5   )r   r*   )r   r   rL   s     r   stats_helper$_get_conv_func.<locals>.stats_helper  s    uTUC " 	"r   )rT   r(   )rL   r  s   ` r   _get_conv_funcr    s    " r   )r[   r_   rR   )r   _calc_c           	         / nU(       d  S nU(       d   SSK nUR                  5       S   nU  VVs/ s H  u  pVUPM	     nnn[        U  VVs/ s H  u  phUPM	     snn5      n	[	        [        U	5      5      n
U Vs/ s H  nSU" U5      -  PM     nn[        U Vs/ s H  n[	        U5      PM     sn5      nSU-  < SU	< S3n[        U[	        U5      -
  S	5      n[        U5      U	-  nS
n[        X5       HR  u  nu  nn[        [        UU-  5      5      nSU-  =(       d    SnUR                  UUUU
US9nUR                  U5        MT     SR                  U5      $ ! [         a    Sn GN@f = fs  snnf s  snnf s  snf s  snf )a  The formatting logic behind :meth:`Stats.format_histogram`, which
takes the output of :meth:`Stats.get_histogram_counts`, and passes
them to this function.

Args:
    bin_counts (list): A list of bin values to counts.
    width (int): Number of character columns in the text output,
        defaults to 80 or console width in Python 3.3+.
    format_bin (callable): Used to convert bin values into string
        labels.
c                     U $ r   r(   )r   s    r   rs   )format_histogram_counts.<locals>.<lambda>  s    qr   r   NP   z%sr   z: z #r   z2{label:>{label_cols}}: {count:>{count_cols}} {bar}#|)r  
label_colsrR   
count_colsbarr   )shutilget_terminal_sizer   r[   r<   r   r   zipr   r   r   r   r   )r   r   r   linesr  r   r
   r   rR   	count_maxr  labelslr  tmp_linebar_colsline_ktmplr  bin_valbar_lenr  lines                          r   r   r   
  s    E 
	,,.q1E %%*$!A*D%:6:xqU:67IS^$J,01DqdZ]"DF1f-fc!ff-.J :-y9H53x=(!,H8_y(F?D#&v#:eEFN+,W}${{&0!&&0"	  $
 	T $; 99U1  	E	 &6 2-s(   E E0E6
:E<FE-,E-r  )r   
__future__r   r   mathr   r   objectr   r*   r  r  r/   __dict__r   rL   attrr2   r   globalsrK   r   r(   r   r   <module>r,     s   B_B &  4V 4,|F |~D, ENN0023OIt$''// i(yy((#	)x)+, 4 	+r   