ó
    Ñ]jí$  ã                  óô   • S SK Jr  S SKJr  S SKJrJrJr  S SKr	S SK
JrJr  S SKJrJr  \(       a  S SKJr  S SKJrJr  S S	KJr   " S
 S5      r\" \R0                  5       " S S5      5       r " S S5      rg)é    )Úannotations)ÚIterable)ÚTYPE_CHECKINGÚLiteralÚcastN)Úcache_readonlyÚdoc)Ú
is_integerÚis_list_like)ÚPositionalIndexer)Ú	DataFrameÚSeries)Úgroupbyc                  óŽ   • \ rS rSrSr\SS j5       r    SS jrSS jrSS jr	SS jr
SS jr\SS	 j5       r\SS
 j5       rSrg)ÚGroupByIndexingMixiné    z4
Mixin for adding ._positional_selector to GroupBy.
c                óh   • [         (       a  [        [        R                  U 5      nOU n[	        U5      $ )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
)r   r   r   ÚGroupByÚGroupByPositionalSelector©ÚselfÚgroupby_selfs     ÚY/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pandas/core/groupby/indexing.pyÚ_positional_selectorÚ)GroupByIndexingMixin._positional_selector%   s*   € ÷^ Š=Ü¤§¡°Ó6‰LàˆLä(¨Ó6Ð6ó    c                ó‚  • [        U5      (       al  [        S [        [        U5       5       5      (       a'  U R	                  [        [        [
           U5      5      nO�U R                  [        [        U5      5      nOo[        U[        5      (       a  U R                  U5      nOH[        U5      (       a   U R                  [        [
        U5      5      nO[        S[        U5       S35      e[        U[        5      (       a&  U(       a  U R                   S:¬  nOU R                   S:  n[        ["        R$                  U5      $ )Nc              3  ó8   #   • U  H  n[        U5      v •  M     g 7f©N)r
   )Ú.0Úis     r   Ú	<genexpr>ÚJGroupByIndexingMixin._make_mask_from_positional_indexer.<locals>.<genexpr>€   s   é € Ð>Ò*= Q”:˜a—=�=Ò*=ùs   ‚zInvalid index zE. Must be integer, list-like, slice or a tuple of integers and slicesr   )r   Úallr   r   Ú_make_mask_from_listÚintÚ_make_mask_from_tupleÚtupleÚ
isinstanceÚsliceÚ_make_mask_from_slicer
   Ú_make_mask_from_intÚ	TypeErrorÚtypeÚboolÚ_ascending_countÚnpÚndarray©r   ÚargÚmasks      r   Ú"_make_mask_from_positional_indexerÚ7GroupByIndexingMixin._make_mask_from_positional_indexer{   sú   € ô ˜×ÑÜÑ>¬$¬x¸Ô*=Ó>×>Ñ>Ø×0Ñ0´´h¼s±mÀSÓ1IÓJ‘à×1Ñ1´$´u¸cÓ2BÓC‘ä˜œU×#Ñ#Ø×-Ñ-¨cÓ2‰DÜ˜�_‰_Ø×+Ñ+¬D´°c«NÓ;‰DäØ ¤ c£ ð ,&ð &óð ô �dœD×!Ñ!ÞØ×,Ñ,°Ñ1‘à×,Ñ,¨qÑ0�ä”B—J‘J Ó%Ð%r   c                óR   • US:¼  a  U R                   U:H  $ U R                  U* S-
  :H  $ )Nr   é   )r0   Ú_descending_count)r   r4   s     r   r,   Ú(GroupByIndexingMixin._make_mask_from_int˜   s1   € Ø�!‹8Ø×(Ñ(¨CÑ/Ð/à×)Ñ)¨s¨d°Q©hÑ7Ð7r   c                ó6  • U Vs/ s H  o"S:¼  d  M
  UPM     nnU Vs/ s H  o"S:  d  M
  U* S-
  PM     nnSnU(       a$  U[         R                  " U R                  U5      -  nU(       a$  U[         R                  " U R                  U5      -  nU$ s  snf s  snf )Nr   r9   F)r1   Úisinr0   r:   )r   Úargsr4   ÚpositiveÚnegativer5   s         r   r%   Ú)GroupByIndexingMixin._make_mask_from_listž   sˆ   € Ù#'Ó4¢4˜C°!©8—C¡4ˆÐ4Ù(,Ó8ª °a±“H�S�D˜1”H©ˆÐ8à"'ˆæØ”B—G’G˜D×1Ñ1°8Ó<Ñ<ˆDæØ”B—G’G˜D×2Ñ2°HÓ=Ñ=ˆDàˆùò 5ùÚ8s   …	B’Bž	B«
Bc                ó  • SnU Hv  n[        U5      (       a#  X R                  [        [        U5      5      -  nM6  [	        U[
        5      (       a  X R                  U5      -  nM`  [        S[        U5       S35      e   U$ )NFzInvalid argument z. Should be int or slice.)	r
   r,   r   r&   r)   r*   r+   Ú
ValueErrorr.   )r   r>   r5   r4   s       r   r'   Ú*GroupByIndexingMixin._make_mask_from_tuple¬   sx   € Ø"'ˆãˆCÜ˜#�‰Ø×0Ñ0´´c¸3³Ó@Ñ@’Ü˜C¤×'Ñ'Ø×2Ñ2°3Ó7Ñ7’ä Ø'¬¨S«	 {Ð2KÐLóð ñ ð ˆr   c                óp  • UR                   nUR                  nUR                  nUb  US:  a  [        SU S35      eSnUc  SnUc  US:”  a  XPR                  U-  S:H  -  nO¦US:¼  a/  XPR                  U:¬  -  nUS:”  a  XPR                  U-
  U-  S:H  -  nOqXPR
                  U* :  -  nU R
                  U-   S-   nU R                  U R
                  -   US-   -   S:  n[        R                  " XpR                  U5      nXVU-  S:H  -  nUb+  US:¼  a  XPR                  U:  -  nU$ XPR
                  U* :¬  -  nU$ )Nr   zInvalid step z. Must be non-negativeTr9   )ÚstartÚstopÚsteprC   r0   r:   r1   Úwhere)r   r4   rF   rG   rH   r5   Úoffset_arrayÚlimit_arrays           r   r+   Ú*GroupByIndexingMixin._make_mask_from_slice»   sq  € Ø—	‘	ˆØ�x‰xˆØ�x‰xˆàÑ  q£Ü˜}¨T¨FÐ2HÐIÓJÐJà"&ˆà‰<ØˆDà‰=Ø�a‹xØ×-Ñ-°Ñ4¸Ñ9Ñ9�øà�a‹ZØ×)Ñ)¨UÑ2Ñ2ˆDà�a‹xØ×.Ñ.°Ñ6¸$Ñ>À!ÑCÑC�øð ×*Ñ*¨e¨VÑ3Ñ3ˆDà×1Ñ1°EÑ9¸AÑ=ˆLà×%Ñ%¨×(>Ñ(>Ñ>À%È!Á)ÑLØñˆKô Ÿ8š8 K×1FÑ1FÈÓUˆLà 4Ñ'¨1Ñ,Ñ,ˆDàÑØ�q‹yØ×-Ñ-°Ñ4Ñ4�ð ˆð ×.Ñ.°4°%Ñ7Ñ7�àˆr   c                ó�   • [         (       a*  [        [        R                  U 5      nUR	                  5       $ U nUR	                  5       $ r   ©r   r   r   r   Ú_cumcount_arrayr   s     r   r0   Ú%GroupByIndexingMixin._ascending_countå   s>   € çŠ=Ü¤§¡°Ó6ˆLð ×+Ñ+Ó-Ð-ð  ˆLà×+Ñ+Ó-Ð-r   c                óp   • [         (       a  [        [        R                  U 5      nOU nUR	                  SS9$ )NF)Ú	ascendingrN   r   s     r   r:   Ú&GroupByIndexingMixin._descending_countî   s0   € çŠ=Ü¤§¡°Ó6‰LàˆLà×+Ñ+°eÐ+Ð<Ð<r   © N)Úreturnr   )r4   úPositionalIndexer | tuplerU   ú
np.ndarray)r4   r&   rU   rW   )r>   zIterable[int]rU   úbool | np.ndarray)r>   r(   rU   rX   )r4   r*   rU   rX   )rU   rW   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r6   r,   r%   r'   r+   r0   r:   Ú__static_attributes__rT   r   r   r   r       sr   † ñð óS7ó ðS7ðj&à&ð&ð 
ô&ô:8ôôô(ðT ó.ó ð.ð ó=ó ó=r   r   c                  ó(   • \ rS rSrSS jrSS jrSrg)r   éø   c                ó   • Xl         g r   ©Úgroupby_object©r   rc   s     r   Ú__init__Ú"GroupByPositionalSelector.__init__ú   ó   € Ø,Õr   c                ón   • U R                   R                  U5      nU R                   R                  U5      $ )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.
)rc   r6   Ú_mask_selected_objr3   s      r   Ú__getitem__Ú%GroupByPositionalSelector.__getitem__ý   s1   € ð> ×"Ñ"×EÑEÀcÓJˆØ×"Ñ"×5Ñ5°dÓ;Ð;r   rb   N©rc   zgroupby.GroupByrU   ÚNone)r4   rV   rU   úDataFrame | Series)rY   rZ   r[   r\   re   rj   r^   rT   r   r   r   r   ø   s   † ô-÷ <r   r   c                  óF   • \ rS rSrSrSS jr S	     S
S jjrSS jrSrg)ÚGroupByNthSelectori   zG
Dynamically substituted for GroupBy.nth to enable both call and index
c                ó   • Xl         g r   rb   rd   s     r   re   ÚGroupByNthSelector.__init__%  rg   r   Nc                ó8   • U R                   R                  X5      $ r   ©rc   Ú_nth)r   ÚnÚdropnas      r   Ú__call__ÚGroupByNthSelector.__call__(  s   € ð
 ×"Ñ"×'Ñ'¨Ó2Ð2r   c                ó8   • U R                   R                  U5      $ r   rt   )r   rv   s     r   rj   ÚGroupByNthSelector.__getitem__/  s   € Ø×"Ñ"×'Ñ'¨Ó*Ð*r   rb   rl   r   )rv   rV   rw   zLiteral['any', 'all'] | NonerU   rn   )rv   rV   rU   rn   )	rY   rZ   r[   r\   r]   re   rx   rj   r^   rT   r   r   rp   rp      s7   † ñô-ð 04ð3à$ð3ð -ð3ð 
õ	3÷+r   rp   )Ú
__future__r   Úcollections.abcr   Útypingr   r   r   Únumpyr1   Úpandas.util._decoratorsr   r	   Úpandas.core.dtypes.commonr
   r   Úpandas._typingr   Úpandasr   r   Úpandas.core.groupbyr   r   r   r   rp   rT   r   r   Ú<module>r…      ss   ðÝ "å $÷ñ ó ÷÷
ö
 Ý0÷õ ,÷U=ñ U=ñp Ð×.Ñ.Ó/÷$<ð $<ó 0ð$<÷N+ò +r   