a
    Sic"                     @  s   d dl mZ d dlmZ d dlmZ d dlmZ d dlZ	d dl
Zd dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ erd dlmZ eG dd deZeG dd deZdS )    )annotations)	dataclass)warn)ClassVarN)	DataFrame)GroupBy)Scale)Stat)TYPE_CHECKING)	ArrayLikec                   @  s4   e Zd ZU dZdZded< dddddd	d
dZdS )Countz
    Count distinct observations within groups.

    See Also
    --------
    Hist : A more fully-featured transform including binning and/or normalization.

    Examples
    --------
    .. include:: ../docstrings/objects.Count.rst

    TzClassVar[bool]group_by_orientr   r   strdict[str, Scale]datagroupbyorientscalesreturnc                 C  sD   ddd |}|| ||< |||tijddgdjdd}|S )Nyxr   r   )subsetT)drop)getagglendropnareset_index)selfr   r   r   r   varres r#   S/var/www/html/django/DPS/env/lib/python3.9/site-packages/seaborn/_stats/counting.py__call__#   s    zCount.__call__N)__name__
__module____qualname____doc__r   __annotations__r%   r#   r#   r#   r$   r      s   
r   c                   @  s   e Zd ZU dZdZded< dZded< dZd	ed
< dZded< dZ	ded< dZ
ded< dZded< dZded< dd Zdd Zdd Zdd Zdd Zdd  Zd!d"dd#d!d$d%d&ZdS )'Hista:
  
    Bin observations, count them, and optionally normalize or cumulate.

    Parameters
    ----------
    stat : str
        Aggregate statistic to compute in each bin:

        - `count`: the number of observations
        - `density`: normalize so that the total area of the histogram equals 1
        - `percent`: normalize so that bar heights sum to 100
        - `probability` or `proportion`: normalize so that bar heights sum to 1
        - `frequency`: divide the number of observations by the bin width

    bins : str, int, or ArrayLike
        Generic parameter that can be the name of a reference rule, the number
        of bins, or the bin breaks. Passed to :func:`numpy.histogram_bin_edges`.
    binwidth : float
        Width of each bin; overrides `bins` but can be used with `binrange`.
    binrange : (min, max)
        Lowest and highest value for bin edges; can be used with either
        `bins` (when a number) or `binwidth`. Defaults to data extremes.
    common_norm : bool or list of variables
        When not `False`, the normalization is applied across groups. Use
        `True` to normalize across all groups, or pass variable name(s) that
        define normalization groups.
    common_bins : bool or list of variables
        When not `False`, the same bins are used for all groups. Use `True` to
        share bins across all groups, or pass variable name(s) to share within.
    cumulative : bool
        If True, cumulate the bin values.
    discrete : bool
        If True, set `binwidth` and `binrange` so that bins have unit width and
        are centered on integer values

    Notes
    -----

    The choice of bins for computing and plotting a histogram can exert
    substantial influence on the insights that one is able to draw from the
    visualization. If the bins are too large, they may erase important features.
    On the other hand, bins that are too small may be dominated by random
    variability, obscuring the shape of the true underlying distribution. The
    default bin size is determined using a reference rule that depends on the
    sample size and variance. This works well in many cases, (i.e., with
    "well-behaved" data) but it fails in others. It is always a good to try
    different bin sizes to be sure that you are not missing something important.
    This function allows you to specify bins in several different ways, such as
    by setting the total number of bins to use, the width of each bin, or the
    specific locations where the bins should break.


    Examples
    --------
    .. include:: ../docstrings/objects.Hist.rst

    countr   statautozstr | int | ArrayLikebinsNzfloat | Nonebinwidthztuple[float, float] | NonebinrangeTzbool | list[str]common_normcommon_binsFbool
cumulativediscretec                 C  s   g d}|  d| d S )N)r,   densitypercentprobability
proportion	frequencyr-   )Z_check_param_one_of)r    Zstat_optionsr#   r#   r$   __post_init__v   s    zHist.__post_init__c                 C  sz   |  }|du r$| |  }}n|\}}|rFt|d |d }	n0|durf|}
t|||
 |
}	nt||||}	|	S )z6Inner function that takes bin parameters as arguments.Ng      ?g      ?)r   minmaxnparangehistogram_bin_edges)r    valsweightr/   r0   r1   r6   startstop	bin_edgesstepr#   r#   r$   _define_bin_edges}   s    zHist._define_bin_edgesc                 C  s   || }| dd}| jp |dk}| ||| j| j| j|}t| jttfrvt	|d }|
 | f}	t||	d}
n
t|d}
|
S )z=Given data, return numpy.histogram parameters to define bins.rC   NZnominal   )r/   range)r/   )r   r6   rH   r/   r0   r1   
isinstancer   intr   r=   r>   dict)r    r   r   
scale_typerB   weightsr6   rF   n_bins	bin_rangebin_kwsr#   r#   r$   _define_bin_params   s    
zHist._define_bin_paramsc                 C  s    |  |||}||| j||S N)rS   apply_eval)r    r   r   r   rN   rR   r#   r#   r$   _get_bins_and_eval   s    zHist._get_bins_and_evalc                 C  sr   || }| dd }| jdk}tj|fi |||d\}}t|}	|d d |	d  }
t||
d|d|	iS )NrC   r7   )rO   r7      r,   space)r   r-   r?   	histogramdiffpdr   )r    r   r   rR   rB   rO   r7   histedgeswidthcenterr#   r#   r$   rV      s    
 
z
Hist._evalc                 C  s   |d }| j dks| j dkr0|t|  }n>| j dkrR|t|  d }n| j dkrn|t|d  }| jr| j dv r||d   }n| }|jf i | j |iS )	Nr,   r9   r:   r8   d   r;   rZ   )r7   r;   )r-   astypefloatsumr5   cumsumassign)r    r   r^   r#   r#   r$   
_normalize   s    


zHist._normalizer   r   r   r   c                   s  || j j } fdd|D }|r0| jdu rR| |||} || j||}n| jdu rft|}n\t| j}t| jt| }	|	r| j j d}
d	dd |	D }d	|
 d
| d}t
| ||| j| |}|r| jdu r| |}n~| jdu r|}nZ| j}t| jt| }	|	r\| j j d}
d	dd |	D }d	|
 d
| d}t
| t||| j}ddd| }|jf i ||| j iS )Nc                   s   g | ]}| j v rt|qS r#   )orderr   ).0vr   r#   r$   
<listcomp>       z!Hist.__call__.<locals>.<listcomp>TFz.common_binsz, c                 s  s   | ]}|V  qd S rT   r#   rj   r   r#   r#   r$   	<genexpr>   rn   z Hist.__call__.<locals>.<genexpr>z"Undefined variables(s) passed to `z`: .z.common_normc                 s  s   | ]}|V  qd S rT   r#   ro   r#   r#   r$   rp      rn   r   r   r   )	__class__r&   lowerr3   rS   rU   rV   r   setjoinr   rW   r2   rh   rg   r-   )r    r   r   r   r   rN   grouping_varsrR   Zbin_groupby	undefinedparamnamesmsgZnorm_grouperotherr#   rl   r$   r%      s>    


zHist.__call__)r&   r'   r(   r)   r-   r*   r/   r0   r1   r2   r3   r5   r6   r<   rH   rS   rW   rV   rh   r%   r#   r#   r#   r$   r+   2   s    
9r+   )
__future__r   dataclassesr   warningsr   typingr   numpyr?   pandasr]   r   Zseaborn._core.groupbyr   Zseaborn._core.scalesr   Zseaborn._stats.baser	   r
   Znumpy.typingr   r   r+   r#   r#   r#   r$   <module>   s    