Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/pandas/core/groupby/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/pandas/core/groupby/__pycache__/indexing.cpython-312.pyc

�

Mٜg&%����ddlmZddlmZddlmZmZmZddlZ	ddl
mZmZddl
mZmZerddlmZddlmZmZdd	lmZGd
�d�Zeej0�Gd�d
��ZGd�d�Zy)�)�annotations)�Iterable)�
TYPE_CHECKING�Literal�castN)�cache_readonly�doc)�
is_integer�is_list_like)�PositionalIndexer)�	DataFrame�Series)�groupbyc�v�eZdZdZedd��Z				dd�Zd
d�Zdd�Zdd�Z	dd�Z
edd��Zedd	��Zy
)�GroupByIndexingMixinz<
    Mixin for adding ._positional_selector to GroupBy.
    c�r�tr%ttj|�}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
        )rrr�GroupBy�GroupByPositionalSelector��self�groupby_selfs  �G/usr/local/lib/python3.12/site-packages/pandas/core/groupby/indexing.py�_positional_selectorz)GroupByIndexingMixin._positional_selector%s7��\������6�L�)��6�6� �L�(��6�6�c�F�t|�rgtd�tt|�D��r'|j	ttt
|��}n�|j
tt|��}net|t�r|j|�}nCt|�r |jtt
|��}ntdt|��d���t|t�r!|r|j dk\}n|j dk}tt"j$|�S)Nc3�2K�|]}t|����y�w�N)r
)�.0�is  r�	<genexpr>zJGroupByIndexingMixin._make_mask_from_positional_indexer.<locals>.<genexpr>�s����>�*=�Q�:�a�=�*=�s�zInvalid index zE. Must be integer, list-like, slice or a tuple of integers and slicesr)r�allrr�_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_indexerz7GroupByIndexingMixin._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��%�%rc�P�|dk\r|j|k(S|j|dz
k(S)Nr�)r-�_descending_count)rr1s  rr)z(GroupByIndexingMixin._make_mask_from_int�s1���!�8��(�(�C�/�/��)�)�s�d�Q�h�7�7rc��|D�cgc]
}|dk\s�	|��}}|D�cgc]}|dks�	|dz
��}}d}|r#|tj|j|�z}|r#|tj|j|�z}|Scc}wcc}w)Nrr5F)r.�isinr-r6)r�argsr1�positive�negativer2s      rr"z)GroupByIndexingMixin._make_mask_from_list�s���#'�4�4�C�3�!�8�C�4��4�(,�8����a��S�D�1�H���8�"'����B�G�G�D�1�1�8�<�<�D���B�G�G�D�2�2�H�=�=�D����5��8s�
A=�A=�
B�Bc���d}|D]l}t|�r#||jtt|��z}�1t	|t
�r||j
|�z}�Vtdt|��d���|S)NFzInvalid argument z. Should be int or slice.)	r
r)rr#r&r'r(�
ValueErrorr+)rr9r2r1s    rr$z*GroupByIndexingMixin._make_mask_from_tuple�sw��"'���C��#����0�0��c�3��@�@���C��'���2�2�3�7�7�� �'��S�	�{�2K�L���
��rc�l�|j}|j}|j}|�|dkrtd|�d���d}|�d}|�|dkDr�||j|zdk(z}n�|dk\r0||j|k\z}|dkDr�||j|z
|zdk(z}ns||j
|kz}|j
|zdz}|j|j
z|dzzdk}t
j||j|�}|||zdk(z}|�,|dk\r||j|kz}|S||j
|k\z}|S)Nrz
Invalid step z. Must be non-negativeTr5)�start�stop�stepr=r-r6r.�where)rr1r?r@rAr2�offset_array�limit_arrays        rr(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���rc��tr*ttj|�}|j	�S|}|j	�Sr�rrrr�_cumcount_arrayrs  rr-z%GroupByIndexingMixin._ascending_count�s<��������6�L��+�+�-�-� �L��+�+�-�-rc�l�trttj|�}n|}|j	d��S)NF)�	ascendingrFrs  rr6z&GroupByIndexingMixin._descending_count�s.��������6�L��L��+�+�e�+�<�<rN)�returnr)r1�PositionalIndexer | tuplerJ�
np.ndarray)r1r#rJrL)r9z
Iterable[int]rJ�bool | np.ndarray)r9r%rJrM)r1r'rJrM)rJrL)
�__name__�
__module__�__qualname__�__doc__rrr3r)r"r$r(r-r6�rrrr sr����S7��S7�j&�
&�&�
�&�:8��
�(�T�.��.��=��=rrc��eZdZdd�Zdd�Zy)rc��||_yr��groupby_object�rrVs  r�__init__z"GroupByPositionalSelector.__init__��
��,��rc�n�|jj|�}|jj|�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.
        )rVr3�_mask_selected_objr0s   r�__getitem__z%GroupByPositionalSelector.__getitem__�s1��>�"�"�E�E�c�J���"�"�5�5�d�;�;rN�rVzgroupby.GroupByrJ�None)r1rKrJ�DataFrame | Series)rNrOrPrXr\rRrrrr�s��-� <rrc�6�eZdZdZdd�Z	d					dd�Zd	d�Zy)
�GroupByNthSelectorzO
    Dynamically substituted for GroupBy.nth to enable both call and index
    c��||_yrrUrWs  rrXzGroupByNthSelector.__init__%rYrNc�:�|jj||�Sr�rV�_nth)r�n�dropnas   r�__call__zGroupByNthSelector.__call__(s��
�"�"�'�'��6�2�2rc�8�|jj|�Srrd)rrfs  rr\zGroupByNthSelector.__getitem__/s���"�"�'�'��*�*rr]r)rfrKrgzLiteral['any', 'all', None]rJr_)rfrKrJr_)rNrOrPrQrXrhr\rRrrrara s7���-�/3�3�$�3�,�3�
�	3�+rra)�
__future__r�collections.abcr�typingrrr�numpyr.�pandas.util._decoratorsrr	�pandas.core.dtypes.commonr
r�pandas._typingr�pandasr
r�pandas.core.groupbyrrrrrarRrr�<module>rsss��"�$�����
�
�0��,�U=�U=�p��.�.�/�$<�$<�0�$<�N+�+r

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists