
    Pi                       d Z ddlmZ ddlmZm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mZ dd	lmZmZmZmZ dd
lmZ ddlmZ ddlmZmZ ddlmc m Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 erddl1m2Z2m3Z3 ddl4m5Z5m6Z6m7Z7 ddl8m9Z9  ed           G d d                      Z:e G d d                      Z;	 	 	 	 	 	 d+d,d&Z<d-d'Z=d.d*Z>dS )/z]
Provide user facing operators for doing the split part of the
split-apply-combine paradigm.
    )annotations)TYPE_CHECKINGfinalN)algos)OutOfBoundsDatetime)InvalidIndexError)cache_readonly
set_module)ensure_int64ensure_platform_intis_list_like	is_scalar)CategoricalDtype)
algorithms)CategoricalExtensionArray)	DataFrame)ops)recode_for_groupby)Index
MultiIndexdefault_index)Series)
PrettyDictpprint_thing)HashableIterator)	ArrayLikeNDFrameTnpt)NDFramepandasc                       e Zd ZU dZded<   ded<   ded<   dZded	<    fd
Z	 	 	 	 	 dddZ	 dd dZ	 d!ddd"dZ	e
d#d            Z xZS )$GrouperaJ  
    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 parameter is given, a level of the index of the target
    object.

    If ``level`` is passed as a keyword to both `Grouper` and
    `groupby`, the values passed to `Grouper` take precedence.

    Parameters
    ----------
    *args
        Currently unused, reserved for future use.
    **kwargs
        Dictionary of the keyword arguments to pass to Grouper.

    Attributes
    ----------
    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 :ref:`here<timeseries.offset_aliases>`.
    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

    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.

    See Also
    --------
    Series.groupby : Apply a function groupby to a Series.
    DataFrame.groupby : Apply a function groupby.

    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_grouper)keylevelfreqr&   r'   ztuple[str, ...]_attributesc                    |                     d          ddlm} |} t                                          |           S )Nr,   r   )TimeGrouper)getpandas.core.resampler/   super__new__)clsargskwargsr/   	__class__s       o/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/groupby/grouper.pyr3   zGrouper.__new__  sB    ::f)888888Cwws###    NFTreturnNonec                    || _         || _        || _        || _        || _        d | _        d | _        d | _        d | _        d S N)	r*   r+   r,   r&   r'   _indexer_deprecatedbinnerr)   _indexer)selfr*   r+   r,   r&   r'   s         r8   __init__zGrouper.__init__  sH     
		@D 59r9   objr   validateobserved tuple[ops.BaseGrouper, NDFrameT]c           	         |                      |          \  }}}t          || j        g| j        | j        || j        |          \  }}}||fS )a  
        Parameters
        ----------
        obj : Series or DataFrame
            Object being grouped.
        validate : bool, default True
            If True, validate the grouper.
        observed : bool, default True
            Whether only observed groups should be in the result. Only
            has an impact when grouping on categorical data.

        Returns
        -------
        A tuple of grouper, obj (possibly sorted)
        )r+   r&   rD   r'   rE   )_set_grouperget_grouperr*   r+   r&   r'   )rA   rC   rD   rE   _groupers         r8   _get_grouperzGrouper._get_grouper"  sb    $ %%c**	Q%XJ*;
 
 
C |r9   )	gpr_indexrM   3tuple[NDFrameT, Index, npt.NDArray[np.intp] | None]c               2   |J | j         | j        t          d          | j        || _        | j        | _        | j         | j         }t          |dd          |k    rt          |t                    r~| j        J | j        N| j        	                                }| j        
                    |          }|
                    |j                  }n| j        
                    |j                  }n||j        vrt          d| d          t          ||         |          }n|j        }| j        | j        }t          |t                    rE|                    |          }t          |                    |          |j        |                   }n|d|j        fvrt          d| d	          d}	| j        s|rV|j        sO|j        	                    d
d          x}	| _        |
                    |	          }|
                    |	d          }|||	fS )a  
        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rP   r   z
The level z is not valid	mergesortfirst)kindna_positionaxis)r*   r+   
ValueErrorr)   r>   r@   getattr
isinstancer   argsorttakeindex
_info_axisKeyErrorr   r   _get_level_number_get_level_valuesnamesrP   r&   is_monotonic_increasingarray)
rA   rC   r&   rM   r*   reverse_indexerunsorted_axaxr+   indexers
             r8   rH   zGrouper._set_grouperA  sD   ( 8DJ$:QRRR = %DM 4DM 8(Cy&$//366:c6;R;R6
 }000=,&*m&;&;&=&=O"&-"4"4_"E"EK$))#)44BB++CI66BBcn,,"#Is#I#I#IJJJ3s8#... Bz%
 b*-- H0077Er33E::%QQQBB1bg,..$%F%%F%F%FGGG 04I 	, 	,r'A 	, 241A1A g 2B 2 2 Gd. !!B((7(++CBr9   strc                      fd j         D             }d                    |          }t                     j        }| d| dS )Nc              3  b   K   | ])}t          |          | dt          |          V  *d S )N=)rY   ).0	attr_namerA   s     r8   	<genexpr>z#Grouper.__repr__.<locals>.<genexpr>  sW       
 
tY''3 777433773333
 
r9   z, ())r-   jointype__name__)rA   
attrs_listattrscls_names   `   r8   __repr__zGrouper.__repr__  sf    
 
 
 
!-
 
 


 		*%%::&%%U%%%%r9   )NNNFT)r&   r%   r'   r%   r:   r;   )TT)rC   r   rD   r%   rE   r%   r:   rF   )F)rC   r   r&   r%   rM   r(   r:   rN   r:   ri   )rt   
__module____qualname____doc____annotations__r-   r3   rB   rL   rH   r   rx   __classcell__)r7   s   @r8   r$   r$   E   s        y yv JJJLLL#MKMMMM$ $ $ $ $ : : : : :( FJ    @ +0M NRM  M  M  M  M  M ^ & & & U& & & & &r9   r$   c                  h   e Zd ZU dZdZded<   ded<   ded<   	 	 	 	 	 	 	 	 d/d0dZd1dZd2dZe	d3d            Z
e	d4d            Ze	d5d             Zed6d"            Ze	d7d$            Zed8d&            Zed9d(            Ze	d:d*            Ze	d;d,            Zed<d-            Ze	d<d.            ZdS )=Groupingah  
    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_codesr(   
_orig_catsr   _indexTFr]   rC   NDFrame | Noner&   r%   rE   in_axisr'   uniquesArrayLike | Noner:   r;   c
                   t          |t                    r|                    d          }|| _        || _        t          ||          }
d | _        || _        || _        || _	        || _
        || _        || _        |	| _        | j        }|Lt          |t                    r|                    |          }n|}|
|}
n|
}|                    |          }
njt          |
t$                    r|| j	        J |
                    | j	        d          \  }}|| _	        t          |t(          j                  r|}
n|j        d         j        }t1          ||j        j        d          }
nt          |
t          t0          t6          t8          j        f          st=          |
dd          dk    r/t?          tA          |
                    }tC          d| d	          |                    |
          }
tE          |
d
          r tG          |
          tG          |          k    s#tI          |
          }d| }tK          |          t          |
t8          j                  r0|
j&        j'        dv r!t          |
          (                                }
nAt          t=          |
dd           tR                    r|
j*        | _        tW          |
||          }
|
| _        d S )NF)deep)rD   r   rP   copyndim   Grouper for '' not 1-dimensional__len__z9Grouper result violates len(labels) == len(data)
result: mMdtype),rZ   r   r   r+   _orig_grouper_convert_grouperr   r   _sortrC   	_observedr   _dropna_uniques_ilevelr   get_level_valuesmapr$   rL   r   
BinGrouper	groupingsgrouping_vectorr   result_indexrP   r   npndarrayrY   ri   rs   rX   hasattrlenr   AssertionErrorr   rT   to_numpyr   
categoriesr   )rA   r]   rK   rC   r+   r&   rE   r   r'   r   r   ilevelindex_levelmapper
newgroupernewobjngtgrpererrmsgs                       r8   rB   zGrouping.__init__  s    gv&& 	/lll..G
$*5'::
!
  %,, $#44V<<#&"-("-//&"9"9 11 *	-
 8'''!0!=!=dhQV!=!W!WJDH*cn55  #-  )!,<"'Z49# # # fe^RZH
 
 	- 22a77_--.. !G!G!G!GHHH#ii88O 33-((CJJ66$_55XQVXX  %V,,,orz22 
	R$)T11
 #)"9"9"B"B"D"D$??AQRR 	R-8DO0$QQO.r9   ri   c                    d| j          dS )Nz	Grouping(rq   rQ   rA   s    r8   rx   zGrouping.__repr__+  s    '49''''r9   r   c                *    t          | j                  S r=   )iterindicesr   s    r8   __iter__zGrouping.__iter__.  s    DL!!!r9   c                X    t          | j        dd           }t          |t                    S )Nr   )rY   r   rZ   r   )rA   r   s     r8   _passed_categoricalzGrouping._passed_categorical1  s'    ,gt<<%!1222r9   r   c                B   | j         }|| j        j        |         S t          | j        t
          t          f          r| j        j        S t          | j        t          j
                  r| j        j        j        S t          | j        t
                    r| j        j        S d S r=   )r   r   rb   rZ   r   r   r   rP   r   r   BaseGrouperr   )rA   r   s     r8   rP   zGrouping.name6  s    ;$V,,d(5&/:: 	-%**,co>> 	-'499,e44 	-',, tr9   
int | Nonec                    | j         }|dS t          |t                    s=| j        }||j        vrt          d| d          |j                            |          S |S )zS
        If necessary, converted index level name to index level position.
        NzLevel z not in index)r+   rZ   intr   rb   r   r]   )rA   r+   r]   s      r8   r   zGrouping._ilevelH  sp    
 
=4%%% 	,KEEK''$%Be%B%B%BCCC;$$U+++r9   r   c                *    t          | j                  S r=   )r   r   r   s    r8   ngroupszGrouping.ngroupsW  s    4<   r9   $dict[Hashable, npt.NDArray[np.intp]]c                    t          | j        t          j                  r| j        j        S t          | j                  }|                                S r=   )rZ   r   r   r   r   r   _reverse_indexer)rA   valuess     r8   r   zGrouping.indices[  sI     d*CO<< 	0'//T122&&(((r9   npt.NDArray[np.signedinteger]c                    | j         d         S )Nr   _codes_and_uniquesr   s    r8   codeszGrouping.codesd      &q))r9   r   c                    | j         d         S )Nr   r   r   s    r8   r   zGrouping.uniquesh  r   r9   /tuple[npt.NDArray[np.signedinteger], ArrayLike]c                (   | j         rp| j        }|j        }| j        rAt	          j        |j                  }||dk             }| j        rt          j	        |          }n!t          j
        t          |                    }d}| j        s|                                }t          j        |          rdd}| j        rt          |          }n5|                                }t	          j        |j        d |                   }t          j        ||d          }t%          j        |||j        d          }|j        }	|r:| j        st          j        |	|k    |	dz   |	          }	t          j        |||	          }	|	|fS t-          | j        t.          j                  r| j        j        }	| j        j        j        }nZ| j        *t%          | j        | j                  }|j        }	| j        }n)t	          j        | j        | j        | j                  \  }	}|	|fS )NFT)r   r   orderedrD   r   )r   )r&   use_na_sentinel)r   r   r   r   r   unique1dr   r   r   r&   aranger   r   isnaanyargmaxnunique_intsinsertr   
from_codesr   whererZ   r   r   
codes_infor   _valuesr   	factorize)
rA   catr   ucodeshas_dropped_nana_maskna_codena_idxr   r   s
             r8   r   zGrouping._codes_and_uniquesl  s    # ;	 &CJ~ 4#,SY77"-: -WV__F3z??33"N< <((**6'?? 
<%)Nz N"%j// ")!1!1","9#)GVG:L"M"MYvw;;F!,S[SX  G IE :z IHUg%5uqy%HHE'599'>!,co>> 	(3E*7?GG]& d2t}MMMCIEmGG
 (1$4:t|  NE7 g~r9   dict[Hashable, Index]c                     j         \  }}t          j        | j        d          }t	          j        t          |          t          |                    \  }t          |          	                                }fdt          ||dd          d          D             } fdt          ||d          D             }t          |          S )NFr   c              3  2   K   | ]\  }}||         V  d S r=    )rm   startendrs      r8   ro   z"Grouping.groups.<locals>.<genexpr>  s/      XXJE31U3Y<XXXXXXr9   r   strictc                L    i | ] \  }}|j                             |          !S r   )r   r\   )rm   kvrA   s      r8   
<dictcomp>z#Grouping.groups.<locals>.<dictcomp>  s/    XXXTQ!T[%%a((XXXr9   T)r   r   _with_inferrP   libalgosgroupsort_indexerr   r   r   cumsumzipr   )rA   r   r   counts_resultresultr   s   `     @r8   groupszGrouping.groups  s    0w#G$)%HHH./B5/I/I3w<<XX	6f%%,,..XXXX#ffQRRjQV2W2W2WXXXXXXXS'RV5W5W5WXXX&!!!r9   c                "    | j         r| S | j        S r=   )r   _observed_groupingr   s    r8   observed_groupingzGrouping.observed_grouping  s    > 	K&&r9   c                    t          | j        | j        | j        | j        | j        d| j        | j        | j        	  	        }|S )NT)rC   r+   r&   rE   r   r'   r   )	r   r   r   rC   r+   r   r   r   r   )rA   groupings     r8   r   zGrouping._observed_grouping  sI    K*L<M

 

 

 r9   )NNNTFFTN)r]   r   rC   r   r&   r%   rE   r%   r   r%   r'   r%   r   r   r:   r;   ry   )r:   r   r:   r%   )r:   r   )r:   r   )r:   r   )r:   r   )r:   r   )r:   r   )r:   r   )r:   r   )r:   r   )rt   rz   r{   r|   r   r}   rB   rx   r   r	   r   rP   r   propertyr   r   r   r   r   r   r   r   r   r9   r8   r   r     s         @ 48F7777MMM
 "$(g/ g/ g/ g/ g/R( ( ( (" " " " 3 3 3 ^3    ^"    ^ ! ! ! X! ) ) ) ^) * * * X* * * * X* > > > ^>@ 
" 
" 
" ^
" ' ' ' X'    ^  r9   r   TFrC   r   r&   r%   rE   rD   r'   r:   5tuple[ops.BaseGrouper, frozenset[Hashable], NDFrameT]c                f
     j         }|t          |t                    rSt          |          rt	          |          dk    r|d         }|&t          |          r|                    |          }d}nt          |          rBt	          |          }|dk    r	|d         }n$|dk    rt          d          t          d          t          |t                    r$ j         j	        |k    rt          d| d          n|dk    s|dk     rt          d	          d}|}t          |t                    rK|                     d
|          \  }	 |j        |	t                       fS |	t          |j        h           fS t          |t          j                  r|t                       fS t          |t                     s|g}
d
}n"|}
t	          |
          t	          |          k    }t#          d |
D                       }t#          d |
D                       }t#          d |
D                       }|s|s|s~|r||zt           t$                    rt'           fd|
D                       }n2t           t(                    sJ t'           fd|
D                       }|st+          j        |
          g}
t          |t.          t           f          r|dgt	          |          z  }
|}n|gt	          |
          z  }g }t1                      }d fd}d fd}t3          |
|d          D ]L\  }} ||          rd}|                    |j	                   n ||          r j        dk    r]| v rY|r                     |d           d| |         }}}|j        dk    rt          d| d          |                    |           nh                     |d          rd
|d}}}nJt=          |          t          |t                    r$|j        |                    |j                   d}nd
}t          |t>                    st?          || |||||          n|}|                     |           Nt	          |          dk    rt	                     rt          d          t	          |          dk    rN|                     t?          tC          d          tE          j#        g tD          j$                                       t          j        ||||          }	|	t          |           fS )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 level,sort, while
    the passed in 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 indexr   z2level > 0 or level < -1 only valid with MultiIndexF)rD   rE   c              3  ^   K   | ](}t          |          pt          |t                    V  )d S r=   )callablerZ   dictrm   gs     r8   ro   zget_grouper.<locals>.<genexpr>2  s7      HHax{{9jD&9&9HHHHHHr9   c              3  N   K   | ] }t          |t          t          f          V  !d S r=   )rZ   r$   r   r  s     r8   ro   zget_grouper.<locals>.<genexpr>3  s1      HHaz!gx%899HHHHHHr9   c           	   3  |   K   | ]7}t          |t          t          t          t          t
          j        f          V  8d S r=   )rZ   listtupler   r   r   r   r  s     r8   ro   zget_grouper.<locals>.<genexpr>4  sJ        DE
1tUFE2:>??     r9   c              3  F   K   | ]}|j         v p|j        j        v V  d S r=   )columnsr]   rb   rm   r  rC   s     r8   ro   zget_grouper.<locals>.<genexpr>A  sI       ' '=>S[ 8A$8' ' ' ' ' 'r9   c              3  4   K   | ]}|j         j        v V  d S r=   )r]   rb   r  s     r8   ro   zget_grouper.<locals>.<genexpr>F  s,      &J&JqCIO';&J&J&J&J&J&Jr9   r:   r%   c                    t          |           sOj        dk    rdS j        d         }	 |                    |            n# t          t
          t          f$ r Y dS w xY wdS )Nr   Fr   T)_is_label_liker   axesget_locr_   	TypeErrorr   )r*   itemsrC   s     r8   
is_in_axiszget_grouper.<locals>.is_in_axisV  s{    c"" 
	x1}}u HRLEc""""i):;   uu ts   A AAc                &   t          | d          sdS 	 | j                 }n$# t          t          t          t
          f$ r Y dS w xY wt          | t                    r5t          |t                    r | j        	                    |j        d          S dS )NrP   Fr   )
r   rP   r_   
IndexErrorr   r   rZ   r   _mgrreferences_same_values)gprobj_gpr_columnrC   s     r8   	is_in_objzget_grouper.<locals>.is_in_objf  s    sF## 	5	 ]NN*&79LM 	 	 	55	c6"" 	Kz.&'I'I 	K822>3FJJJus   # AATr   rV   r   r   )rC   r+   r&   rE   r   r'   )r   )r&   r'   r   )%r]   rZ   r   r   r   r   r   rX   ri   rP   r$   rL   r*   	frozensetr   r   r  r   r   allr   comasarray_tuplesafer  setr   addr   _check_label_or_level_ambiguity_is_level_referencer_   r   appendr   r   rd   intp)rC   r*   r+   r&   rE   rD   r'   
group_axisnlevelsrK   keysmatch_axis_lengthany_callableany_groupersany_arraylikeall_in_columns_indexlevelsr   
exclusionsr  r  r  r   rP   pings   `                        r8   rI   rI     s#   > J  j*-- 	E"" !s5zzQa{y//{ 11%88 E"" Se**a<<!!HEE\\$%<===$%QRRR%%% W9>U**$%W5%W%W%WXXX +ebjj !UVVV EC #w 	%''eh'OO7?IKK,,Iswi00#55 
C	)	) %IKK$$c4   9u!IIZ8 HH4HHHHHLHH4HHHHHL  IM    M 11 1 	1
 Mc9%% 	K#& ' ' ' 'BF' ' ' $ $   c6*****#&&J&J&J&JT&J&J&J#J#J # 	1)$//0D%%'' %;6CJJ&D3t99$ "I #J            $t444 + +
U9S>> 	GNN38$$$$Z__ 	x1}} E77!7DDD%)3Cs8q== %%NT%N%N%NOOOt$$$$((1(55 $&+S$smm#W%% 	#'*=NN37###GGG c8,,H!	 	 	 	  	 	
9~~s3xx0111
9~~-"2"2BHRrw4O4O4OPPQQQ oj)$vNNNGIj))3..r9   c                `    t          | t          t          f          p| d uot          |           S r=   )rZ   ri   r  r   )vals    r8   r  r    s*    cC<((PS_-O3Pr9   rW   r   c                >   t          |t                    r|j        S t          |t                    r;|j                            |           r|j        S |                    |           j        S t          |t                    r|j        S t          |t          t          t          t          t          j        f          rat          |          t          |           k    rt!          d          t          |t          t          f          rt#          j        |          }|S |S )Nz$Grouper and axis must be same length)rZ   r  r0   r   r]   equalsr   reindexr   r  r  r   r   r   r   r   rX   r  r  )rW   rK   s     r8   r   r     s    '4   {	GV	$	$ =%% 	1?"??4((00	GZ	(	( 
	GdE5+rzJ	K	K w<<3t99$$CDDDge}-- 	5+G44Gr9   )NNTFTT)rC   r   r&   r%   rE   r%   rD   r%   r'   r%   r:   r   r   )rW   r   )?r|   
__future__r   typingr   r   numpyr   pandas._libsr   r   pandas._libs.tslibsr   pandas.errorsr   pandas.util._decoratorsr	   r
   pandas.core.dtypes.commonr   r   r   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   r   collections.abcr   r   pandas._typingr   r   r    pandas.core.genericr!   r$   r   rI   r  r   r   r9   r8   <module>rL     sv   
 # " " " " "       
          4 3 3 3 3 3 + + + + + +       
            7 6 6 6 6 6 " " " " " "        !                 ' ' ' ' ' ' # # # # # # > > > > > >         
 & % % % % %       
  ,       
          ,+++++ HS& S& S& S& S& S& S& S&l
 q q q q q q q ql	 	
V/ V/ V/ V/ V/rQ Q Q Q     r9   