
    Mh                       S r SSKJr  SSKJrJr  SSKrSSKrSSK	J
r
J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  SSKJrJr  SSKJr  SSKJr  SSKJrJr  SSK J!s  J"r#  SSK$J%r%  SSK&J'r'  SSK(J)r)  SSK*J+r+J,r,J-r-  SSK.J/r/  SSK0J1r1  \(       a  SSK2J3r3J4r4  SSK5J6r6J7r7J8r8J9r9  SSK:J;r;   " S S5      r<\ " S S5      5       r=       S             S S jjr>S!S jr?S"S jr@g)#z]
Provide user facing operators for doing the split part of the
split-apply-combine paradigm.
    )annotations)TYPE_CHECKINGfinalN)using_copy_on_writewarn_copy_on_write)lib)OutOfBoundsDatetime)InvalidIndexError)cache_readonly)find_stack_level)is_list_like	is_scalar)CategoricalDtype)
algorithms)CategoricalExtensionArray)	DataFrame)ops)recode_for_groupby)CategoricalIndexIndex
MultiIndex)Series)pprint_thing)HashableIterator)	ArrayLikeAxisNDFrameTnpt)NDFramec                  z  ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   S	rS
\S'   U 4S jrSSS\R                  SS4       SS jjr
 S     SS jjr SSS.       SS jjjr\\S S j5       5       r\\S 5       5       r\\S 5       5       r\\S 5       5       r\\S 5       5       r\S!S j5       rSrU =r$ )"GrouperB   an  
A Grouper allows the user to specify a groupby instruction for an object.

This specification will select a column via the key parameter, or if the
level and/or axis parameters are given, a level of the index of the target
object.

If `axis` and/or `level` are passed as keywords to both `Grouper` and
`groupby`, the values passed to `Grouper` take precedence.

Parameters
----------
key : str, defaults to None
    Groupby key, which selects the grouping column of the target.
level : name/number, defaults to None
    The level for the target index.
freq : str / frequency object, defaults to None
    This will groupby the specified frequency if the target selection
    (via key or level) is a datetime-like object. For full specification
    of available frequencies, please see `here
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`_.
axis : str, int, defaults to 0
    Number/name of the axis.
sort : bool, default to False
    Whether to sort the resulting labels.
closed : {'left' or 'right'}
    Closed end of interval. Only when `freq` parameter is passed.
label : {'left' or 'right'}
    Interval boundary to use for labeling.
    Only when `freq` parameter is passed.
convention : {'start', 'end', 'e', 's'}
    If grouper is PeriodIndex and `freq` parameter is passed.

origin : Timestamp or str, default 'start_day'
    The timestamp on which to adjust the grouping. The timezone of origin must
    match the timezone of the index.
    If string, must be one of the following:

    - 'epoch': `origin` is 1970-01-01
    - 'start': `origin` is the first value of the timeseries
    - 'start_day': `origin` is the first day at midnight of the timeseries

    - 'end': `origin` is the last value of the timeseries
    - 'end_day': `origin` is the ceiling midnight of the last day

    .. versionadded:: 1.3.0

offset : Timedelta or str, default is None
    An offset timedelta added to the origin.

dropna : bool, default True
    If True, and if group keys contain NA values, NA values together with
    row/column will be dropped. If False, NA values will also be treated as
    the key in groups.

Returns
-------
Grouper or pandas.api.typing.TimeGrouper
    A TimeGrouper is returned if ``freq`` is not ``None``. Otherwise, a Grouper
    is returned.

Examples
--------
``df.groupby(pd.Grouper(key="Animal"))`` is equivalent to ``df.groupby('Animal')``

>>> df = pd.DataFrame(
...     {
...         "Animal": ["Falcon", "Parrot", "Falcon", "Falcon", "Parrot"],
...         "Speed": [100, 5, 200, 300, 15],
...     }
... )
>>> df
   Animal  Speed
0  Falcon    100
1  Parrot      5
2  Falcon    200
3  Falcon    300
4  Parrot     15
>>> df.groupby(pd.Grouper(key="Animal")).mean()
        Speed
Animal
Falcon  200.0
Parrot   10.0

Specify a resample operation on the column 'Publish date'

>>> df = pd.DataFrame(
...    {
...        "Publish date": [
...             pd.Timestamp("2000-01-02"),
...             pd.Timestamp("2000-01-02"),
...             pd.Timestamp("2000-01-09"),
...             pd.Timestamp("2000-01-16")
...         ],
...         "ID": [0, 1, 2, 3],
...         "Price": [10, 20, 30, 40]
...     }
... )
>>> df
  Publish date  ID  Price
0   2000-01-02   0     10
1   2000-01-02   1     20
2   2000-01-09   2     30
3   2000-01-16   3     40
>>> df.groupby(pd.Grouper(key="Publish date", freq="1W")).mean()
               ID  Price
Publish date
2000-01-02    0.5   15.0
2000-01-09    2.0   30.0
2000-01-16    3.0   40.0

If you want to adjust the start of the bins based on a fixed timestamp:

>>> start, end = '2000-10-01 23:30:00', '2000-10-02 00:30:00'
>>> rng = pd.date_range(start, end, freq='7min')
>>> ts = pd.Series(np.arange(len(rng)) * 3, index=rng)
>>> ts
2000-10-01 23:30:00     0
2000-10-01 23:37:00     3
2000-10-01 23:44:00     6
2000-10-01 23:51:00     9
2000-10-01 23:58:00    12
2000-10-02 00:05:00    15
2000-10-02 00:12:00    18
2000-10-02 00:19:00    21
2000-10-02 00:26:00    24
Freq: 7min, dtype: int64

>>> ts.groupby(pd.Grouper(freq='17min')).sum()
2000-10-01 23:14:00     0
2000-10-01 23:31:00     9
2000-10-01 23:48:00    21
2000-10-02 00:05:00    54
2000-10-02 00:22:00    24
Freq: 17min, dtype: int64

>>> ts.groupby(pd.Grouper(freq='17min', origin='epoch')).sum()
2000-10-01 23:18:00     0
2000-10-01 23:35:00    18
2000-10-01 23:52:00    27
2000-10-02 00:09:00    39
2000-10-02 00:26:00    24
Freq: 17min, dtype: int64

>>> ts.groupby(pd.Grouper(freq='17min', origin='2000-01-01')).sum()
2000-10-01 23:24:00     3
2000-10-01 23:41:00    15
2000-10-01 23:58:00    45
2000-10-02 00:15:00    45
Freq: 17min, dtype: int64

If you want to adjust the start of the bins with an `offset` Timedelta, the two
following lines are equivalent:

>>> ts.groupby(pd.Grouper(freq='17min', origin='start')).sum()
2000-10-01 23:30:00     9
2000-10-01 23:47:00    21
2000-10-02 00:04:00    54
2000-10-02 00:21:00    24
Freq: 17min, dtype: int64

>>> ts.groupby(pd.Grouper(freq='17min', offset='23h30min')).sum()
2000-10-01 23:30:00     9
2000-10-01 23:47:00    21
2000-10-02 00:04:00    54
2000-10-02 00:21:00    24
Freq: 17min, dtype: int64

To replace the use of the deprecated `base` argument, you can now use `offset`,
in this example it is equivalent to have `base=2`:

>>> ts.groupby(pd.Grouper(freq='17min', offset='2min')).sum()
2000-10-01 23:16:00     0
2000-10-01 23:33:00     9
2000-10-01 23:50:00    36
2000-10-02 00:07:00    39
2000-10-02 00:24:00    24
Freq: 17min, dtype: int64
boolsortdropnaIndex | None
_gpr_index_grouper)keylevelfreqaxisr&   r'   ztuple[str, ...]_attributesc                V   > UR                  S5      b  SSKJn  Un [        TU ]  U 5      $ )Nr-   r   )TimeGrouper)getpandas.core.resampler1   super__new__)clsargskwargsr1   	__class__s       M/var/www/html/env/lib/python3.13/site-packages/pandas/core/groupby/grouper.pyr5   Grouper.__new__   s)    ::f)8Cws##    NFTc                l   [        U 5      [        L a8  U[        R                  La#  [        R
                  " S[        [        5       S9  OSnU[        R                  L a  SnXl        X l	        X0l
        X@l        XPl        X`l        S U l        S U l        S U l        S U l        S U l        S U l        S U l        g )Nz~Grouper axis keyword is deprecated and will be removed in a future version. To group on axis=1, use obj.T.groupby(...) instead
stacklevelr   )typer#   r   
no_defaultwarningswarnFutureWarningr   r+   r,   r-   r.   r&   r'   _grouper_deprecated_indexer_deprecated_obj_deprecatedr)   binnerr*   _indexer)selfr+   r,   r-   r.   r&   r'   s          r:   __init__Grouper.__init__  s     : 3>>) "/1 3>>!D
			#' @D #59r<   c           
         U R                  U5      u  n  n[        UU R                  /U R                  U R                  U R
                  UU R                  S9u  pCnX@l        XA4$ )z
Parameters
----------
obj : Series or DataFrame
validate : bool, default True
    if True, validate the grouper

Returns
-------
a tuple of grouper, obj (possibly sorted)
)r.   r,   r&   validater'   )_set_grouperget_grouperr+   r.   r,   r&   r'   rE   )rJ   objrN   _groupers        r:   _get_grouperGrouper._get_grouper,  sc     %%c*	Q%XXJ**;;
C $+ |r<   )	gpr_indexc                  Uc   eU R                   b  U R                  b  [        S5      eU R                  c  X0l        U R                  U l        U R                   b  U R                   n[        USS5      U:X  a  [        U[        5      (       a  U R                  c   eU R
                  bQ  U R
                  R                  5       nU R                  R                  U5      nUR                  UR                  5      nOU R                  R                  UR                  5      nOXAR                  ;  a  [        SU S35      e[        X   US9nOUR                  U R                   5      nU R                  bz  U R                  n[        U["        5      (       a8  UR%                  U5      n[        UR'                  U5      UR(                  U   S9nO!USUR*                  4;  a  [        SU S	35      eSn	U R,                  (       d  U(       a[  UR.                  (       dJ  UR0                  R                  S
SS9=ol        UR                  U	5      nUR                  XR                   S9nXl        Xpl        XU	4$ )aG  
given an object and the specifications, setup the internal grouper
for this particular specification

Parameters
----------
obj : Series or DataFrame
sort : bool, default False
    whether the resulting grouper should be sorted
gpr_index : Index or None, default None

Returns
-------
NDFrame
Index
np.ndarray[np.intp] | None
Nz2The Grouper cannot specify both a key and a level!namezThe grouper name z is not foundrX   r   z
The level z is not valid	mergesortfirst)kindna_positionr.   )r+   r,   
ValueErrorr*   rF   rI   getattr
isinstancer   argsorttakeindex
_info_axisKeyErrorr   	_get_axisr.   r   _get_level_number_get_level_valuesnamesrX   r&   is_monotonic_increasingarrayrG   r)   )
rJ   rQ   r&   rV   r+   reverse_indexerunsorted_axaxr,   indexers
             r:   rO   Grouper._set_grouperK  s    ( 88DJJ$:QRR == %M 44DM 88((Cy&$/36:c6;R;R
 }}000==,&*mm&;&;&=O"&--"4"4_"EK$))#))4B++CII6Bnn,"%6se=#IJJ38#. tyy)Bzz%

 b*--007Er33E:%QB QL0(:eWM)JKK 04IIr'A'A 241A1A g 2B 2 G. !B((7(3C  #r<   c                    [         R                  " [        U 5      R                   S3[        [        5       S9  U R                  nUc  [        S5      eU$ )NzS.ax is deprecated and will be removed in a future version. Use Resampler.ax insteadr>   z1_set_grouper must be called before ax is accessed)rB   rC   r@   __name__rD   r   r)   r_   )rJ   rd   s     r:   ro   
Grouper.ax  sT     	Dz""# $7 7')		
 =PQQr<   c                    [         R                  " [        U 5      R                   S3[        [        5       S9  U R                  $ )Nz^.indexer is deprecated and will be removed in a future version. Use Resampler.indexer instead.r>   )rB   rC   r@   rs   rD   r   rF   rJ   s    r:   rp   Grouper.indexer  sC     	Dz""# $B B')		
 '''r<   c                    [         R                  " [        U 5      R                   S3[        [        5       S9  U R                  $ )NzX.obj is deprecated and will be removed in a future version. Use GroupBy.indexer instead.r>   )rB   rC   r@   rs   rD   r   rG   rv   s    r:   rQ   Grouper.obj  sC    
 	Dz""# $@ @')		
 ###r<   c                    [         R                  " [        U 5      R                   S3[        [        5       S9  U R                  $ )Nz\.grouper is deprecated and will be removed in a future version. Use GroupBy.grouper instead.r>   )rB   rC   r@   rs   rD   r   rE   rv   s    r:   rS   Grouper.grouper  sC     	Dz""# $@ @')		
 '''r<   c                    [         R                  " [        U 5      R                   S3[        [        5       S9  U R                  R                  $ )NzZ.groups is deprecated and will be removed in a future version. Use GroupBy.groups instead.r>   )rB   rC   r@   rs   rD   r   rE   groupsrv   s    r:   r}   Grouper.groups  sG     	Dz""# $? ?')		
 ''...r<   c                   ^  U 4S jT R                    5       nSR                  U5      n[        T 5      R                  nU SU S3$ )Nc           	   3  v   >#    U  H.  n[        TU5      c  M  U S[        [        TU5      5       3v   M0     g 7f)N=)r`   repr).0	attr_namerJ   s     r:   	<genexpr>#Grouper.__repr__.<locals>.<genexpr>  s<      
-	tY' <yk4i 89:;-s   9!9z, ())r/   joinr@   rs   )rJ   
attrs_listattrscls_names   `   r:   __repr__Grouper.__repr__  sJ    
!--


 		*%:&&1UG1%%r<   )r)   r*   rE   rI   rF   rG   r.   rH   r'   r-   r+   r,   r&   )r.   zAxis | lib.NoDefaultr&   r%   r'   r%   returnNone)T)rQ   r   rN   r%   r   z tuple[ops.BaseGrouper, NDFrameT])F)rQ   r   r&   r%   rV   r(   r   z3tuple[NDFrameT, Index, npt.NDArray[np.intp] | None]r   r   r   str)rs   
__module____qualname____firstlineno____doc____annotations__r/   r5   r   rA   rK   rT   rO   r   propertyro   rp   rQ   rS   r}   r   __static_attributes____classcell__)r9   s   @r:   r#   r#   B   ss   rh JL#UKU$ %(^^%:
 #%: %: %: 
%:P /3'+	)@ +0R NRR R #'R ?KR 	<R h 
  
 (  ( 	$  	$ (  ( /  / & &r<   r#   c                     \ rS rSr% SrSrS\S'   S\S'   S\S	'   S
\S'           S               SS jjrS S jrS!S jr	\
S"S j5       r\
S#S j5       r\
S$S j5       r\S%S j5       r\
S&S j5       r\S'S j5       r\
S(S j5       r\S(S j5       r\
S)S j5       r\S)S j5       r\
S)S j5       r\S)S j5       r\
S*S j5       r\
S+S j5       rSrg),Groupingi  a  
Holds the grouping information for a single key

Parameters
----------
index : Index
grouper :
obj : DataFrame or Series
name : Label
level :
observed : bool, default False
    If we are a Categorical, use the observed values
in_axis : if the Grouping is a column in self.obj and hence among
    Groupby.exclusions list
dropna : bool, default True
    Whether to drop NA groups.
uniques : Array-like, optional
    When specified, will be used for unique values. Enables including empty groups
    in the result for a BinGrouper. Must not contain duplicates.

Attributes
-------
indices : dict
    Mapping of {group -> index_list}
codes : ndarray
    Group codes
group_index : Index or None
    unique groups
groups : dict
    Mapping of {group -> label_list}
Nz$npt.NDArray[np.signedinteger] | None_codeszCategorical | None_all_grouperr(   
_orig_catsr   _indexc
                4   X@l         X l        [        X5      n
S U l        S U l        Xl        XPl        X0l        X`l        Xpl	        Xl
        Xl        U R                  nUbE  [        U[        5      (       a  UR                  U5      nOUnU
c  Un
GOmU
nUR!                  U5      n
GOX[        U
["        5      (       a  U R                  c   eU
R%                  U R                  SS9u  pXl        [        U[&        R(                  5      (       a  Un
OUR*                  S   R,                  n[/        UUR0                  R2                  S9n
O[        U
[4        [.        [6        [8        R:                  45      (       d  [=        U
SS5      S:w  a#  [?        [A        U
5      5      n[C        SU S35      eUR!                  U
5      n
[E        U
S	5      (       a  [G        U
5      [G        U5      :X  d  [I        U
5      nS
U 3n[K        U5      e[        U
[8        R:                  5      (       a4  U
RL                  RN                  S;   a  [5        U
5      RQ                  5       n
OD[        [=        U
SS 5      [R        5      (       a$  U
RT                  U l        [W        XU5      u  ol        Xl        g )NFrN   r   rY   ndim   Grouper for '' not 1-dimensional__len__z9Grouper result violates len(labels) == len(data)
result: mMdtype),r,   _orig_grouper_convert_grouperr   r   r   _sortrQ   	_observedin_axis_dropna_uniques_ilevelra   r   get_level_valuesmapr#   rT   r   
BinGrouper	groupingsgrouping_vectorr   result_indexrX   r   r   npndarrayr`   r   r@   r_   hasattrlenr   AssertionErrorr   r\   to_numpyr   
categoriesr   )rJ   rd   rS   rQ   r,   r&   observedr   r'   uniquesr   ilevelindex_levelmapper
newgroupernewobjngtgrpererrmsgs                       r:   rK   Grouping.__init__  sT    
$*5: 
!
  %,,#44V<#&"-("-//&"9 11
 88'''!0!=!=dhhQV!=!WJH*cnn55 #-  ))!,<<"'1H1H1M1M"Nfe^RZZH
 
 2a7_-. =3F!GHH#ii8O 33(CJ6$_5**/2  %V,,orzz22$$))T1
 #)"9"B"B"D$?AQRR-88DO1Cx2.O.  /r<   c                "    SU R                    S3$ )Nz	Grouping(r   rY   rv   s    r:   r   Grouping.__repr__x  s    499+Q''r<   c                ,    [        U R                  5      $ N)iterindicesrv   s    r:   __iter__Grouping.__iter__{  s    DLL!!r<   c                P    [        U R                  SS 5      n[        U[        5      $ )Nr   )r`   r   ra   r   )rJ   r   s     r:   _passed_categoricalGrouping._passed_categorical~  s$    ,,gt<%!122r<   c                   U R                   nUb  U R                  R                  U   $ [        U R                  [
        [        45      (       a  U R                  R                  $ [        U R                  [        R                  5      (       a   U R                  R                  R                  $ [        U R                  [
        5      (       a  U R                  R                  $ g r   )r   r   rj   ra   r   r   r   rX   r   r   BaseGrouperr   )rJ   r   s     r:   rX   Grouping.name  s    ;;$$V,,d((5&/::%%***,,coo>>''44999,,e44'',,, r<   c                    U R                   nUc  g[        U[        5      (       dE  U R                  nXR                  ;  a  [        SU S35      eUR                  R                  U5      $ U$ )zC
If necessary, converted index level name to index level position.
NzLevel z not in index)r,   ra   intr   rj   r   rd   )rJ   r,   rd   s      r:   r   Grouping._ilevel  sc    
 

=%%%KKEKK'$veWM%BCC;;$$U++r<   c                ,    [        U R                  5      $ r   )r   _group_indexrv   s    r:   ngroupsGrouping.ngroups  s    4$$%%r<   c                    [        U R                  [        R                  5      (       a  U R                  R                  $ [        U R                  5      nUR                  5       $ r   )ra   r   r   r   r   r   _reverse_indexer)rJ   valuess     r:   r   Grouping.indices  sL     d**COO<<''///T112&&((r<   c                     U R                   S   $ )Nr   )_codes_and_uniquesrv   s    r:   codesGrouping.codes  s    &&q))r<   c                    U R                   b  U R                  R                  $ U R                  (       a  U R                  R                  $ U R
                  S   $ )^
Analogous to result_index, but holding an ArrayLike to ensure
we can retain ExtensionDtypes.
r   )r   _result_index_valuesr   r   r   rv   s    r:   _group_arraylikeGrouping._group_arraylike  sN     (%%---%%$$,,,&&q))r<   c                ^    [         R                  " S[        [        5       S9  U R                  $ )r   zOgroup_arraylike is deprecated and will be removed in a future version of pandascategoryr?   )rB   rC   rD   r   r   rv   s    r:   group_arraylikeGrouping.group_arraylike  s,     	 "')		
 $$$r<   c                    U R                   b@  U R                  n[        U[        5      (       d   eU R                  nUR                  U5      $ U R                  $ r   )r   r   ra   r   r   set_categories)rJ   	group_idxcatss      r:   r   Grouping._result_index  sU     ())Ii)9::::??D++D11   r<   c                ^    [         R                  " S[        [        5       S9  U R                  $ )NzLresult_index is deprecated and will be removed in a future version of pandasr   )rB   rC   rD   r   r   rv   s    r:   r   Grouping.result_index  s*     "')		
 !!!r<   c                   U R                   u  pU R                  (       GdK  U R                  (       Ga9  [        U[        5      (       d   eU R
                  (       ab  U[        U5      :H  R                  5       (       aA  [        R                  " [        R                  " UR                  S/5      UR                  SS9nO[        U5      S:  a  U R                  nUR                  S:  R                  5       nUR                  U   S:  ad  [        R                   " UR                  S U 5      n[        R"                  " UR                  US5      n[        R                  " XbR                  SS9n[$        R&                  " X R(                  S9$ )NFr   r   rY   )r   r   r   ra   r   r   r   any
from_codesr   appendr   r   r   argmaxr   nunique_intsinsertr   _with_inferrX   )rJ   r   r   catna_idxna_unique_idx	new_codess          r:   r   Grouping._group_index  s%   00||| 8 8 8g{3333zzuG499;;%00IIgmmbT2G4F4FQV Ua**))a-//199V$q($.$;$;CIIgv<N$OM "		'-- KI)44!#5#5G   yy99r<   c                ^    [         R                  " S[        [        5       S9  U R                  $ )NzKgroup_index is deprecated and will be removed in a future version of pandasr   )rB   rC   rD   r   r   rv   s    r:   group_indexGrouping.group_index  s*     "')		
    r<   c                P   U R                   (       Ga  U R                  nUR                  nU R                  (       aO  [        R
                  " UR                  5      nX3S:g     nU R                  (       a  [        R                  " U5      nO[        R                  " [        U5      5      n[        R                  " X2UR                  SS9nUR                  nU R                  (       d  US:  n[        R                   " U5      (       a  U R                  (       a#  [        U5      n[        R"                  " XgU5      nO]UR%                  5       n[        R&                  " US U 5      n[        R"                  " XW:  US-   U5      n[        R"                  " XgU5      nU R                  (       d  UR)                  U R*                  5      nXT4$ [-        U R                  [.        R0                  5      (       a9  U R                  R2                  nU R                  R4                  R6                  nXT4$ U R8                  b9  [        U R                  U R8                  S9nUR                  nU R8                  nXT4$ [        R:                  " U R                  U R                  U R                  S9u  pTXT4$ )Nr   F)r   r   orderedrN   r   r   )r   )r&   use_na_sentinel)r   r   r   r   r   unique1dr   r   r   r&   aranger   r   r   r  r   r   wherer   r  reorder_categoriesr   ra   r   r   
codes_infor   r   r   	factorize)	rJ   r  r   ucodesr   r   na_maskna_coder  s	            r:   r   Grouping._codes_and_uniques	  s    ### &&CJ~~#,,SYY7"-::WWV_F3z?3!,,S[[SXG IIE<<!)66'??zz"%j/ "5 A ")!1","9"9%."I ")9519e L "5 A>>!44T__E>!,,coo>>((33E**77??G ~ ]]& d22t}}MCIIEmmG ~ (11$$4::t||NE ~r<   c                    [         R                  " U R                  U R                  SS9nU R                  R                  U5      $ )NFr   )r   r   r   r   r   groupby)rJ   r   s     r:   r}   Grouping.groupsH  s5    %%djj$2C2CeT{{""4((r<   )r   r   r   r   r   r   r   r   r   r   r,   rQ   )NNNTFFTN)rd   r   rQ   zNDFrame | Noner&   r%   r   r%   r   r%   r'   r%   r   zArrayLike | Noner   r   r   )r   r   r   r%   )r   r   )r   z
int | None)r   r   )r   z$dict[Hashable, npt.NDArray[np.intp]])r   znpt.NDArray[np.signedinteger])r   r   r   )r   z/tuple[npt.NDArray[np.signedinteger], ArrayLike])r   zdict[Hashable, np.ndarray])rs   r   r   r   r   r   r   rK   r   r   r   r   rX   r   r   r   r   r   r   r   r   r   r   r
  r   r}   r    r<   r:   r   r     s   @ 48F07$$M
 "$(g/g/ 	g/ g/ g/ g/ g/ "g/ 
g/R(" 3 3  "   & & ) ) * * * * % % 	! 	! " " : :, ! ! < <| ) )r<   r   c                
  ^  T R                  U5      nUGb  [        U[        5      (       aK  [        U5      (       a  [	        U5      S:X  a  US   nUc#  [        U5      (       a  UR                  U5      nSnO[        U5      (       a3  [	        U5      n	U	S:X  a  US   nOU	S:X  a  [        S5      e[        S5      e[        U[        5      (       a@  T R                  U5      R                  U:w  a   [        SU ST R                  U5       35      eOUS:  d  US:  a  [        S	5      eSnUn[        U[        5      (       aF  UR                  T S
S9u  n
m UR                  c  U
[        5       T 4$ U
[        UR                  15      T 4$ [        U[        R                   5      (       a  U[        5       T 4$ [        U["        5      (       d  U/nS
nOUn[	        U5      [	        U5      :H  n[%        S U 5       5      n[%        S U 5       5      n[%        S U 5       5      nU(       d  U(       d  U(       d  U(       ax  Ucu  [        T [&        5      (       a  [)        U 4S jU 5       5      nO,[        T [*        5      (       d   e[)        U 4S jU 5       5      nU(       d  [,        R.                  " U5      /n[        U[0        ["        45      (       a  Uc  S/[	        U5      -  nUnOU/[	        U5      -  n/ n[3        5       nSU 4S jjnSU 4S jjn[5        UU5       GHG  u  nnU" U5      (       a  SnUR7                  UR                  5        OU" U5      (       a  T R8                  S:w  aW  UT ;   aQ  U(       a  T R;                  UUS9  SUT U   nnnUR8                  S:w  a  [        SU S35      eUR7                  U5        OiT R=                  UUS9(       a  S
USnnnOM[?        U5      e[        U[        5      (       a+  UR                  b  UR7                  UR                  5        SnOS
n[        U[@        5      (       d  [A        UUT UUUUUS9OUnURC                  U5        GMJ     [	        U5      S:X  a  [	        T 5      (       a  [        S5      e[	        U5      S:X  aD  URC                  [A        [E        / SS9[F        RH                  " / [F        RJ                  S95      5        [        R                   " UUXGS9n
U
[        U5      T 4$ )a  
Create and return a BaseGrouper, which is an internal
mapping of how to create the grouper indexers.
This may be composed of multiple Grouping objects, indicating
multiple groupers

Groupers are ultimately index mappings. They can originate as:
index mappings, keys to columns, functions, or Groupers

Groupers enable local references to axis,level,sort, while
the passed in axis, level, and sort are 'global'.

This routine tries to figure out what the passing in references
are and then creates a Grouping for each one, combined into
a BaseGrouper.

If observed & we have a categorical grouper, only show the observed
values.

If validate, then check for key/level overlaps.

Nr   r   zNo group keys passed!z*multiple levels only valid with MultiIndexzlevel name z is not the name of the r   z2level > 0 or level < -1 only valid with MultiIndexFr   c              3  f   #    U  H'  n[        U5      =(       d    [        U[        5      v   M)     g 7fr   )callablera   dictr   gs     r:   r   get_grouper.<locals>.<genexpr>  s#     H4ax{9jD&994s   /1c              3  N   #    U  H  n[        U[        [        45      v   M     g 7fr   )ra   r#   r   r"  s     r:   r   r$    s     H4az!gx%8994s   #%c           	   3     #    U  H4  n[        U[        [        [        [        [
        R                  45      v   M6     g 7fr   )ra   listtupler   r   r   r   r"  s     r:   r   r$    s,      IMA
1tUFE2::>??s   <>c              3     >#    U  H3  oTR                   ;   =(       d    UTR                  R                  ;   v   M5     g 7fr   )columnsrd   rj   r   r#  rQ   s     r:   r   r$    s0      'BFQS[[ 8A$88$s   ;>c              3  T   >#    U  H  oTR                   R                  ;   v   M     g 7fr   )rd   rj   r+  s     r:   r   r$    s     &JTCIIOO';Ts   %(c                   > [        U 5      (       d3  TR                  S:X  a  gTR                  S   n UR                  U 5        gg! [        [
        [        4 a     gf = f)Nr   Fr   T)_is_label_liker   axesget_locrf   	TypeErrorr
   )r+   itemsrQ   s     r:   
is_in_axisget_grouper.<locals>.is_in_axis  s]    c""xx1} HHRLEc"
 	 i):; s   A AAc                  > [        U S5      (       d  g[        5       (       d  [        5       (       aa   TU R                     n[        U [        5      (       a;  [        U[        5      (       a&  U R                  R                  UR                  S5      $ g U TU R                     L $ ! [        [
        [        [        4 a     gf = f! [        [
        [        [        4 a     gf = f)NrX   Fr   )r   r   r   rX   rf   
IndexErrorr
   r	   ra   r   _mgrreferences_same_values)gprobj_gpr_columnrQ   s     r:   	is_in_objget_grouper.<locals>.is_in_obj  s    sF##  $6$8$8!$SXX #v&&:nf+M+Mxx66"''  		#chh-'' j*;=PQ  *&79LM 	 	s#   B% C %CCC"!C"Tr^   r   r   )rQ   r,   r&   r   r   r'   r   )r   )r&   r'   r  )&rg   ra   r   r   r   r   r   r_   r   rX   _get_axis_namer#   rT   r+   	frozensetr   r   r'  r   r   allr   comasarray_tuplesafer(  setzipaddr   _check_label_or_level_ambiguity_is_level_referencerf   r   r   r   r   rl   intp)rQ   r+   r.   r,   r&   r   rN   r'   
group_axisnlevelsrS   keysmatch_axis_lengthany_callableany_groupersany_arraylikeall_in_columns_indexlevelsr   
exclusionsr3  r;  r9  r   rX   pings   `                         r:   rP   rP   N  s   @ t$J  j*--E""s5zQa{y// 11%8 E""e*a<!!HE\$%<==$%QRR%%%==&++u4$%eW -""%"4"4T":!;=  5
 ebj !UVV EC #w''e'<77?IK,,Iswwi0#55 
C	)	)IK$$c4  u!IZ8 H4HHLH4HHL IM M Mc9%%#& 'BF' $  c6****#&&JT&J#J #))$/0D%%'';6CJ&D3t9$ "I #J 4 $'
US>>GNN388$__xx1}77$7G%)3Cs88q= %}TF:M%NOOt$((4(8&+S$sm#W%%#''*=NN377#GG c8,, !	  	 	W (Z 9~s3xx011
9~%%"8"((2RWW:UVW ooj)$NGIj)3..r<   c                h    [        U [        [        45      =(       d    U S L=(       a    [        U 5      $ r   )ra   r   r(  r   )vals    r:   r.  r.  8  s%    cC<(PS_-O3Pr<   c                V   [        U[        5      (       a  UR                  $ [        U[        5      (       aG  UR                  R                  U 5      (       a  UR                  $ UR                  U 5      R                  $ [        U[        5      (       a  UR                  $ [        U[        [        [        [        [        R                  45      (       aV  [        U5      [        U 5      :w  a  [!        S5      e[        U[        [        45      (       a  ["        R$                  " U5      nU$ U$ )Nz$Grouper and axis must be same length)ra   r!  r2   r   rd   equalsr   reindexr   r'  r(  r   r   r   r   r   r_   r@  rA  )r.   rS   s     r:   r   r   <  s    '4  {{	GV	$	$==%%??"??4(000	GZ	(	(	GdE5+rzzJ	K	Kw<3t9$CDDge}--++G4Gr<   )Nr   NTFTT)rQ   r   r.   r   r&   r%   r   r%   rN   r%   r'   r%   r   z5tuple[ops.BaseGrouper, frozenset[Hashable], NDFrameT]r  )r.   r   )Ar   
__future__r   typingr   r   rB   numpyr   pandas._configr   r   pandas._libsr   pandas._libs.tslibsr	   pandas.errorsr
   pandas.util._decoratorsr   pandas.util._exceptionsr   pandas.core.dtypes.commonr   r   pandas.core.dtypes.dtypesr   pandas.corer   pandas.core.arraysr   r   pandas.core.commoncorecommonr@  pandas.core.framer   pandas.core.groupbyr   pandas.core.groupby.categoricalr   pandas.core.indexes.apir   r   r   pandas.core.seriesr   pandas.io.formats.printingr   collections.abcr   r   pandas._typingr   r   r   r    pandas.core.genericr!   r#   r   rP   r.  r   r  r<   r:   <module>rq     s   #  
  3 + 2 4 7 " !   ' # > 
 & 3
  ,c& c&L b) b) b)N 	
g/	g/ g/
 g/ g/ g/ g/ ;g/TQr<   