o
    ŀg                     @  s  d Z ddlmZ ddlmZmZ ddlZddlZddl	m
Z
m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 ddl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!  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l0m1Z1 erddl2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z; G dd dZ<eG dd dZ=							d0d1d)d*Z>d2d+d,Z?d3d.d/Z@dS )4z]
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                      s   e Zd ZU dZded< ded< ded< ded< dZd	ed
<  fddZdddejddfd/ddZ		d0d1ddZ
	d2ddd3dd Zeed4d"d#Zeed$d% Zeed&d' Zeed(d) Zeed*d+ Zed5d-d.Z  ZS )6Groupera  
    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                   s*   | dd urddlm} |} t | S )Nr*   r   )TimeGrouper)getpandas.core.resampler-   super__new__)clsargskwargsr-   	__class__ O/var/www/html/myenv/lib/python3.10/site-packages/pandas/core/groupby/grouper.pyr1      s   zGrouper.__new__NFTr+   Axis | lib.NoDefaultreturnNonec                 C  s   t | tu r|tjurtjdtt d nd}|tju rd}|| _|| _	|| _
|| _|| _|| _d | _d | _d | _d | _d | _d | _d | _d S )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$   r7   r7   r8   __init__  s.   	


zGrouper.__init__objr   validate tuple[ops.BaseGrouper, NDFrameT]c              	   C  sF   |  |\}}}t|| jg| j| j| j|| jd\}}}|| _||fS )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#   rK   r$   )_set_grouperget_grouperr(   r+   r)   r#   r$   rC   )rH   rJ   rK   _grouperr7   r7   r8   _get_grouper,  s   zGrouper._get_grouper)	gpr_indexrR   3tuple[NDFrameT, Index, npt.NDArray[np.intp] | None]c          
      C  s  |dusJ | j dur| jdurtd| jdu r || _| j| _| j durq| j }t|dd|kr[t|tr[| jdus<J | jdurS| j	 }| j
|}|
|j}nR| j
|j}nJ||jvrhtd| dt|| |d}n4|| j}| jdur| j}t|tr||}t|||j| d}n|d|jfvrtd| d	d}	| js|r|js|jj	d
dd }	| _|
|	}|j
|	| j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rT   r   z
The level z is not valid	mergesortfirst)kindna_positionr+   )r(   r)   
ValueErrorr'   rD   rG   getattr
isinstancer   argsorttakeindex
_info_axisKeyErrorr   	_get_axisr+   r   _get_level_number_get_level_valuesnamesrT   r#   is_monotonic_increasingarrayrE   r&   )
rH   rJ   r#   rR   r(   reverse_indexerunsorted_axaxr)   indexerr7   r7   r8   rM   K  sH   









zGrouper._set_grouperr   c                 C  s8   t jt| j dtt d | j}|d u rtd|S )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)r@   rA   r>   __name__rB   r   r&   r[   )rH   r`   r7   r7   r8   rk     s   z
Grouper.axc                 C  $   t jt| j dtt d | jS )Nz^.indexer is deprecated and will be removed in a future version. Use Resampler.indexer instead.r<   )r@   rA   r>   rm   rB   r   rD   rH   r7   r7   r8   rl        zGrouper.indexerc                 C  rn   )NzX.obj is deprecated and will be removed in a future version. Use GroupBy.indexer instead.r<   )r@   rA   r>   rm   rB   r   rE   ro   r7   r7   r8   rJ     s   zGrouper.objc                 C  rn   )Nz\.grouper is deprecated and will be removed in a future version. Use GroupBy.grouper instead.r<   )r@   rA   r>   rm   rB   r   rC   ro   r7   r7   r8   rP     rp   zGrouper.grouperc                 C  s&   t jt| j dtt d | jjS )NzZ.groups is deprecated and will be removed in a future version. Use GroupBy.groups instead.r<   )r@   rA   r>   rm   rB   r   rC   groupsro   r7   r7   r8   rq     s   zGrouper.groupsstrc                   s8    fdd j D }d|}t j}| d| dS )Nc                 3  s6    | ]}t  |d ur| dtt  | V  qd S )N=)r\   repr).0	attr_namero   r7   r8   	<genexpr>  s    z#Grouper.__repr__.<locals>.<genexpr>z, ())r,   joinr>   rm   )rH   
attrs_listattrscls_namer7   ro   r8   __repr__  s   


zGrouper.__repr__)r+   r9   r#   r"   r$   r"   r:   r;   )T)rJ   r   rK   r"   r:   rL   )F)rJ   r   r#   r"   rR   r%   r:   rS   r:   r   r:   rr   )rm   
__module____qualname____doc____annotations__r,   r1   r   r?   rI   rQ   rM   r   propertyrk   rl   rJ   rP   rq   r~   __classcell__r7   r7   r5   r8   r!   B   sN   
  5	( T		
r!   c                   @  s*  e Zd ZU dZdZded< ded< ded< d	ed
< 								dEdFddZdGddZdHdd Ze	dId!d"Z
e	dJd$d%Ze	dKd'd(ZedLd*d+Ze	dMd-d.ZedNd0d1Ze	dOd3d4ZedOd5d6Ze	dPd7d8ZedPd9d:Ze	dPd;d<ZedPd=d>Ze	dQd@dAZe	dRdCdDZdS )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_codeszCategorical | None_all_grouperr%   
_orig_catsr   _indexTFr`   rJ   NDFrame | Noner#   r"   observedin_axisr$   uniquesArrayLike | Noner:   r;   c
                 C  s  || _ || _t||}
d | _d | _|| _|| _|| _|| _|| _	|| _
|	| _| j}|d urIt|tr8||}n|}|
d u rA|}
nx|
}||}
npt|
trz| jd usUJ |
j| jdd\}}|| _t|tjrk|}
nN|jd j}t||jjd}
n?t|
ttttjfst|
dddkrtt |
}t!d| d||
}
t"|
d	rt#|
t#|kst$|
}d
| }t%|t|
tjr|
j&j'dv rt|
( }
ntt|
dd t)r|
j*| _t+|
||\}
| _|
| _d S )NFrK   r   rU   ndim   Grouper for '' not 1-dimensional__len__z9Grouper result violates len(labels) == len(data)
result: mMdtype),r)   _orig_grouper_convert_grouperr   r   r   _sortrJ   	_observedr   _dropna_uniques_ilevelr]   r   get_level_valuesmapr!   rQ   r   
BinGrouper	groupingsgrouping_vectorr   result_indexrT   r   r   npndarrayr\   rr   r>   r[   hasattrlenr   AssertionErrorr   rX   to_numpyr   
categoriesr   )rH   r`   rP   rJ   r)   r#   r   r   r$   r   r   ilevelindex_levelmapper
newgroupernewobjngtgrpererrmsgr7   r7   r8   rI     sn   





zGrouping.__init__rr   c                 C  s   d| j  dS )Nz	Grouping(ry   rU   ro   r7   r7   r8   r~   x  s   zGrouping.__repr__r   c                 C  
   t | jS N)iterindicesro   r7   r7   r8   __iter__{  s   
zGrouping.__iter__c                 C  s   t | jdd }t|tS )Nr   )r\   r   r]   r   )rH   r   r7   r7   r8   _passed_categorical~  s   
zGrouping._passed_categoricalr   c                 C  sb   | j }|d ur| 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   rf   r]   r   r   r   rT   r   r   BaseGrouperr   )rH   r   r7   r7   r8   rT     s   
zGrouping.name
int | Nonec                 C  sL   | j }|du r	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)   r]   intr   rf   r   r`   )rH   r)   r`   r7   r7   r8   r     s   

zGrouping._ilevelr   c                 C  r   r   )r   _group_indexro   r7   r7   r8   ngroups     
zGrouping.ngroups$dict[Hashable, npt.NDArray[np.intp]]c                 C  s(   t | jtjr| jjS t| j}| S r   )r]   r   r   r   r   r   _reverse_indexer)rH   valuesr7   r7   r8   r     s   
zGrouping.indicesnpt.NDArray[np.signedinteger]c                 C  s
   | j d S )Nr   )_codes_and_uniquesro   r7   r7   r8   codes  r   zGrouping.codesr   c                 C  s*   | j dur	| jjS | jr| jjS | jd S )v
        Analogous to result_index, but holding an ArrayLike to ensure
        we can retain ExtensionDtypes.
        Nr   )r   _result_index_valuesr   r   r   ro   r7   r7   r8   _group_arraylike  s
   

zGrouping._group_arraylikec                 C     t jdtt d | jS )r   zOgroup_arraylike is deprecated and will be removed in a future version of pandascategoryr=   )r@   rA   rB   r   r   ro   r7   r7   r8   group_arraylike  s   zGrouping.group_arraylikec                 C  s4   | j d ur| j}t|tsJ | j}||S | jS r   )r   r   r]   r   r   set_categories)rH   	group_idxcatsr7   r7   r8   r     s   

zGrouping._result_indexc                 C  r   )NzLresult_index is deprecated and will be removed in a future version of pandasr   )r@   rA   rB   r   r   ro   r7   r7   r8   r        zGrouping.result_indexc                 C  s   | j \}}| js_| jr_t|tsJ | jr-|t|k r-tjt	
|jdg|jdd}n2t|dkr_| j}|jdk  }|j| dk r_t|jd | }t	|j|d}tj||jdd}tj|| jdS )NFr   r   rU   )r   r   r   r]   r   r   r   any
from_codesr   appendr   r   r   argmaxr   nunique_intsinsertr   _with_inferrT   )rH   r   r   catna_idxna_unique_idx	new_codesr7   r7   r8   r     s"   
zGrouping._group_indexc                 C  r   )NzKgroup_index is deprecated and will be removed in a future version of pandasr   )r@   rA   rB   r   r   ro   r7   r7   r8   group_index  r   zGrouping.group_index/tuple[npt.NDArray[np.signedinteger], ArrayLike]c           	      C  sp  | j r|| j}|j}| jr!t|j}||dk }| jr t	|}nt
t|}tj|||jdd}|j}| jso|dk }t|ro| jrPt|}t|||}n| }t|d | }t||k|d |}t|||}| jsx|| j}||fS t| jtjr| jj}| jjj}||fS | jd urt| j| jd}|j}| j}||fS tj| j| j| jd\}}||fS )Nr   F)r   r   orderedrK   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   r]   r   r   
codes_infor   r   r   	factorize)	rH   r   r   ucodesr   r   na_maskna_coder   r7   r7   r8   r   	  sP   





zGrouping._codes_and_uniquesdict[Hashable, np.ndarray]c                 C  s    t j| j| jdd}| j|S )NFr   )r   r   r   r   r   groupby)rH   r   r7   r7   r8   rq   H  s   zGrouping.groups)NNNTFFTN)r`   r   rJ   r   r#   r"   r   r"   r   r"   r$   r"   r   r   r:   r;   r   )r:   r   r:   r"   )r:   r   )r:   r   )r:   r   )r:   r   )r:   r   )r:   r   r   )r:   r   )r:   r   )rm   r   r   r   r   r   rI   r~   r   r
   r   rT   r   r   r   r   r   r   r   r   r   r   r   r   rq   r7   r7   r7   r8   r     sZ   
  
i
		>r   TFrJ   r   r+   r   r#   r"   r   rK   r$   r:   5tuple[ops.BaseGrouper, frozenset[Hashable], NDFrameT]c                   s    |}|durtt|tr,t|rt|dkr|d }|du r+t|r+||}d}nHt|rIt|}	|	dkr=|d }n|	dkrEtdtdt|trd  |j	|krctd| d 
| n|dksl|dk rptd	d}|}t|tr|j d
d\}
 |jdu r|
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 |D }tdd |D }tdd |D }|s|s|s|r|du rt trt fdd|D }nt tsJ t fdd|D }|st|g}t|ttfr&|du r#dgt| }|}n|gt| }g }t }d  fdd}d  fdd}t||D ]\}}||rWd}||j	 nd||r jdkr| v r|rq j||d d| | }}}|jdkrtd| d|| n, j||drd
|d}}}nt|t|tr|jdur||j d}nd
}t|t st || |||||dn|}|!| qEt|dkrt rtdt|dkr|!t t"g ddt#j$g t#j%d tj||||d}
|
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 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                 s  s"    | ]}t |pt|tV  qd S r   )callabler]   dictru   gr7   r7   r8   rw     s     zget_grouper.<locals>.<genexpr>c                 s  s    | ]
}t |ttfV  qd S r   )r]   r!   r   r   r7   r7   r8   rw     s    c                 s  s&    | ]}t |tttttjfV  qd S r   )r]   listtupler   r   r   r   r   r7   r7   r8   rw         
c                 3  s&    | ]}| j v p| jjv V  qd S r   )columnsr`   rf   r   rJ   r7   r8   rw     r   c                 3  s    | ]	}| j jv V  qd S r   )r`   rf   r   r   r7   r8   rw     s    r:   r"   c              
     sP   t | s& jdkrdS  jd }z||  W dS  tttfy%   Y dS w dS )Nr   Fr   T)_is_label_liker   axesget_locrb   	TypeErrorr	   )r(   itemsr   r7   r8   
is_in_axis  s   

zget_grouper.<locals>.is_in_axisc                   s   t | dsdS t st r7z | j }W n ttttfy"   Y dS w t| t	r5t|t	r5| j
|j
dS dS z|  | j u W S  ttttfyM   Y dS w )NrT   Fr   )r   r   r   rT   rb   
IndexErrorr	   r   r]   r   _mgrreferences_same_values)gprobj_gpr_columnr   r7   r8   	is_in_obj  s$   
zget_grouper.<locals>.is_in_objTrZ   r   r   )rJ   r)   r#   r   r   r$   r   )r   )r#   r$   r   )&rc   r]   r   r   r   r   r   r[   rr   rT   _get_axis_namer!   rQ   r(   	frozensetr   r   r   r   r   allr   comasarray_tuplesafer   setzipaddr   _check_label_or_level_ambiguity_is_level_referencerb   r   r   r   r   rh   intp)rJ   r(   r+   r)   r#   r   rK   r$   
group_axisnlevelsrP   keysmatch_axis_lengthany_callableany_groupersany_arraylikeall_in_columns_indexlevelsr   
exclusionsr   r  r  r   rT   pingr7   r   r8   rN   N  s   
 
	











$rN   c                 C  s   t | ttfp| d uot| S r   )r]   rr   r   r   )valr7   r7   r8   r   8  s   r   r   c                 C  s   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rIt|t| kr;tdt |t	t
frGt|}|S |S )Nz$Grouper and axis must be same length)r]   r   r.   r   r`   equalsr   reindexr   r   r   r   r   r   r   r   r[   r	  r
  )r+   rP   r7   r7   r8   r   <  s   



r   )Nr   NTFTT)rJ   r   r+   r   r#   r"   r   r"   rK   r"   r$   r"   r:   r   r   )r+   r   )Ar   
__future__r   typingr   r   r@   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   rN   r   r   r7   r7   r7   r8   <module>   sZ       )  i 
k