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__/ops.cpython-312.pyc

�

MٜgZ����dZddlmZddlZddlZddlmZmZmZm	Z	ddl
Zddlm
Z
mZddlmcmZddlmZmZmZmZmZddlmZddlmZdd	lmZmZdd
l m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'm(Z(ddl)m*Z*dd
l+m,Z,ddl-m.Z.m/Z/m0Z0m1Z1ddl2m3Z3ddl4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:erddl;m<Z<m=Z=m>Z>ddl?m@Z@d$d�ZAd�ZBGd�d�ZCGd�d�ZDGd�deD�ZEd%d�ZFGd�dee�ZGGd�deG�ZHGd �d!eG�ZIdd"�													d&d#�ZJy)'a
Provide classes to perform the groupby aggregate operations.

These are not exposed to the user and provide implementations of the grouping
operations, primarily in cython. These classes (BaseGrouper and BinGrouper)
are contained *in* the SeriesGroupBy and DataFrameGroupBy objects.
�)�annotationsN)�
TYPE_CHECKING�Callable�Generic�final)�NaT�lib)�	ArrayLike�AxisInt�NDFrameT�Shape�npt��AbstractMethodError)�cache_readonly)�maybe_cast_pointwise_result�maybe_downcast_to_dtype)�ensure_float64�ensure_int64�ensure_platform_int�
ensure_uint64�is_1d_only_ea_dtype)�isna�
maybe_fill)�	DataFrame)�grouper)�CategoricalIndex�Index�
MultiIndex�ensure_index)�Series)�compress_group_index�decons_obs_group_ids�get_flattened_list�get_group_index�get_group_index_sorter�get_indexer_dict)�Hashable�Iterator�Sequence)�NDFramec�b�t|tj�r|tk7rt	d��yy)NzMust produce aggregated value)�
isinstance�np�ndarray�object�
ValueError)�obj�dtypes  �B/usr/local/lib/python3.12/site-packages/pandas/core/groupby/ops.py�check_result_arrayr5Ps1���#�r�z�z�"��F�?��<�=�=��#�c�z�t|d�r.|j}|jdk(rt|�dk(r|d}|S)zb
    Extract the result object, it might be a 0-dim ndarray
    or a len-1 0-dim, or a scalar
    �_values�r)�hasattrr8�ndim�len)�ress r4�extract_resultr>[s:��
�s�I���k�k���8�8�q�=�S��X��]��a�&�C��Jr6c� �eZdZUdZegd��Zd:d�Zideje	jd���deje	jd���dd�d	d
�deje	jd���d
eje	jd
���dd�dd�dd�dd�dd�deje	jd���deje	jd���dd�dd�dd�d d!�d"d#d$d%d&d'�d(�Z
d)ed*<d d+iZed;d,��Zeej$								d<d-���Zd=d.�Zd>d/�Zd?d0�Zd?d1�Zed2d2d3�													d@d4��Ze														d@d5��ZedAd6��Zed7d8�											dBd9��Zy2)C�WrappedCythonOpaB
    Dispatch logic for functions defined in _libs.groupby

    Parameters
    ----------
    kind: str
        Whether the operation is an aggregate or transform.
    how: str
        Operation name, e.g. "mean".
    has_dropped_na: bool
        True precisely when dropna=True and the grouper contains a null value.
    )�any�all�rank�count�size�idxmin�idxmaxc�.�||_||_||_y�N��kind�how�has_dropped_na)�selfrKrLrMs    r4�__init__zWrappedCythonOp.__init__}s����	����,��r6rA)�val_testrB�sum�	group_sum�prod�
group_prodrF)�namerG�min�	group_min�max�	group_max�mean�
group_mean�median�group_median_float64�var�	group_var�std�sem�skew�
group_skew�first�	group_nth�last�
group_last�ohlc�
group_ohlc�
group_cumprod�group_cumsum�group_cummin�group_cummax�
group_rank)�cumprod�cumsum�cummin�cummaxrC)�	aggregate�	transformzdict[str, dict]�_CYTHON_FUNCTIONS�c�(�||jdvryy)Nrsrt)ru)�clsrLs  r4�get_kind_from_howz!WrappedCythonOp.get_kind_from_how�s���#�'�'��4�4��r6c�^�|j}|j||}t|�r|}ntt|�}|r|S|tjt�k(rF|dvrtd|�d|�d���|dvr|S|dk(r	|Sd|jvrtd|�d|�d���|Std|��)	N)r\roz2function is not implemented for this dtype: [how->z,dtype->�])r`rarFrGrbr0zPThis should not be reached. Please report a bug at github.com/pandas-dev/pandas/)
rUru�callable�getattr�
libgroupbyr.r3r0�NotImplementedError�__signatures__)rxrKrLr3�
is_numeric�	dtype_str�ftype�fs        r4�_get_cython_functionz$WrappedCythonOp._get_cython_function�s���
�J�J�	��%�%�d�+�C�0���E�?��A��
�E�*�A���H�
�b�h�h�v�&�
&��+�+�)�� �E��)��A�7����:�:��������H�
��!1�!1�1�)�� �E��)��A�7����H�%�0���
r6c�2�|j}|dvr
t|�}|S|jjdvra|dvs|jdk(r|jr
t|�}|S|dvr1|jjdk(r
t|�}|St
|�}|S)z�
        Cast numeric dtypes to float64 for functions that only support that.

        Parameters
        ----------
        values : np.ndarray

        Returns
        -------
        values : np.ndarray
        )r\r`rarb�iu)r^rZrt)rQrhrSrpro�i)rLrr3rKrMrr)rN�valuesrLs   r4�_get_cython_valsz WrappedCythonOp._get_cython_vals�s����h�h���2�2�$�F�+�F�"�
��\�\�
�
�$�
&��o�%��	�	�[�(�T�-@�-@�(��/���
��D�D��<�<�$�$��+�)�&�1�F��
�+�6�2�F��
r6c���|j}|j}|jj|d�}|dk(r||f}|S|dkDrt	d��|dk(r|j
}|S|f|j
ddz}|S)Nr9rhz<arity of more than 1 is not supported for the 'how' argumentrt)rLrK�
_cython_arity�getr�shape)rN�ngroupsr�rLrK�arity�	out_shapes       r4�_get_output_shapez!WrappedCythonOp._get_output_shape�s����h�h���y�y���"�"�&�&�s�A�.���&�=� �%�(�I����Q�Y�%�N��
��[�
 ����I���!�
�V�\�\�!�"�%5�5�I��r6c��|j}|dk(rd}n2|dvrd}n+|jdvr|j�|j��}nd}tj|�S)NrC�float64�rFrG�intp�iufcbr0)rLrK�itemsizer.r3)rNr3rL�	out_dtypes    r4�_get_out_dtypezWrappedCythonOp._get_out_dtypes^���h�h���&�=�!�I�
�(�
(��I��z�z�W�$�$�z�z�l�5�>�>�*:�;�	�$�	��x�x�	�"�"r6c�2�|j}|dvrA|tjt�k(r#tjtj�S|S|dvrA|j
dvr|S|j
dvr#tjtj�S|S)a
        Get the desired dtype of a result based on the
        input dtype and how it was computed.

        Parameters
        ----------
        dtype : np.dtype

        Returns
        -------
        np.dtype
            The desired dtype of the result.
        )rQrprQrSro)rZr\r^r`ra�fc�iub)rLr.r3�bool�int64rKr�)rNr3rLs   r4�_get_result_dtypez!WrappedCythonOp._get_result_dtypes����h�h���=�=�������&��x�x����)�)����;�
;��z�z�T�!������u�$��x�x��
�
�+�+��r6N)�mask�result_maskc	��|jdk(r[|ddd�f}|�	|ddd�f}|�	|ddd�f}|j|f|||||d�|��}	|	jddk(r|	dS|	jS|j|f|||||d�|��S)Nr9)�	min_countr��comp_idsr�r�r)r;�_call_cython_opr��T)
rNr�r�r�r�r�r��kwargs�values2dr=s
          r4�_cython_op_ndim_compatz&WrappedCythonOp._cython_op_ndim_compat6s����;�;�!���d�A�g��H����D�!�G�}���&�)�$��'�2��&�$�&�&���#��!��'�
���C��y�y��|�q� ��1�v�
��5�5�L�#�t�#�#��
�����#�

��
�	
r6c���|}|j}	|	jdv}
|	jdv}|r|jd�}d}
n |	jdk(r|jd�}|jdk(r|jtj
�}|jdvrv|�t|�}|	tk(r*|d	r%|j�r|j�}d||<|jtd
��jtj�}d}
|j}|�|j}|�|j}|j||�}|j|j|j|j|
�}
|j!|�}|j#|j�}t%t	j&||���}|jd
k(r�t	j(|tj*��}|jdvr|
d!||||||||d�|��n�|jdvr$|jdvr||d<|
||||f|||d�|��n�|jdvr&|
d!|||||d�|��|jtd
��}nw|jdvr.|
d!||||||d�|��|	tk(rQ|jt�}n;t-|j�d���|jdk7r||d<|
d!||||||d�|��|jd
k(r�|jdvr�|jjdvrn|slt/|jdvrdnd|�}|k}|j�r;|�||j1�s&J�|jd �}tj2||<|j}|j|j4vr)|j7|j�}t9||�}|S|}|S)"Nr��mMr�T�b�uint8�float16)rArB�skipnaF)�copy�r3rs)rFrGrVrXrZrfrdrQ)�out�countsr��labelsr�r�r��is_datetimelike)rar`r^rhrSr\)r`rar�)r�r�r�)r�r�r�r�r�)rb)r�r�r�r�r�r�z is not implementedrCr�)r�r�r�r�r�r�r�r�)rQrSrr9r��)r3rK�view�astyper.�float32rLrr0rAr�r��int8r�r�r�r�r�r�empty�zerosr�rrXrB�nan�cast_blocklistr�r)rNr�r�r�r�r�r�r��orig_valuesr3r�r�r��funcr��resultr��cutoff�empty_groups�	res_dtype�	op_results                     r4r�zWrappedCythonOp._call_cython_opbs
���������Z�Z�7�*�
��*�*��,����[�[��)�F��J�
�Z�Z�3�
��[�[��)�F��<�<�9�$��]�]�2�:�:�.�F��8�8�~�%��|��F�|������(�#��x�x�z�!'�����'+��t���]�]�4�e�]�4�9�9�"�'�'�B�F��J��������6�6�D��&�)�m�m���*�*�7�F�;�	��(�(����D�H�H�f�l�l�J�W���&�&�v�.���'�'����5�	��B�H�H�Y�i�@�A���9�9��#��X�X�g�R�X�X�6�F��x�x�	�	��
��!�!�#�'�� +�$3�
��
����L�L��8�8�~�-�0?�F�,�-������		�
(�� +�	��	����^�+����!�#�� +���
� ���t�%��8�����X�%����!�!�#�� +�
����F�?�#�]�]�6�2�F�*�T�X�X�J�6I�*J�K�K��x�x�6�!�(3��}�%��
����� /��

��
��9�9��#����8L�(L��|�|� � �D�(���$�(�(�o�"=�Q�1�i�P��%�����#�#�%�"�.�*�<�8�<�<�>�>�>�"(���y�!9��/1�v�v��|�,������8�8�4�.�.�.�
�.�.�{�/@�/@�A�I�/��	�B�I����I��r6c��|jdkDrtd��|jdk(r
|dk(sJ|��yt|j�s|dk(sJ�yy)N�z.number of dimensions is currently limited to 2r9r)r;rrr3)rN�axisr�s   r4�_validate_axiszWrappedCythonOp._validate_axissU���;�;��?�%�&V�W�W��;�;�!���1�9�"�d�"�9�$�V�\�\�2��1�9��9�3r6���)r�c	���|j||�t|tj�s,|jd|j
|j|||d�|��S|j|f|||dd�|��S)zW
        Call our cython function, with appropriate pre- and post- processing.
        )rLrMr�r��idsN)r�r�r�r�r�)r�r-r.r/�_groupby_oprLrMr�)rNr�r�r�r�r�r�s       r4�cython_operationz WrappedCythonOp.cython_operations���	
���D�&�)��&�"�*�*�-�%�6�%�%���H�H�#�2�2�#�����
�
�+�t�*�*��
�����
��

�	
r6)rK�strrLr�rMr��return�None)rLr�r�r�)rKr�rLr�r3�np.dtyper�r�)r��
np.ndarrayr�r�)r��intr�r�r�r
)r3r�r�r�)r�r�r�r�r�r�r�r�r��npt.NDArray[np.bool_] | Noner�r�r�r�)r�rr�r
r�r�)r�r
r�rr�r�r�r�r�r�r�r
)�__name__�
__module__�__qualname__�__doc__�	frozensetr�rO�	functools�partialr~�
group_any_all�group_idxmin_idxmaxr_ru�__annotations__r��classmethodry�cacher�r�r�r�r�rr�r�r�r�r�r6r4r@r@is1����C��N�-�
��$�9�$�$�Z�%=�%=��N�
��$�9�$�$�Z�%=�%=��N�
�
�;�
�
�L�	
�

�'�i�'�'�
�(F�(F�X�V�
�
�'�i�'�'�
�(F�(F�X�V�

�
�;�
�
�;�
�
�L�
�
�,�
�
�;�
�
�$�9�$�$�Z�%9�%9��F�
�
�$�9�$�$�Z�%9�%9��F�
�
�L�
�
�[�
� 
�L�!
�"
�L�#
�('�$�$�$� �
�)*����:�Q�K�M�������_�_�'��'� �'�)1�'�?C�'���'�R#�J�&#� �4�.2�48�)
��)
��	)
�
�)
��
)
�+�)
�2�)
�
�)
��)
�V�[��[��	[�
�[��
[�+�[�2�[�
�[��[�z������!
��!
��	!
�
�!
��
!
��!
�
�!
��!
r6r@c���eZdZUdZded<		d#									d$d�Zed%d��Zed&d��Zd'd�Z	ed(d��Z
	d)					d*d	�Zed)d+d
��Z
eed���Zed,d��Zed-d
��Zeed.d���Zed/d��Zed0d��Zed1d��Zed2d��Zeed3d���Zeed3d���Zed4d��Zed-d��Ze		d5d��Zeed(d���Zed6d��Zed7d��Zed8d��Ze	d9									d:d��Z e	d;							d<d��Z!e						d=d��Z"e	d)							d>d��Z#eed-d ���Z$eed-d!���Z%y")?�BaseGroupera�
    This is an internal Grouper class, which actually holds
    the generated groups

    Parameters
    ----------
    axis : Index
    groupings : Sequence[Grouping]
        all the grouping instances to handle in this grouper
        for example for grouper list to groupby, need to pass the list
    sort : bool, default True
        whether this grouper will give sorted result or not

    rr�c�|�t|t�sJ|��||_t|�|_||_||_yrI)r-rr��list�
_groupings�_sort�dropna)rNr��	groupings�sortr�s     r4rOzBaseGrouper.__init__Bs9���$��&�,��,�&���	�26�y�/�����
���r6c��|jSrI)r��rNs r4r�zBaseGrouper.groupingsPs�����r6c�:�td�|jD��S)Nc3�4K�|]}|j���y�wrI)r�)�.0�pings  r4�	<genexpr>z$BaseGrouper.shape.<locals>.<genexpr>Vs����=�n�d�T�\�\�n�s�)�tupler�r�s r4r�zBaseGrouper.shapeTs���=�d�n�n�=�=�=r6c�,�t|j�SrI)�iter�indicesr�s r4�__iter__zBaseGrouper.__iter__Xs���D�L�L�!�!r6c�,�t|j�SrI)r<r�r�s r4�nkeyszBaseGrouper.nkeys[s���4�>�>�"�"r6c#�vK�|j||��}|j}t||�Ed{���y7��w)��
        Groupby iterator

        Returns
        -------
        Generator yielding sequence of (name, subsetted object)
        for each group
        �r�N)�
_get_splitter�group_keys_seq�zip)rN�datar��splitter�keyss     r4�get_iteratorzBaseGrouper.get_iterator_s8�����%�%�d��%�6���"�"���t�X�&�&�&�s�/9�7�9c�l�|j\}}}t||||j|j|��S)zV
        Returns
        -------
        Generator yielding subsetted objects
        )�
sorted_ids�sort_idxr�)�
group_infor��_sorted_ids�	_sort_idx)rNrr�r��_r�s      r4r�zBaseGrouper._get_splitterns<���/�/���Q�������'�'��^�^��

�	
r6c��t|j�dk(r|jdS|j\}}}t	|||j|j
�S�Nr9r)r<r��levelsrr$�codes�rNr�r
r�s    r4r�zBaseGrouper.group_keys_seqsM���t�~�~��!�#��;�;�q�>�!�"�o�o�O�C��G�&�c�7�D�K�K����L�Lr6c�P�t|j�dk(r3t|jt�r|jdj
S|jD�cgc]}|j��}}|jD�cgc]}|j��}}t||�Scc}wcc}w)z"dict {group name -> group indices}r9r)	r<r�r-�result_indexrr�r�_group_indexr')rNr��
codes_listrs    r4r�zBaseGrouper.indices�s����t�~�~��!�#�
�4�3D�3D�FV�(W��>�>�!�$�,�,�,�-1�^�^�<�^�T�d�j�j�^�
�<�.2�n�n�=�n�d��!�!�n��=��
�D�1�1��=��=s�B�=B#c��t|j|j|jd��}t	||j��\}}|j
r8t
j|dk\�}t
j|dk(�|}||}t||j�}|j
r|t
j|�z
}|S)zR
        Get the original integer locations of result_index in the input.
        T�r��xnull�r�rr�)r%rr�r�r"rMr.�whererpr&r��take)rN�group_indexr
r��	null_gapsr�s      r4�result_ilocszBaseGrouper.result_ilocs�s���&��J�J��
�
����4�
��.�k��
�
�K���Q�����8�8�K�1�,�-�D��	�	�+��"3�4�T�:�I�%�d�+�K�'��T�\�\�B������b�g�g�i��0�0�F��
r6c�T�|jD�cgc]}|j��c}Scc}wrI)r�r�rNr�s  r4rzBaseGrouper.codes�s$��(,�~�~�6�~�t��
�
�~�6�6��6��%c�T�|jD�cgc]}|j��c}Scc}wrI)r�rrs  r4r
zBaseGrouper.levels�s$��.2�n�n�=�n�d��!�!�n�=�=��=rc�T�|jD�cgc]}|j��c}Scc}wrI)r�rUrs  r4�nameszBaseGrouper.names�s"��&*�n�n�5�n�d��	�	�n�5�5��5rc��|j\}}}|rtj||dk7|��}ng}t||jdd��S)z&
        Compute group sizes.
        r�)�	minlengthr�F)�indexr3r�)rr.�bincountr!r)rNr�r
r�r�s     r4rEzBaseGrouper.size�sJ��
�/�/���Q����+�+�c�#��)�n��@�C��C��c��!2�!2�'��N�Nr6c��t|j�dk(r|jdjSg}|jD]X}|j}t	|t
�s|j
|��1|j
|jdj��Ztj|�}|jj|�S)�!dict {group name -> group labels}r9r)r<r��groups�grouping_vectorr-r��appendr�from_arraysr��groupby)rN�
to_groupbyr��gvr%s     r4r)zBaseGrouper.groups�s����t�~�~��!�#��>�>�!�$�+�+�+��J������)�)��!�"�k�2��%�%�b�)��%�%�b�l�l�1�o�&E�&E�F�'��*�*�:�6�E��9�9�$�$�U�+�+r6c�F�t|jd�jS�Nr)rr�is_monotonic_increasingr�s r4�is_monotoniczBaseGrouper.is_monotonic�s���T�_�_�Q�'�(�@�@�@r6c�T�t|jddkj��S)zE
        Whether grouper has null value(s) that are dropped.
        r)r�rrAr�s r4rMzBaseGrouper.has_dropped_na�s&���T�_�_�Q�'�!�+�0�0�2�3�3r6c�^�|j�\}}t|�}t|�}|||fSrI)�_get_compressed_codesr<r)rNr��
obs_group_idsr�s    r4rzBaseGrouper.group_info�s6��"&�"<�"<�">���-��m�$��&�x�0�����/�/r6c�&�|j\}}}|SrI)r�rNr�r
s   r4�
codes_infozBaseGrouper.codes_info�s���O�O�	��Q���
r6c�L�t|j�dkDr:t|j|jdd��}t||j��S|jd}|jtjt|j�tj��fS)Nr9Trrrr�)r<r�r%rr�r"r�r.�arangerr�)rNrr�s   r4r6z!BaseGrouper._get_compressed_codes�sx��
�t�~�~���"�)�$�*�*�d�j�j�t�SW�X�K�'��$�*�*�E�E��~�~�a� ���z�z�2�9�9�S��):�):�%;�2�7�7�K�K�Kr6c�,�t|j�SrI)r<rr�s r4r�zBaseGrouper.ngroupss���4�$�$�%�%r6c�n�|j}|j\}}}t|||j|d��S)NT)r)rrr#r�)rNrr��obs_idsr
s     r4�reconstructed_codeszBaseGrouper.reconstructed_codess1���
�
���/�/���W�a�#�C��$�*�*�e�4�P�Pr6c�6�t|j�dk(r5|jdjj|jd�S|j
}|jD�cgc]}|j��}}t
||d|j��Scc}w)Nr9rF)r
r�verify_integrityr")r<r��
_result_index�renamer"r@r)rNrr�r
s    r4rzBaseGrouper.result_indexs����t�~�~��!�#��>�>�!�$�2�2�9�9�$�*�*�Q�-�H�H��(�(��15���@���$�$�$���@�����d�j�j�
�	
��As�(Bc�,�t|j�dk(r|jdjgSg}t|j|j�D]<\}}t|�}|jj
|�}|j|��>|Sr)r<r��_group_arrayliker�r@rrr+)rN�	name_listr�rr
s     r4�get_group_levelszBaseGrouper.get_group_levelss����t�~�~��!�#��N�N�1�%�6�6�7�7��	��t�~�~�t�/G�/G�H�K�D�%�'��.�E��*�*�/�/��6�F����V�$�	I��r6c	��|dvsJ�t|||j��}|j\}}	}	|j}
|jd|||||
d�|��S)z;
        Returns the values of a cython operation.
        )rtrsrJ)r�r�r�r�r�r�)r@rMrr�r�)rNrKr�rLr�r�r��cy_opr�r
r�s           r4�_cython_operationzBaseGrouper._cython_operation,sr���1�1�1�1��T�s�4�CV�CV�W���O�O�	��Q���,�,��%�u�%�%�
������
��

�	
r6c���t|jtj�sd}|j	||�}tj|d��}|rt||jd��}|S|}|S)a1
        Parameters
        ----------
        obj : Series
        func : function taking a Series and returning a scalar-like
        preserve_dtype : bool
            Whether the aggregation is known to be dtype-preserving.

        Returns
        -------
        np.ndarray or ExtensionArray
        TF)�	try_float)�numeric_only)	r-r8r.r/�_aggregate_series_pure_pythonr	�maybe_convert_objectsrr3)rNr2r��preserve_dtyper��npvaluesr�s       r4�
agg_serieszBaseGrouper.agg_seriesHsj��"�#�+�+�r�z�z�2�
"�N��3�3�C��>���,�,�V�u�E���-�h��	�	�PT�U�C��
��C��
r6c��|j\}}}tj|d��}d}|j|d��}t	|�D]7\}}	||	�}
t|
�}
|st
|
|	j�d}|
||<�9|S)N�Or�Frr�T)rr.r�r��	enumerater>r5r3)rNr2r�r
r�r��initializedrr��groupr=s           r4rOz)BaseGrouper._aggregate_series_pure_pythonis������
��1�g����'��-�����%�%�c��%�2��!�(�+�H�A�u��u�+�C� ��%�C��"�3����4�"���F�1�I�,��
r6c�z�d}|j||��}|j}g}t||�}|D]R\}	}
tj	|
d|	�|
j
}||
�}|st
|||�sd}|j|��Tt|�dk(r$t|dd�dvr||jdd�||fS)NFr�rUTrr�)rbrQrS)r�r�r�r0�__setattr__�axes�_is_indexed_liker+r<r}�iloc)
rNr�rr��mutatedr�
group_keys�
result_values�zipped�keyrX�
group_axesr=s
             r4�apply_groupwisezBaseGrouper.apply_groupwise�s������%�%�d��%�6���(�(�
��
��Z��*�� �J�C��
���u�f�c�2����J��E�(�C��#3�C��T�#J���� � ��%�!��z�?�a��G�A�z�4�$@�E
�%
�
�d�i�i���m���g�%�%r6c�:�|j\}}}t||�SrI)rr&rs    r4r	zBaseGrouper._sort_idx�s ���/�/���Q��%�c�7�3�3r6c�X�|j\}}}|j|j�SrI)rrr	r9s   r4rzBaseGrouper._sorted_ids�s&���O�O�	��Q���x�x����'�'r6N)TT)
r�rr�zSequence[grouper.Grouping]r�r�r�r�r�r��r�zlist[grouper.Grouping])r�r
)r�zIterator[Hashable]�r�r��r)rrr�rr�z#Iterator[tuple[Hashable, NDFrameT]])rr+r�rr��DataSplitter)r�z$dict[Hashable, npt.NDArray[np.intp]]�r��npt.NDArray[np.intp])r�z#list[npt.NDArray[np.signedinteger]]�r�zlist[Index]�r�zlist[Hashable])r�r!)r�zdict[Hashable, np.ndarray])r�r��r�z6tuple[npt.NDArray[np.intp], npt.NDArray[np.intp], int])r�z:tuple[npt.NDArray[np.signedinteger], npt.NDArray[np.intp]])r�zlist[npt.NDArray[np.intp]]�r�r)r�zlist[ArrayLike])r�)
rKr�rLr�r�rr�r�r�r
)F)r2r!r�rrQr�r�r
)r2r!r�rr�znpt.NDArray[np.object_])r�rrzDataFrame | Seriesr�rr�ztuple[list, bool])&r�r�r�r�r�rO�propertyr�r�r�r�rrr�rr�r�rrr
r"rEr)r3rMrr:r6r�r@rrHrKrSrOrdr	rr�r6r4r�r�0sn��
��K������.���	�
��
�
������>��>�"��#��#�/0�
'��
'�$+�
'�	,�
'��
��
� ��M���M��2��2�����4�
�7���7��>��>��6��6��
O��
O��
,��
,���A���A���4���4��0��0�����
�
L�	C�
L��
L���&���&��Q��Q�
�
��
��
��
�$��

��
��	
�
�
��

�
�
��
�6�BG����!)��;?��	����@����!)��	 ����.�EF�$&��$&�!3�$&�;B�$&�	�$&��$&�R��4���4�
��(���(r6r�c���eZdZUdZded<ded<	d	dd�Zed��Zedd	��Z	edd
��Z
ddd�Zed��Zedd
��Z
edd��Zedd��Zedd��Zedd��Zedd��Zy)�
BinGroupera�
    This is an internal Grouper class

    Parameters
    ----------
    bins : the split index of binlabels to group the item of axis
    binlabels : the label list
    indexer : np.ndarray[np.intp], optional
        the indexer created by Grouper
        some groupers (TimeGrouper) will sort its axis and its
        group_info is also sorted, so need the indexer to reorder

    Examples
    --------
    bins: [2, 4, 6, 8, 10]
    binlabels: DatetimeIndex(['2005-01-01', '2005-01-03',
        '2005-01-05', '2005-01-07', '2005-01-09'],
        dtype='datetime64[ns]', freq='2D')

    the group_info, which contains the label of each item in grouped
    axis, the index of label in label list, group number, is

    (array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4]), array([0, 1, 2, 3, 4]), 5)

    means that, the grouped axis has 10 items, can be grouped into 5
    labels, the first and second items belong to the first label, the
    third and forth items belong to the second label, and so on

    znpt.NDArray[np.int64]�binsr�	binlabelsNc��t|�|_t|�|_||_t|j�t|j�k(sJ�yrI)rrtr ru�indexerr<)rNrtrurws    r4rOzBinGrouper.__init__�sD��!��&��	�%�i�0�������4�>�>�"�c�$�)�)�n�4�4�4r6c��t|j|j�D��cic]\}}|tur||��}}}|Scc}}w)r()r�rurtr)rNrb�valuer�s    r4r)zBinGrouper.groups�sN��"�$�.�.�$�)�)�<�
�<�
��U��#�~�
��J�<�	�
�
�
��
s�>c��y)Nr9r�r�s r4r�zBinGrouper.nkeys�s��r6c��|j\}}}|j�&tj||jf�}||}|SrI)rrwr.�lexsort)rNr�r
�sorters    r4r:zBinGrouper.codes_info�sB���O�O�	��Q���<�<�#��Z�Z��d�l�l� 3�4�F��f�+�C��
r6c#� �K�|dk(r�fd�}n�fd�}t�j|�}d}t|j|j�D]\}}|t
ur
||||�f��|}�||kr|jd||d�f��yy�w)r�rc�"���j||SrI�r]��start�edgers  �r4�<lambda>z)BinGrouper.get_iterator.<locals>.<lambda>
s������5��)>r6c�.���jdd�||�fSrIr�r�s  �r4r�z)BinGrouper.get_iterator.<locals>.<lambda>s������1�e�D�j�=�)Ar6r�N)r<r[r�rtrur)rNrr��slicer�lengthr�r��labels `      r4rzBinGrouper.get_iterators�������1�9�>�F�A�F��T�Y�Y�t�_�%�����t�y�y�$�.�.�9�K�D�%��C���V�E�4�0�0�0��E�:�
�6�>��.�.��$�f�U�D�&9�9�9��s�BBc���tjt�}d}t|j|j
�D]-\}}||ks�|turtt||��||<|}�/|Sr1)�collections�defaultdictr�r�rurtr�range)rNr�r�r��bins     r4r�zBinGrouper.indicessc���)�)�$�/��
���d�n�n�d�i�i�8�J�E�3��3�w���#�%)�%��3�-�%8�G�E�N���	9�
�r6c��|j}tj|tj��}tjtj
d|jf�}t|�}|t|j�k(r*tjtj|�|�}n<tjtj
dtj|�f|�}t|�||fS)Nr�rr�)
r�r.r<r��diff�r_rtrr<�repeat)rNr�r7�repr�s     r4rzBinGrouper.group_info(s����,�,���	�	�'����9�
��g�g�b�e�e�A�t�y�y�L�)�*��!�#�&���c�$�)�)�n�$��y�y����7�!3�S�9�H��y�y����r�2�9�9�W�+=�'=�!>��D�H�
 ��)���
�	
r6c��tjdtj|jdd|jddk7�dzfgS)Nrr9r�)r.r��flatnonzerortr�s r4r@zBinGrouper.reconstructed_codes:sB�����a�����	�	�!�"�
����3�B��(G�H�1�L�L�M�N�Nr6c��t|j�dk7r't|jd�r|jddS|jS)Nrr9)r<rurr�s r4rzBinGrouper.result_index?s>���t�~�~��!�#��T�^�^�A�->�(?��>�>�!�"�%�%��~�~�r6c��|jgSrI)rur�s r4r
zBinGrouper.levelsFs������r6c�0�|jjgSrI)rurUr�s r4r"zBinGrouper.namesJs�����#�#�$�$r6c��|j}|jd}|j|�}tj||dd|j
��}|gS)NrF)�in_axis�level�uniques)rurrr�Groupingr8)rN�levrr�r�s     r4r�zBinGrouper.groupingsNsN���n�n������"�����%�������F�E��s�{�{�
���v�
r6rI�r�r�rhrkri)rr+r�rro)r�zlist[np.ndarray]rprmrnrg)r�r�r�r�r�rOrr)rqr�r:rr�rr@rr
r"r�r�r6r4rsrs�s����< �����	5�

�5��	��	���������:�2�	��	��
��
�"�O��O������ �� ��%��%����r6rsc���t|t�r0t|�dkDry|j|j	||�St|t
�r!|j|j	||�Sy)Nr9F)r-r!r<r[�equalsr)r2r[r�s   r4r\r\Ysa���#�v���t�9�q�=���x�x��~�$�$�T�$�Z�0�0�	�C��	#��x�x��~�$�$�T�$�Z�0�0�r6c�V�eZdZdd�													dd�Zd	d�Zed
d��Zdd�Zy)rjrr�c��||_t|�|_||_||_||_||_t|t�sJ|��yrI)	rrr�r��_slabelsr	r�r-r�)rNrr�r�rrr�s       r4rOzDataSplitter.__init__isH����	�)�&�1������"��
�!�����	��$��$�*�d�*�$r6c#�K�|j}|jdk(rytj|j|j�\}}t||�D]#\}}|j
|t||�����%y�wr1)�_sorted_datar�r	�generate_slicesr�r��_chop�slice)rN�sdata�starts�endsr��ends      r4r�zDataSplitter.__iter__}sm�����!�!���<�<�1��
��*�*�4�=�=�$�,�,�G�����f�d�+�J�E�3��*�*�U�E�%��$5�6�6�,�s�A=A?c�d�|jj|j|j��S)Nr�)rrr	r�r�s r4r�zDataSplitter._sorted_data�s!���y�y�~�~�d�n�n�4�9�9�~�=�=r6c��t|��rIr)rNr��	slice_objs   r4r�zDataSplitter._chop�s
��!�$�'�'r6N)rrr�rlr�r�rrlrrlr�rr�r�)r�r))r�r)r�r�r�r+)r�r�r�rOr�rr�r�r�r6r4rjrjhsn���+��+�%�+��	+�'�
+�)�+��+�
�+�(7��>��>�(r6rjc��eZdZdd�Zy)�SeriesSplitterc��|jj|�}|j||j��}|j|_|j
|d��S)N�r[r-��method)�_mgr�	get_slice�_constructor_from_mgrr[rU�_name�__finalize__)rNr�r��mgr�sers     r4r�zSeriesSplitter._chop�sP���j�j�"�"�9�-���)�)�#�C�H�H�)�=���J�J��	�����i��8�8r6N)r�r!r�r�r�r!�r�r�r�r�r�r6r4r�r��s��9r6r�c��eZdZdd�Zy)�
FrameSplitterc��|jj|d|jz
��}|j||j��}|j|d��S)Nr9r�r�r-r�)r�r�r�r�r[r�)rNr�r�r��dfs     r4r�zFrameSplitter._chop�sQ���j�j�"�"�9�1�t�y�y�=�"�A��
�
(�
(��3�8�8�
(�
<�����u�Y��7�7r6N)r�rr�r�r�rr�r�r6r4r�r��s��8r6r�r�c�X�t|t�rt}nt}|||||||��S)N)rrr�)r-r!r�r�)rr�r�rrr��klasss       r4r�r��s4���$���$2������f�g��Z�d��r6r�)r�rr�r�)rr+r�rlr�r�rrlrrlr�rr�rj)Kr��
__future__rr�r��typingrrrr�numpyr.�pandas._libsrr	�pandas._libs.groupby�_libsr-r~�pandas._typingr
rrr
r�
pandas.errorsr�pandas.util._decoratorsr�pandas.core.dtypes.castrr�pandas.core.dtypes.commonrrrrr�pandas.core.dtypes.missingrr�pandas.core.framer�pandas.core.groupbyr�pandas.core.indexes.apirrrr �pandas.core.seriesr!�pandas.core.sortingr"r#r$r%r&r'�collections.abcr(r)r*�pandas.core.genericr+r5r>r@r�rsr\rjr�r�r�r�r6r4�<module>r�s:���#�������*�)���.�2�����
(�'���&������,�>��D
�D
�NF(�F(�R]��]�@�'(�7�8�$�'(�T9�\�9�	8�L�	8�&��
�� ����
#��%�
����r6

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