
    eCi!!                        S SK Jr  S SKJr  S SKJr  S SKrS SKr	S SKJ
r
  S SKJr  S SKJr  S SKJr  S S	KJr  \(       a  S S
KJr  \ " S S\5      5       r\ " S S\5      5       rg)    )annotations)	dataclass)ClassVarN)	DataFrame)GroupBy)Scale)Stat)TYPE_CHECKING)	ArrayLikec                  F    \ rS rSr% SrSrS\S'             S	S jrSrg)
Count   z
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_orientc           	         SSS.U   nUR                  UR                  " S0 XQU   0D6U[        05      R                  SS/S9R	                  SS9nU$ )Nyxr   r   )subsetT)drop )aggassignlendropnareset_index)selfdatagroupbyorientscalesvarress          Q/home/james-whalen/.local/lib/python3.13/site-packages/seaborn/_stats/counting.py__call__Count.__call__"   sa     c"6*S3&\23c3Z@VC:V&[d[#	 	 
    r   N
r   r   r   r   r   strr    zdict[str, Scale]returnr   )	__name__
__module____qualname____firstlineno____doc__r   __annotations__r$   __static_attributes__r   r&   r#   r   r      s@     '+O^*(/9<FV	r&   r   c                      \ rS rSr% SrSrS\S'   SrS\S'   S	rS
\S'   S	r	S\S'   Sr
S\S'   SrS\S'   SrS\S'   SrS\S'   S rS rS rS rS rS r          SS jrSrg	)Hist0   a
  
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`.
    Note that if `binwidth` does not evenly divide the bin range, the actual
    bin width used will be only approximately equal to the parameter value.
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                0    / SQnU R                  SU5        g )N)r4   densitypercentprobability
proportion	frequencyr5   )_check_param_one_of)r   stat_optionss     r#   __post_init__Hist.__post_init__t   s    
 	  6r&   c                   UR                  [        R                  * [        R                  5      R                  [        R                  [        R                  5      R	                  5       nUc   UR                  5       UR                  5       pOUu  pxU(       a  [        R                  " US-
  US-   5      n	U	$ Ub  [        [        X-
  U-  5      5      n[        R                  " XXR5      n	U	$ )z6Inner function that takes bin parameters as arguments.g      ?g      ?)replacenpinfnanr   minmaxarangeintroundhistogram_bin_edges)
r   valsweightr7   r8   r9   r>   startstop	bin_edgess
             r#   _define_bin_edgesHist._define_bin_edges{   s    ||RVVGRVV,44RVVRVVDKKM((*dhhj4"KE		%"*dSj9I  #5$,(!:;<..t8LI r&   c                   X   nUR                  SS5      nU R                  =(       d    US:H  nU R                  XEU R                  U R                  U R
                  U5      n[        U R                  [        [        45      (       a9  [        U5      S-
  nUR                  5       UR                  5       4n	[        XS9n
U
$ [        US9n
U
$ )z=Given data, return numpy.histogram parameters to define bins.rU   Nnominal   )r7   range)r7   )getr>   rY   r7   r8   r9   
isinstancer(   rQ   r   rN   rO   dict)r   r   r   
scale_typerT   weightsr>   rX   n_bins	bin_rangebin_kwss              r#   _define_bin_paramsHist._define_bin_params   s    |((8T* ==;J)$;**499dmmT]]H
	 dii#s,,^a'F!8I8G  	*Gr&   c                ^    U R                  XU5      nUR                  XR                  X%5      $ )N)rg   apply_eval)r   r   r   r   rb   rf   s         r#   _get_bins_and_evalHist._get_bins_and_eval   s)    ))$
C}}T::v??r&   c                    X   nUR                  SS 5      nU R                  S:H  n[        R                  " U40 UDXVS.D6u  px[        R                  " U5      n	US S U	S-  -   n
[
        R                  " X*SUSU	05      $ )NrU   r@   )rc   r@      r4   space)r_   r5   rK   	histogramdiffpdr   )r   r   r   rf   rT   rc   r@   histedgeswidthcenters              r#   rk   
Hist._eval   s|    |((8T*))y(ll4U7UGUseai'||VWdGUKLLr&   c                .   US   nU R                   S:X  d  U R                   S:X  a'  UR                  [        5      UR                  5       -  nOeU R                   S:X  a*  UR                  [        5      UR                  5       -  S-  nO+U R                   S:X  a  UR                  [        5      US   -  nU R                  (       a6  U R                   S;   a  X!S   -  R                  5       nOUR                  5       nUR                  " S	0 U R                   U0D6$ )
Nr4   rB   rC   rA   d   rD   rq   )r@   rD   r   )r5   astypefloatsumr=   cumsumr   )r   r   ru   s      r#   
_normalizeHist._normalize   s    G}99%l)B;;u%
2DYY)#;;u%
2S8DYY+%;;u%W5D??yy44G},446{{}{{/dii.//r&   c                R   XC   R                   R                  R                  5       nU Vs/ s H  ofUR                  ;   d  M  [	        U5      PM!     nnU(       a  U R
                  SL a/  U R                  XU5      nUR                  XR                  X85      nO_U R
                  SL a  [        U5      n	O'[        U R
                  5      n	U R                  SU5        U	R                  XR                  X2U5      nU(       a  U R                  SL a  U R                  U5      nO]U R                  SL a  [        U5      n
O'[        U R                  5      n
U R                  SU5        U
R                  XR                  5      nSSS.U   nUR                  " S0 XU R                     0D6$ s  snf )	NTFr;   r:   r   r   r   r   )	__class__r*   lowerorderr(   r;   rg   rj   rk   r   _check_grouping_varsrl   r:   r   r   r5   )r   r   r   r   r    rb   vgrouping_varsrf   bin_groupbynorm_groupbyothers               r#   r$   Hist.__call__   sl    ^--66<<>
)-DAgmm1CQD 0 0D 8--dJGG==zz6CD5(%m4%d&6&67))-G$$--v
D  0 0D 8??4(D5(&}5&t'7'78))-G%%dOO<D$V,{{6e$))_5665 Es   F$F$r   r'   )r*   r+   r,   r-   r.   r5   r/   r7   r8   r9   r:   r;   r=   r>   rG   rY   rg   rl   rk   r   r$   r0   r   r&   r#   r2   r2   0   s    8r D#"(D
(!Hl!+/H(/$(K!($(K!(JHd7(,@
M0$77(/79<7FV7	7r&   r2   )
__future__r   dataclassesr   typingr   numpyrK   pandasrt   r   seaborn._core.groupbyr   seaborn._core.scalesr   seaborn._stats.baser	   r
   numpy.typingr   r   r2   r   r&   r#   <module>r      sb    " !     ) & $  & D  : w74 w7 w7r&   