Ë
    u™ãj0  ã                  óÜ   — d dl mZ d dlmZmZmZ d dlZd dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZmZ erd dlmZ d d	lmZ d d
lmZmZ d dlmZ  G d„ d«      Z G d„ d«      Z G d„ d«      Zy)é    )Úannotations)ÚTYPE_CHECKINGÚLiteralÚcastN)ÚPandas4Warning)Úcache_readonly)Úfind_stack_level)Ú
is_integerÚis_list_like)ÚIterable)ÚPositionalIndexer)Ú	DataFrameÚSeries)Úgroupbyc                  óv   — e Zd ZdZedd„«       Z	 	 	 	 dd„Zdd„Zdd„Zdd„Z	dd„Z
edd„«       Zedd	„«       Zy
)ÚGroupByIndexingMixinz<
    Mixin for adding ._positional_selector to GroupBy.
    c                óV   — t         rt        d| «      }t        |«      S | }t        |«      S )aÌ
  
        Return positional selection for each group.

        ``groupby._positional_selector[i:j]`` is similar to
        ``groupby.apply(lambda x: x.iloc[i:j])``
        but much faster and preserves the original index and order.

        ``_positional_selector[]`` is compatible with and extends :meth:`~GroupBy.head`
        and :meth:`~GroupBy.tail`. For example:

        - ``head(5)``
        - ``_positional_selector[5:-5]``
        - ``tail(5)``

        together return all the rows.

        Allowed inputs for the index are:

        - An integer valued iterable, e.g. ``range(2, 4)``.
        - A comma separated list of integers and slices, e.g. ``5``, ``2, 4``, ``2:4``.

        The output format is the same as :meth:`~GroupBy.head` and
        :meth:`~GroupBy.tail`, namely
        a subset of the ``DataFrame`` or ``Series`` with the index and order preserved.

        Returns
        -------
        Series
            The filtered subset of the original Series.
        DataFrame
            The filtered subset of the original DataFrame.

        See Also
        --------
        DataFrame.iloc : Purely integer-location based indexing for selection by
            position.
        GroupBy.head : Return first n rows of each group.
        GroupBy.tail : Return last n rows of each group.
        GroupBy.nth : Take the nth row from each group if n is an int, or a
            subset of rows, if n is a list of ints.

        Notes
        -----
        - The slice step cannot be negative.
        - If the index specification results in overlaps, the item is not duplicated.
        - If the index specification changes the order of items, then
          they are returned in their original order.
          By contrast, ``DataFrame.iloc`` can change the row order.
        - ``groupby()`` parameters such as as_index and dropna are ignored.

        The differences between ``_positional_selector[]`` and :meth:`~GroupBy.nth`
        with ``as_index=False`` are:

        - Input to ``_positional_selector`` can include
          one or more slices whereas ``nth``
          just handles an integer or a list of integers.
        - ``_positional_selector`` can  accept a slice relative to the
          last row of each group.
        - ``_positional_selector`` does not have an equivalent to the
          ``nth()`` ``dropna`` parameter.

        Examples
        --------
        >>> df = pd.DataFrame(
        ...     [["a", 1], ["a", 2], ["a", 3], ["b", 4], ["b", 5]], columns=["A", "B"]
        ... )
        >>> df.groupby("A")._positional_selector[1:2]
           A  B
        1  a  2
        4  b  5

        >>> df.groupby("A")._positional_selector[1, -1]
           A  B
        1  a  2
        2  a  3
        4  b  5
        úgroupby.GroupBy)r   r   ÚGroupByPositionalSelector©ÚselfÚgroupby_selfs     úg/var/www/html/python-recuperauto-other/env/lib/python3.12/site-packages/pandas/core/groupby/indexing.pyÚ_positional_selectorz)GroupByIndexingMixin._positional_selector&   s4   € õ^ ÜÐ 1°4Ó8ˆLô )¨Ó6Ð6ð  ˆLä(¨Ó6Ð6ó    c                óü  — t        |«      rTt        d„ t        d|«      D «       «      r| j                  t        d|«      «      }n}| j	                  t        d|«      «      }nat        |t        «      r| j                  |«      }n?t        |«      r| j                  t        d|«      «      }nt        dt        |«      › d�«      ‚t        |t        «      r!|r| j                  dk\  }n| j                  dk  }t        d	|«      S )
Nc              3  ó2   K  — | ]  }t        |«      –— Œ y ­w©N)r
   )Ú.0Úis     r   ú	<genexpr>zJGroupByIndexingMixin._make_mask_from_positional_indexer.<locals>.<genexpr>�   s   è ø€ Ò@ Q”:˜a—=Ñ@ùs   ‚r   úIterable[int]ÚtupleÚintzInvalid index zE. Must be integer, list-like, slice or a tuple of integers and slicesr   ú
np.ndarray)r   Úallr   Ú_make_mask_from_listÚ_make_mask_from_tupleÚ
isinstanceÚsliceÚ_make_mask_from_slicer
   Ú_make_mask_from_intÚ	TypeErrorÚtypeÚboolÚ_ascending_count©r   ÚargÚmasks      r   Ú"_make_mask_from_positional_indexerz7GroupByIndexingMixin._make_mask_from_positional_indexer|   så   € ô ˜ÔÜÑ@¬$¨z¸3Ó*?Ô@Ô@Ø×0Ñ0´°oÀsÓ1KÓL‘à×1Ñ1´$°wÀÓ2DÓE‘ä˜œUÔ#Ø×-Ñ-¨cÓ2‰DÜ˜Œ_Ø×+Ñ+¬D°¸Ó,<Ó=‰DäØ ¤ c£ ð ,&ð &óð ô �dœDÔ!ÙØ×,Ñ,°Ñ1‘à×,Ñ,¨qÑ0�ä�L $Ó'Ð'r   c                óP   — |dk\  r| j                   |k(  S | j                  | dz
  k(  S )Nr   é   )r0   Ú_descending_count)r   r2   s     r   r,   z(GroupByIndexingMixin._make_mask_from_int™   s1   € Ø�!Š8Ø×(Ñ(¨CÑ/Ð/à×)Ñ)¨s¨d°Q©hÑ7Ð7r   c                ó  — |D �cg c]
  }|dk\  sŒ	|‘Œ }}|D �cg c]  }|dk  sŒ	| dz
  ‘Œ }}d}|r#|t        j                  | j                  |«      z  }|r#|t        j                  | j                  |«      z  }|S c c}w c c}w )Nr   r6   F)ÚnpÚisinr0   r7   )r   Úargsr2   ÚpositiveÚnegativer3   s         r   r'   z)GroupByIndexingMixin._make_mask_from_listŸ   sˆ   € Ø#'Ö4˜C¨3°!«8’CÐ4ˆÐ4Ø(,Ö8 °°a³�S�D˜1“HÐ8ˆÐ8à"'ˆáØ”B—G‘G˜D×1Ñ1°8Ó<Ñ<ˆDáØ”B—G‘G˜D×2Ñ2°HÓ=Ñ=ˆDàˆùò 5ùÚ8s   …
A=�A=š
B¥Bc                óä   — d}|D ]h  }t        |«      r|| j                  t        d|«      «      z  }Œ-t        |t        «      r|| j                  |«      z  }ŒRt        dt        |«      › d�«      ‚ |S )NFr$   zInvalid argument z. Should be int or slice.)r
   r,   r   r)   r*   r+   Ú
ValueErrorr.   )r   r;   r3   r2   s       r   r(   z*GroupByIndexingMixin._make_mask_from_tuple­   s}   € Ø"'ˆàò 	ˆCÜ˜#ŒØ˜×0Ñ0´°e¸SÓ1AÓBÑB‘Ü˜C¤Ô'Ø˜×2Ñ2°3Ó7Ñ7‘ä Ø'¬¨S«	 {Ð2KÐLóð ð	ð ˆr   c                ól  — |j                   }|j                  }|j                  }|�|dk  rt        d|› d�«      ‚d}|€d}|€|dkD  r¾|| j                  |z  dk(  z  }n¨|dk\  r0|| j                  |k\  z  }|dkD  rŒ|| j                  |z
  |z  dk(  z  }ns|| j
                  | k  z  }| j
                  |z   dz   }| j                  | j
                  z   |dz   z   dk  }t        j                  || j                  |«      }|||z  dk(  z  }|�,|dk\  r|| j                  |k  z  }|S || j
                  | k\  z  }|S )Nr   zInvalid step z. Must be non-negativeTr6   )ÚstartÚstopÚstepr?   r0   r7   r9   Úwhere)r   r2   rA   rB   rC   r3   Úoffset_arrayÚlimit_arrays           r   r+   z*GroupByIndexingMixin._make_mask_from_slice¼   s  € Ø—	‘	ˆØ�x‰xˆØ�x‰xˆàÐ  q¢Ü˜}¨T¨FÐ2HÐIÓJÐJà"&ˆàˆ<ØˆDàˆ=Ø�aŠxØ˜×-Ñ-°Ñ4¸Ñ9Ñ9‘à�aŠZØ�D×)Ñ)¨UÑ2Ñ2ˆDà�aŠxØ˜×.Ñ.°Ñ6¸$Ñ>À!ÑCÑC‘ð �D×*Ñ*¨e¨VÑ3Ñ3ˆDà×1Ñ1°EÑ9¸AÑ=ˆLà×%Ñ%¨×(>Ñ(>Ñ>À%È!Á)ÑLØñˆKô Ÿ8™8 K°×1FÑ1FÈÓUˆLà�L 4Ñ'¨1Ñ,Ñ,ˆDàÐØ�qŠyØ˜×-Ñ-°Ñ4Ñ4�ð ˆð ˜×.Ñ.°4°%Ñ7Ñ7�àˆr   c                ój   — t         rt        d| «      }|j                  «       S | }|j                  «       S )Nr   ©r   r   Ú_cumcount_arrayr   s     r   r0   z%GroupByIndexingMixin._ascending_countæ   s9   € åÜÐ 1°4Ó8ˆLð ×+Ñ+Ó-Ð-ð  ˆLà×+Ñ+Ó-Ð-r   c                óP   — t         rt        d| «      }n| }|j                  d¬«      S )Nr   F)Ú	ascendingrH   r   s     r   r7   z&GroupByIndexingMixin._descending_countï   s+   € åÜÐ 1°4Ó8‰LàˆLà×+Ñ+°eÐ+Ó<Ð<r   N)Úreturnr   )r2   úPositionalIndexer | tuplerL   r%   )r2   r$   rL   r%   )r;   r"   rL   úbool | np.ndarray)r;   r#   rL   rN   )r2   r*   rL   rN   )rL   r%   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r4   r,   r'   r(   r+   r0   r7   © r   r   r   r   !   sr   „ ñð òS7ó ðS7ðj(à&ð(ð 
ó(ó:8óóó(ðT ò.ó ð.ð ò=ó ñ=r   r   c                  ó    — e Zd ZdZdd„Zdd„Zy)r   aÔ	  
    Return positional selection for each group.

    ``groupby._positional_selector[i:j]`` is similar to
    ``groupby.apply(lambda x: x.iloc[i:j])``
    but much faster and preserves the original index and order.

    ``_positional_selector[]`` is compatible with and extends :meth:`~GroupBy.head`
    and :meth:`~GroupBy.tail`. For example:

    - ``head(5)``
    - ``_positional_selector[5:-5]``
    - ``tail(5)``

    together return all the rows.

    Allowed inputs for the index are:

    - An integer valued iterable, e.g. ``range(2, 4)``.
    - A comma separated list of integers and slices, e.g. ``5``, ``2, 4``, ``2:4``.

    The output format is the same as :meth:`~GroupBy.head` and
    :meth:`~GroupBy.tail`, namely
    a subset of the ``DataFrame`` or ``Series`` with the index and order preserved.

    Returns
    -------
    Series
        The filtered subset of the original Series.
    DataFrame
        The filtered subset of the original DataFrame.

    See Also
    --------
    DataFrame.iloc : Purely integer-location based indexing for selection by
        position.
    GroupBy.head : Return first n rows of each group.
    GroupBy.tail : Return last n rows of each group.
    GroupBy.nth : Take the nth row from each group if n is an int, or a
        subset of rows, if n is a list of ints.

    Notes
    -----
    - The slice step cannot be negative.
    - If the index specification results in overlaps, the item is not duplicated.
    - If the index specification changes the order of items, then
      they are returned in their original order.
      By contrast, ``DataFrame.iloc`` can change the row order.
    - ``groupby()`` parameters such as as_index and dropna are ignored.

    The differences between ``_positional_selector[]`` and :meth:`~GroupBy.nth`
    with ``as_index=False`` are:

    - Input to ``_positional_selector`` can include
      one or more slices whereas ``nth``
      just handles an integer or a list of integers.
    - ``_positional_selector`` can  accept a slice relative to the
      last row of each group.
    - ``_positional_selector`` does not have an equivalent to the
      ``nth()`` ``dropna`` parameter.

    Examples
    --------
    >>> df = pd.DataFrame(
    ...     [["a", 1], ["a", 2], ["a", 3], ["b", 4], ["b", 5]], columns=["A", "B"]
    ... )
    >>> df.groupby("A")._positional_selector[1:2]
       A  B
    1  a  2
    4  b  5

    >>> df.groupby("A")._positional_selector[1, -1]
       A  B
    1  a  2
    2  a  3
    4  b  5
    c                ó   — || _         y r   ©Úgroupby_object©r   rW   s     r   Ú__init__z"GroupByPositionalSelector.__init__H  ó
   € Ø,ˆÕr   c                ón   — | j                   j                  |«      }| j                   j                  |«      S )a  
        Select by positional index per group.

        Implements GroupBy._positional_selector

        Parameters
        ----------
        arg : PositionalIndexer | tuple
            Allowed values are:
            - int
            - int valued iterable such as list or range
            - slice with step either None or positive
            - tuple of integers and slices

        Returns
        -------
        Series
            The filtered subset of the original groupby Series.
        DataFrame
            The filtered subset of the original groupby DataFrame.

        See Also
        --------
        DataFrame.iloc : Integer-location based indexing for selection by position.
        GroupBy.head : Return first n rows of each group.
        GroupBy.tail : Return last n rows of each group.
        GroupBy._positional_selector : Return positional selection for each group.
        GroupBy.nth : Take the nth row from each group if n is an int, or a
            subset of rows, if n is a list of ints.
        )rW   r4   Ú_mask_selected_objr1   s      r   Ú__getitem__z%GroupByPositionalSelector.__getitem__K  s1   € ð> ×"Ñ"×EÑEÀcÓJˆØ×"Ñ"×5Ñ5°dÓ;Ð;r   N©rW   r   rL   ÚNone)r2   rM   rL   úDataFrame | Series)rO   rP   rQ   rR   rY   r]   rS   r   r   r   r   ù   s   „ ñLó\-ô <r   r   c                  ó6   — e Zd ZdZdd„Z	 d	 	 	 	 	 dd„Zd	d„Zy)
ÚGroupByNthSelectorzO
    Dynamically substituted for GroupBy.nth to enable both call and index
    c                ó   — || _         y r   rV   rX   s     r   rY   zGroupByNthSelector.__init__s  rZ   r   Nc                ó:   — | j                   j                  ||«      S r   )rW   Ú_nth)r   ÚnÚdropnas      r   Ú__call__zGroupByNthSelector.__call__v  s   € ð
 ×"Ñ"×'Ñ'¨¨6Ó2Ð2r   c                ó€   — t        j                  dt        t        «       ¬«       | j                  j                  |«      S )NzoGroupBy.nth[...] is deprecated and will be removed in a future version of pandas. Use GroupBy.nth(...) instead.)Ú
stacklevel)ÚwarningsÚwarnr   r	   rW   re   )r   rf   s     r   r]   zGroupByNthSelector.__getitem__}  s5   € Ü�‰ð?äÜ'Ó)õ		
ð ×"Ñ"×'Ñ'¨Ó*Ð*r   r^   r   )rf   rM   rg   zLiteral['any', 'all'] | NonerL   r`   )rf   rM   rL   r`   )rO   rP   rQ   rR   rY   rh   r]   rS   r   r   rb   rb   n  s7   „ ñó-ð 04ð3à$ð3ð -ð3ð 
ó	3ô+r   rb   )Ú
__future__r   Útypingr   r   r   rk   Únumpyr9   Úpandas.errorsr   Úpandas.util._decoratorsr   Úpandas.util._exceptionsr	   Úpandas.core.dtypes.commonr
   r   Úcollections.abcr   Úpandas._typingr   Úpandasr   r   Úpandas.core.groupbyr   r   r   rb   rS   r   r   ú<module>rx      sa   ðÝ "÷ñ ó
 ã å (Ý 2Ý 4÷ñ
 Ý(å0÷õ ,÷U=ñ U=÷pr<ñ r<÷j+ò +r   