Sindbad~EG File Manager

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

�

Mٜg��b�ddlmZddlZddlmZddlZddlmZddlZddlm	Z	m
Z
mZmZm
Z
ddlZddlZddlmZddlmZddlmZdd	lmZmZmZmZmZmZmZmZdd
l m!Z!ddl"m#Z#ddl$m%Z%dd
l&m'Z'ddl(m)Z)ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1m2Z2ddl3m4Z4m5Z5m6Z6ddl7m8Z8ddl9m:cm;Z<ddl=m>Z>e	r*ddl?m@Z@mAZAmBZBmCZCmDZDddlEmFZFmGZGmHZHddlImJZJddlKmLZLddlMmNZNeOePe
fZQ								d6																	d7d�ZRGd�dej���ZTGd�deT�ZUGd �deU�ZVGd!�d"eV�ZWGd#�d$eV�ZXGd%�d&eU�ZYGd'�d(eT�ZZGd)�d*eZ�Z[				d8d+�Z\d9d,�Z]				d:d-�Z^				d;d.�Z_										d<d/�Z`d=d0�Zad>d1�Zbd?d2�Zc				d@d3�ZddAd4�Ze								dBd5�Zfy)C�)�annotationsN)�defaultdict)�partial)�
TYPE_CHECKING�Any�Callable�Literal�cast)�option_context)�lib)�BlockValuesRefs)�AggFuncType�AggFuncTypeBase�AggFuncTypeDict�
AggObjType�Axis�AxisInt�NDFrameT�npt)�import_optional_dependency)�SpecificationError)�cache_readonly)�find_stack_level)�is_nested_object)�is_dict_like�is_extension_array_dtype�is_list_like�is_numeric_dtype�is_sequence)�CategoricalDtype�ExtensionDtype)�ABCDataFrame�
ABCNDFrame�	ABCSeries)�generate_apply_looper)�ensure_wrapped_if_datetimelike)�	Generator�Hashable�Iterable�MutableMapping�Sequence)�	DataFrame�Index�Series)�GroupBy)�	Resampler)�
BaseWindow�
FrameApplyc
��|j|�}|dk(rt}
n|dk(rt}
t|fi|	��\}}}}|�J�
|||||||||	��	S)z=construct and return a row or column based frame apply objectr�)�raw�result_type�by_row�engine�
engine_kwargs�args�kwargs)�_get_axis_number�
FrameRowApply�FrameColumnApply�reconstruct_func)�obj�func�axisr5r6r7r8r9r:r;�klass�_s            �</usr/local/lib/python3.12/site-packages/pandas/core/apply.py�frame_applyrFRsw������%�D��q�y���	
��� ��$�T�4�V�4�M�A�t�Q�������������#�
��
�
�c��eZdZUded<dddd�															dd�Zejdd��Zej				dd	��Zej				dd
��Z	dd�Z
dd�Zdd
�Zdd�Z
dd�Z								dd�Z				dd�Zdd�Z										d d�Z						d!d�Zdd�Zdd�Z								d"d�Zd#d�Zy)$�ApplyrrB�compat�pythonN�r7r8r9c���||_||_|dus|dvsJ�||_|xsd|_|	xsi|_||_|�in||_|dvrtd��||_||_	y)NF)rJ�_compat�)N�reduce�	broadcast�expandzUinvalid value for result_type, must be one of {None, 'reduce', 'broadcast', 'expand'})
r@r5r7r:r;r8r9�
ValueErrorr6rA)
�selfr@rAr5r6r7r8r9r:r;s
          rE�__init__zApply.__init__ys������������&�,A�"A�A�A�����J�B��	��l�������#0�#8�R�m����E�E��=��
�
'�����	rGc��y�NrO�rTs rE�applyzApply.apply����rGc��yrWrO�rT�op_names  rE�agg_or_apply_list_likezApply.agg_or_apply_list_like����	
rGc��yrWrOr\s  rE�agg_or_apply_dict_likezApply.agg_or_apply_dict_like�r_rGc��|j}|j}|j}|j}t	|t
�r|j
�St|�r|j�St|�r|j�St|�r9tj|�}|r"|s |st|||�t||��Sy)z�
        Provide an implementation for the aggregators.

        Returns
        -------
        Result of aggregation, or None if agg cannot be performed by
        this method.
        N)r@rAr:r;�
isinstance�str�	apply_strr�
agg_dict_liker�
agg_list_like�callable�com�get_cython_func�warn_alias_replacement�getattr)rTr@rAr:r;�fs      rE�aggz	Apply.agg�s����h�h���y�y���y�y�������d�C� ��>�>�#�#�����%�%�'�'�
�$�
��%�%�'�'��D�>��#�#�D�)�A���f�&�s�D�!�4�&�w�s�A��(�(�rGc���|j}|j}|j}|j}|j}|j
dk(}|j
|�dk(r/|rJ�|jj|dg|��i|��jSt|�r\t|�sQttt|�}|r(|D�cic]}tj|�xs||��}}n|D�cic]}||��}}t|�r!tt |�}|j#|�Stt|�}	|j%|�}	t-|	t.t0f�r#|	j2r|j2st+d��t-|	t.t0f�r%|	j4j7|j4�st+d��|	Scc}wcc}w#t&$r�t($r}
t+d�|
�d}
~
wwxYw)aI
        Transform a DataFrame or Series.

        Returns
        -------
        DataFrame or Series
            Result of applying ``func`` along the given axis of the
            Series or DataFrame.

        Raises
        ------
        ValueError
            If the transform function fails or does not transform.
        r4rzTransform function failedNzFunction did not transform)r@rArBr:r;�ndimr<�T�	transformrrr
�listrri�get_callable_namer�transform_dict_like�transform_str_or_callable�	TypeError�	ExceptionrSrcr$r"�empty�index�equals)rTr@rArBr:r;�	is_series�v�col�result�errs           rErrzApply.transform�s����h�h���y�y���y�y���y�y�������H�H��M�	�����%��*� � �=�"�3�5�5�?�?�4��<�T�<�V�<�>�>�>����l�4�&8���_�-�t�4�D��BF�G�$�Q��-�-�a�0�5�A�q�8�$��G�-0�1�S�c��T�	�S��1�������.�D��+�+�D�1�1��O�T�*��	C��3�3�D�9�F�
�v�	�<�8�9�����I�I��8�9�9�
�&�9�l�";�<�F�L�L�DW�DW��I�I�E
��9�:�:��
��EH��1���	���	C��8�9�s�B��	C�s$�!G�*
G
�3G�G2�!G-�-G2c�t�ddlm}|j}|j}|j}t|t�sJ�t|�dk(rtd��|jd||�}i}|j�D]2\}}|j|d��}	|	j|dg|��i|��||<�4||d��S)zC
        Compute transform in the case of a dict-like func
        r��concatz$No transform functions were providedrrr4�rp�rB)
�pandas.core.reshape.concatr�r@r:r;rcr#�lenrS�normalize_dictlike_arg�items�_gotitemrr)
rTrAr�r@r:r;�results�name�how�colgs
          rEruzApply.transform_dict_likes���	6��h�h���y�y�������#�z�*�*�*��t�9��>��C�D�D��*�*�;��T�B��68������I�D�#��<�<��1�<�-�D�*�D�N�N�3��C�D�C�F�C�G�D�M�&��g�A�&�&rGc�l�|j}|j}|j}t|t�r|j
||g|��i|��S|s7|s5t
j|�}|rt|||�t||��S	|j|fd|i|��S#t$r||g|��i|��cYSwxYw)zL
        Compute transform in the case of a string or callable func
        r:)r@r:r;rcrd�
_apply_strrirjrkrlrYrx)rTrAr@r:r;rms      rErvzApply.transform_str_or_callable's����h�h���y�y�������d�C� �"�4�?�?�3��>�t�>�v�>�>��F��#�#�D�)�A��&�s�D�!�4�&�w�s�A��(�(�	.��3�9�9�T�7��7��7�7���	.���-�d�-�f�-�-�	.�s�B�B3�2B3c�&�|jd��S)z�
        Compute aggregation in the case of a list-like argument.

        Returns
        -------
        Result of aggregation.
        rn�r])r^rXs rErgzApply.agg_list_like>����*�*�5�*�9�9rGc�\�ttt|j�}|j}g}g}|j
dk(r�|D]�}|j
|jd|��}	t||	�r|jg|j�n|j}
t|	|�|g|
��i|��}|j|�tj|�xs|}|j|���||fSg}
t|�D]�\}}|j
|d|j dd�|f��}	t||	�r|jg|j�n|j}
t|	|�|g|
��i|��}|j|�|
j|���|j"j%|
�}||fS)aF
        Compute agg/apply results for like-like input.

        Parameters
        ----------
        op_name : {"agg", "apply"}
            Operation being performed.
        selected_obj : Series or DataFrame
            Data to perform operation on.
        kwargs : dict
            Keyword arguments to pass to the functions.

        Returns
        -------
        keys : list[Hashable] or Index
            Index labels for result.
        results : list
            Data for result. When aggregating with a Series, this can contain any
            Python objects.
        r4)rp�subsetN)r
rsrrAr@rpr�r��include_axisrBr:rl�appendrirt�	enumerate�iloc�columns�take)rTr]�selected_objr;rAr@r��keys�ar�r:�new_resr��indicesrzr~s                rE�compute_list_likezApply.compute_list_likeHs���4�D��)�4�9�9�5���h�h����������!����|�|�L�$5�$5�A�l�|�S��$�G�T�2��Y�Y�+����+�����
1�'�$��0��D�T�D�V�D�����w�'��,�,�Q�/�4�1�����D�!��<�W�}���G�'��5�
��s��|�|�C�a��8I�8I�!�U�(�8S�|�T��$�G�T�2��Y�Y�+����+�����
1�'�$��0��G��G��G�����w�'����u�%�6� �'�'�,�,�W�5�D��W�}�rGc���ddlm}|j}	|||dd��S#t$r>}ddlm}||||j��}t|�rtd�|�|cYd}~Sd}~wwxYw)	Nrr�r4F)r�rB�sort�r.�rzr�z3cannot combine transform and aggregation operations)	r�r�r@rw�pandasr.r�rrS)rTr�r�r�r@r�r.rs        rE�wrap_results_list_likezApply.wrap_results_list_like�so��	6��h�h��	��'��1�5�A�A���
	�
&��G�4�c�h�h�?�F���'� �I�����M��
	�s� �	A'�3A"�A'�"A'c�&�|jd��S)z�
        Compute aggregation in the case of a dict-like argument.

        Returns
        -------
        Result of aggregation.
        rnr�)rarXs rErfzApply.agg_dict_like�r�rGc���ddlm}m}|j}t	|||f�}tt|j�}	|j|||	�}	|jdk(xr0|jj�t|j�k}
|jdk(rc|j|d��}|	j�D��
cgc]\}}
t||�|
fi|����}}}
t!|	j#��}||fS|s�|
r�g}g}|	j�D]�\}}
|jj%|g�}|jj'|�}t)t �}t+||�D]\}}||j-|��|j�D���cgc]0\}}|D]&}t|j/|d��|�|
fi|����(�2}}}}||gt|�zz
}||z
}��||fS|	j�D��
cgc])\}}
t|j|d��|�|
fi|����+}}}
t!|	j#��}||fScc}
}wcc}}}wcc}
}w)a�
        Compute agg/apply results for dict-like input.

        Parameters
        ----------
        op_name : {"agg", "apply"}
            Operation being performed.
        selected_obj : Series or DataFrame
            Data to perform operation on.
        selection : hashable or sequence of hashables
            Used by GroupBy, Window, and Resample if selection is applied to the object.
        kwargs : dict
            Keyword arguments to pass to the functions.

        Returns
        -------
        keys : list[hashable]
            Index labels for result.
        results : list
            Data for result. When aggregating with a Series, this can contain any
            Python object.
        r��DataFrameGroupBy�
SeriesGroupBy�r4r�r�)�pandas.core.groupby.genericr�r�r@rcr
rrAr�rpr��nuniquer�r�r�rlrsr��get_indexer_forr�r�zipr��_ixs)rTr]r��	selectionr;r�r�r@�
is_groupbyrA�is_non_unique_colr�rDr�r�r��keyr��labels�label_to_indicesrz�label�indice�key_datas                        rE�compute_dict_likezApply.compute_dict_like�s���:	
�
�h�h����&6�
�%F�G�
��O�T�Y�Y�/���*�*�7�L�$�G��
����"�
K��$�$�,�,�.��\�5I�5I�1J�J�	�
����!��<�<�	��<�2�D�KO�:�:�<�X�<���C�-�w�t�W�-�c�<�V�<�<�G�X���	�	��$�D�:�W�}��9� 1��G��D� �J�J�L���S�&�.�.�>�>��u�E��%�-�-�2�2�7�;��#.�t�#4� �$'���$8�L�E�5�$�U�+�2�2�5�9�%9�
+;�*@�*@�*B��*B���w�")��H�G�L�-�-�f�1�-�=�w�G��V�v�V�")�W�*B�������H�
�-�-���8�#��)�.�W�}��	!%�
�
��� ,�H�C��<�����S�q��1�7�;�C�J�6�J� ,�
����	�	��$�D��W�}���=Y����s�I�#5I 
�.I'c��ddlm}ddlm}|j}|D�cgc]}t|t���}}t|�r�tt||��}	|D�
cgc]}
|	|
jr�|
��}}
|gk7r|n|}|jdk(r/||�}|j|jj�|}t|t�rdnd}
||D�
cic]}
|
|	|
��
c}
|
|��}|St!|�rt#d��ddlm}|jdk(rt'd	|�}|j(}nd}||||�
�}|Scc}wcc}
wcc}
w)Nr�r-r�r�r4)rBr�zLcannot perform both aggregation and transformation operations simultaneouslyr�r.r�)r�r-r�r�r@rcr#�all�dictr�ryrp�
_set_namesr��namesr$�anyrSr.r
r�)rTr��result_index�result_datar-r�r@�r�
is_ndframer��k�keys_to_use�kturBrr.r�s                 rE�wrap_results_dict_likezApply.wrap_results_dict_like�sY��	!�5��h�h��:E�E��A�j��J�/��
�E��z�?��3�|�[�9�:�G�&2�K�l��'�!�*�:J�:J�1�l�K�K�)4��):�+��K�� � �A�%��K�(�����|�3�3�9�9�:�!��!+�C��!;�A��D��(3�4��1��G�A�J���4�� ��F�2�
�)��_��!��
�
&��x�x�1�}��8�S�)���x�x�����K�|�$�G�F��
��QF��
L��5s�E�E�/E�
Ec�p�tt|j�}|j}ddlm}m}t||d�}t|�r�tj|�}g|j�|j��}|jdk7rd|vs|dvrtd|�d���d|vrlt|||f�rEd}|dvr|jj}||jk7r3|j|j d<n|j|j d<|j"||g|j��i|j ��S)	zy
        Compute apply in case of a string.

        Returns
        -------
        result: Series or DataFrame
        rr�NrB)�corrwith�skewz
Operation z does not support axis=1)�idxmax�idxmin)r
rdrAr@r�r�r�rlrh�inspect�getfullargspecr:�
kwonlyargsrBrSrcr;r�)	rTrAr@r�r��method�sig�	arg_names�default_axiss	         rErezApply.apply_str.s���C����#���h�h��	
���d�D�)���F���(�(��0�C�4�#�(�(�4�S�^�^�4�I��y�y�A�~��i�'�4�3G�+G� �:�d�V�3K�!L�M�M���"��c�M�3C�#D�E�
$%�L��3�3�(,�x�x�}�}��#�t�y�y�0�.2�i�i����F�+�*.�)�)�D�K�K��'��t���s�D�D�4�9�9�D����D�DrGc���|jdk(rtd��|jdk(rlt|jt
�rR|jjj|jdfd|ji|j��jS|j}|j}t|�r|jd��}n|jd��}t||fi|��}|S)z�
        Compute apply in case of a list-like or dict-like.

        Returns
        -------
        result: Series, DataFrame, or None
            Result when self.func is a list-like or dict-like, None otherwise.
        �numbazIThe 'numba' engine doesn't support list-like/dict likes of callables yet.r4rr:rYr�)r8�NotImplementedErrorrBrcr@r"rqrYrAr:r;rrar^�reconstruct_and_relabel_result)rTrAr;rs    rE�apply_list_or_dict_likezApply.apply_list_or_dict_like]s����;�;�'�!�%�/��
�
�9�9��>�j����<�@�#�4�8�8�:�:�#�#�D�I�I�q�P�t�y�y�P�D�K�K�P�R�R�R��y�y����������0�0��0�A�F��0�0��0�A�F�/���G��G���
rGc��	�|dvsJ�|dk(r0t|t�r td�|j�D��s td�|j�D��rt	d��|j
dk7rfddlm}|t|j���j|jd	�
�}t|�dkDrtdt|��d���tttf�	t�	fd
�|j�D��r4i}|j�D]\}}t|�	�s|g||<�|||<�|}|S)a
        Handler for dict-like argument.

        Ensures that necessary columns exist if obj is a DataFrame, and
        that a nested renamer is not passed. Also normalizes to all lists
        when values consists of a mix of list and non-lists.
        )rYrnrrrnc3�8K�|]\}}t|����y�wrW)r��.0rDr}s   rE�	<genexpr>z/Apply.normalize_dictlike_arg.<locals>.<genexpr>�s����=����1�L��O����c3�8K�|]\}}t|����y�wrW)rr�s   rEr�z/Apply.normalize_dictlike_arg.<locals>.<genexpr>�s����;�l�d�a��,�q�/�l�r�znested renamer is not supportedr4rr�T)r�z
Column(s) z
 do not existc3�<�K�|]\}}t|�����y�wrW)rc)r�rD�x�aggregator_typess   �rEr�z/Apply.normalize_dictlike_arg.<locals>.<genexpr>�s�����H�<�4�1�a�z�!�-�.�<�s�)rcr$r�r�rrpr�r-rsr��
differencer�r��KeyError�tupler�)
rTr�r@rAr-�cols�new_funcr�r}r�s
         @rEr�zApply.normalize_dictlike_arg|s����3�3�3�3�
�5�L��3�	�*��=��
�
��=�=��;�d�j�j�l�;�;�$�%F�G�G��8�8�q�=�$���d�i�i�k�*�+�6�6�s�{�{��6�N�D��4�y�1�}���D��J�<�}�E�F�F� �%��.���H�4�:�:�<�H�H�(*�H��
�
����1�!�!�%5�6�#$�#�H�Q�K�"#�H�Q�K�	%�
�D��rGc��t|t�sJ�t||�rTt||�}t	|�r||i|��St|�dk(sJ�t|D�cgc]	}|dvs�|��c}�dk(sJ�|Stt|�r(t|d�rtt|�}||g|��i|��Sd|�dt|�j�d�}t|��cc}w)z�
        if arg is a string, then try to operate on it:
        - try to find a function (or attribute) on obj
        - try to find a numpy function
        - raise
        rr��	__array__�'z' is not a valid function for 'z' object)
rcrd�hasattrrlrhr��np�type�__name__�AttributeError)rTr@rAr:r;rm�kwarg�msgs        rEr�zApply._apply_str�s����$��$�$�$��3�����T�"�A���{��$�)�&�)�)��t�9��>�!�>��6�K�6�%�U�(�5J��6�K�L�PQ�Q�Q�Q��H�
�R��
�7�3��#<���D�!�A��S�*�4�*�6�*�*��d�V�:�4��9�;M�;M�:N�h�W�C� ��%�%��Ls�	C�!C)r@rrArr5�boolr6�
str | Noner7�#Literal[False, 'compat', '_compat']r8rdr9�dict[str, bool] | None�return�None�r��DataFrame | Series�r]�Literal['agg', 'apply']r�r�)r�zDataFrame | Series | None)r�r,)r]r�r��Series | DataFramer;�dict[str, Any]r�z(tuple[list[Hashable] | Index, list[Any]])r��Iterable[Hashable]r�zlist[Series | DataFrame])
r]r�r�rr�zHashable | Sequence[Hashable]r;rr�z tuple[list[Hashable], list[Any]])r�rr�zlist[Hashable]r�rs)r�rdr@r�rArr�r)rArd)r��
__module__�__qualname__�__annotations__rU�abc�abstractmethodrYr^rarnrrrurvrgr�r�rfr�r�rer�r�r�rOrGrErIrIvs���
�M�7?��04�!�
�!��!��	!�
 �!�4�!��!�.�!�
�!�F	���
��
�	���
�.�
�	�
��
�
	���
�.�
�	�
��
�
�@A�F'�0.�.:�@�(�@�)�@��	@�

2�@�D�&��1I��*:�M�(�M�)�M�1�	M�
�M�
*�
M�^4�(�4�%�4��	4�l-E�^�>+��+�/�+�7F�+�	�+�Z&rGrI)�	metaclassc�`�eZdZUdZded<ed	d��Zed	d��Z				d
d�Z				d
d�Z	y)�NDFrameApplyzg
    Methods shared by FrameApply and SeriesApply but
    not GroupByApply or ResamplerWindowApply
    r�r@c�.�|jjSrW)r@rzrXs rErzzNDFrameApply.index�s���x�x�~�~�rGc�L�|jj|j�SrW)r@�
_get_agg_axisrBrXs rE�agg_axiszNDFrameApply.agg_axis�s���x�x�%�%�d�i�i�0�0rGc�V�|j}|j}|dk(rHt|t�r
|j}n#t|t
�r|jrdnd}nd}i|�d|i�}t
|dd�dk(rtd��|j|||�\}}|j||�}|S)	NrYrNFr7rBrr4�"axis other than 0 is not supported)
r@r;rcr2r7�SeriesApplyrlr�r�r�)rTr]r@r;r7r�r�rs        rEr^z#NDFrameApply.agg_or_apply_list_like�s����h�h�������g���$�
�+������D�+�.�&*�k�k��u����1��1��&�1�F��3���"�a�'�%�&J�K�K��.�.�w��V�D�
��g��,�,�T�7�;���
rGc��|dvsJ�|j}i}|dk(r#|jrdnd}|jd|i�t|dd�dk(rt	d	��d}|j||||�\}}|j
|||�}|S)
N�rnrYrYrNFr7rBrr4r)r@r7�updaterlr�r�r�)	rTr]r@r;r7r�r�r�rs	         rEraz#NDFrameApply.agg_or_apply_dict_like�s����*�*�*�*��h�h�����g��"&�+�+�Y�5�F��M�M�8�V�,�-��3���"�a�'�%�&J�K�K��	�$(�$:�$:��S�)�V�%
�!��k��,�,�S�,��L���
rGN�r�r-r�)
r�rr�__doc__r�propertyrzrr^rarOrGrEr
r
�s_���

��
�����1��1��.��	��.�.��	�rGr
c���eZdZUded<dddd�															d�fd�Zeejdd���Zeejdd	���Z	eejdd
���Z
eejej	d	d d����Zejd��Zd
�Zej						d!d��Zedd��Zedd��Zed��Zd"d�Z�fd�Zd�Zd#d�Zd$d�Zd�Zd%d�Zd�Zd!d�Zd"�fd�Z�xZ S)&r2r,r@FrKNrLc�f��|dur|dk7rtd|�d���t�
|�	|||||||||	��	y)NFrJzby_row=z not allowed)r7r8r9r:r;)rS�superrU)rTr@rAr5r6r7r8r9r:r;�	__class__s          �rErUzFrameApply.__init__sU������6�X�#5��w�v�h�l�;�<�<�
���������'���	�
	
rGc��yrWrOrXs rEr�zFrameApply.result_index#���	
rGc��yrWrOrXs rE�result_columnszFrameApply.result_columns(rrGc��yrWrOrXs rE�series_generatorzFrameApply.series_generator-rrGc��yrWrO)rA�nogil�nopython�parallels    rE�generate_numba_apply_funcz$FrameApply.generate_numba_apply_func2s��	
rGc��yrWrOrXs rE�apply_with_numbazFrameApply.apply_with_numba:rZrGc���|jjj�D]<\}}t|�st	d|�d|�d���t|�s�/t	d|�d���y)NzColumn z# must have a numeric dtype. Found 'z	' insteadzM is backed by an extension array, which is not supported by the numba engine.)r@�dtypesr�rrSr)rT�colname�dtypes   rE�validate_values_for_numbaz$FrameApply.validate_values_for_numba>sx��"�h�h�o�o�3�3�5�N�G�U�#�E�*� ��g�Y�'�#�W�I�/���(��.� ��g�Y�'B�C���6rGc��yrWrO�rTr��	res_indexs   rE�wrap_results_for_axisz FrameApply.wrap_results_for_axisLr_rGc��|jSrW)rrXs rE�res_columnszFrameApply.res_columnsTs���"�"�"rGc�.�|jjSrW)r@r�rXs rEr�zFrameApply.columnsXs���x�x���rGc�.�|jjSrW)r@�valuesrXs rEr6zFrameApply.values\s���x�x���rGc�v�t|j�r*|jdk(rtd��|j	�St|j�dk(r(t|j�dk(r|j�St|jt�r*|jdk(rtd��|j�St|jtj�r�|jdk(rtd��tjd��5|jj j#d|j�	�}d
d
d
�|jj%|j&��S|j(dk(r5|jdk(rtd
��|j+|j�St-|jj.�s|j�S|j0r'|j3|j|j4��S|j7�S#1swY��xYw)zcompute the resultsr�z9the 'numba' engine doesn't support lists of callables yetrzJthe 'numba' engine doesn't support using a string as the callable functionzOthe 'numba' engine doesn't support using a numpy ufunc as the callable function�ignore�r�rY)rAN)�axesrQz:the 'numba' engine doesn't support result_type='broadcast'�r8r9)rrAr8r�r�r�r�rz�apply_empty_resultrcrdrer��ufunc�errstater@�_mgrrY�_constructor_from_mgrr:r6�apply_broadcastr��shaper5�	apply_rawr9�apply_standard�rTr�s  rErYzFrameApply.apply`s�����	�	�"��{�{�g�%�)�O����/�/�1�1��t�|�|���!�c�$�*�*�o��&:��*�*�,�,��d�i�i��%��{�{�g�%�)�8����>�>�#�#���	�	�2�8�8�
,��{�{�g�%�)�C�������*��(�(�-�-�-�-�g�D�I�I�-�F��+��8�8�1�1�'����1�M�M����{�*��{�{�g�%�)�P����'�'����1�1��T�X�X�^�^�$��*�*�,�,��X�X��>�>����D�DV�DV�>�W�W��"�"�$�$�++�*�s�2H/�/H8c���|j}|j}|jdk(r|jn|jj|_d|_d}	t�|��}||_||_|dk(r|�|jn|}|�>|jj
|j|fd|ji|j��}|S#||_||_wxYw)Nrr4r:)	r@rBrqrrnrYrAr:r;)rTr@rBrrs    �rErnzFrameApply.agg�s�����h�h���y�y�� $�y�y�A�~�4�8�8�4�8�8�:�:�����	���	��W�[�]�F��D�H��D�I��1�9�!'�!3�V�X�X��F��>�#�T�X�X�^�^�D�I�I�t�S�$�)�)�S�t�{�{�S�F��
���D�H��D�I�s�C
�
Cc�n�t|j�sJ�|jdvr|jj	�S|jdk(}ddlm}|s�	|jdk(rA|j|gtj��g|j��i|j��}nJ|j||jtj��g|j��i|j��}t||�}|r�t|j �rA|j|gtj��g|j��i|j��}ntj"}|jj%||j ��S|jj	�S#t$rY��wxYw)z�
        we have an empty result; at least 1 axis is 0

        we will try to apply the function to an empty
        series in order to see if this is a reduction function
        )rPNrPrr��r,)rzr,�rz)rhrAr6r@�copyr�r.rBr��float64r:r;r�rcrxr�r�nan�_constructor_sliced)rT�
should_reducer.r�s    rEr<zFrameApply.apply_empty_result�sk����	�	�"�"�"����#3�3��8�8�=�=�?�"��(�(�H�4�
�!��
:��9�9��>�!��	�	��r����4��7;�y�y��DH�K�K��A�"��	�	��T�\�\����D�������+�+��A�%/�q�&�$9� 9�
���4�=�=�!��D�I�I�f�R�r�z�z�:�V�T�Y�Y�V�$�+�+�V���F�F���8�8�/�/�����/�G�G��8�8�=�=�?�"���
��
�s�BF(�(	F4�3F4c�&�d�}|dk(rO|�in|}t|jfi|��}||j|j�}t	j
|�}nSt	j||j�|j|jg|j��i|j��}|jdk(r2|jj||j|j��S|jj||j��S)z$apply to the values as a numpy arrayc����fd�}|S)z�
            Wrap user supplied function to work around numpy issue.

            see https://github.com/numpy/numpy/issues/8352
            c�n���|i|��}t|t�rtj|t��}|S)NrH)rcrdr��array�object)r:r;rrAs   �rE�wrapperz<FrameApply.apply_raw.<locals>.wrap_function.<locals>.wrapper�s1����t�.�v�.���f�c�*��X�X�f�F�;�F��
rGrO)rArTs` rE�
wrap_functionz+FrameApply.apply_raw.<locals>.wrap_function�s���
��NrGr�r��rzr�rI)r%rAr6rBr��squeeze�apply_along_axisr:r;rpr@�_constructorrzr�rMr)rTr8r9rU�	nb_looperrs      rErCzFrameApply.apply_raw�s���
	��W��"/�"7�B�]�M�.��	�	��*��I��t�{�{�D�I�I�6�F��Z�Z��'�F��(�(��d�i�i�(��	�	��������	�
�+�+��F��;�;�!���8�8�(�(��t�z�z�4�<�<�(�X�X��8�8�/�/��d�m�m�/�L�LrGc�4�t|j�sJ�tj|j�}|j
d}t
|j�D]�\}}|j||g|j��i|j��}tj|�j}|dkDrtd��|dk(r|t|�k7rtd��||dd�|f<��|jj||j |j��}|S)Nrr4ztoo many dims to broadcastzcannot broadcast resultrV)rhrAr��
empty_liker6rBr�r�r:r;�asarrayrprSr�r@rYrz)	rT�target�
result_values�result_compare�ir~�res�aresrs	         rErAzFrameApply.apply_broadcast	s�����	�	�"�"�"��
�
�f�m�m�4�
� ���a�������/�F�A�s��$�)�)�F�3�K�C�$�)�)�C�t�{�{�C�C��:�:�c�?�'�'�D��a�x� �!=�>�>��q�y�!�S��X�-�$�%>�?�?�"%�M�!�Q�$��0����&�&�����v�~�~�'�
���
rGc��|jdk(r|j�\}}n|j�\}}|j||�S)NrK)r8�apply_series_generator�apply_series_numba�wrap_resultsr/s   rErDzFrameApply.apply_standard%sI���;�;�(�"�!%�!<�!<�!>��G�Y�!%�!8�!8�!:��G�Y�� � ��)�4�4rGc��t|j�sJ�|j}|j}i}t	dd�5t|�D]^\}}|j|g|j��i|j��||<t||t�s�G||jd��||<�`	ddd�||fS#1swY||fSxYw)Nzmode.chained_assignmentF)�deep)rhrAr!r�rr�r:r;rcr$rJ)rT�
series_genr0r�rar}s      rErez!FrameApply.apply_series_generator.s�����	�	�"�"�"��*�*�
��%�%�	���
�5�t�
<�!�*�-���1�&�T�Y�Y�q�D�4�9�9�D����D���
��g�a�j�)�4�")�����e��!<�G�A�J�
.�=��	�!�!�=��	�!�!�s�AB8�B8�8Cc�.�|jjdd�rtd��|jjj
r|jj
std��|j�|j�}||jfS)Nr%FzAParallel apply is not supported when raw=False and engine='numba'zBThe index/columns must be unique when raw=False and engine='numba')
r9�getr�r@rz�	is_uniquer�r-r(r�rEs  rErfzFrameApply.apply_series_numbaAs������!�!�*�e�4�%�S��
��x�x�~�~�'�'�t�|�|�/E�/E�%�T��
�	
�&�&�(��'�'�)����)�)�)�)rGc��ddlm}t|�dkDr$d|vr t|d�r|j	||�S|j
j}t|�dk(r||ur||tj��}n||�}||_	|S)Nrr�rH)
r�r.r�rr1r@rMr�rKrz)rTr�r0r.�constructor_slicedrs      rErgzFrameApply.wrap_resultsNs���!��w�<�!���W���W�Q�Z�1H��-�-�g�y�A�A�"�X�X�9�9���w�<�1��!3�v�!=�'��r�z�z�B�F�'��0�F� ����
rGc����|jdk(rB|j}|j|j}|j	||j
��St�|��S)N�sizerI)rAr@rBrBrMrrre)rTr@�valuers   �rErezFrameApply.apply_strcsT����9�9����(�(�C��I�I�d�i�i�(�E��*�*�5��
�
�*�F�F��w� �"�"rG)r@rrArr5r�r6r�r7�Literal[False, 'compat']r8rdr9r�r�r�r�r�zGenerator[Series, None, None]�TTF�r�z5Callable[[npt.NDArray, Index, Index], dict[int, Any]]�r��ResTyper0r-r�r�r�)rKN�r^r,r�r,)r�ztuple[ResType, Index])!r�rrrrUrrrr�rr!�staticmethod�	functools�cacher&r(r-r1r3r�rr6rYrnr<rCrArDrerfrgre�
__classcell__�rs@rEr2r2s����	�N�,1��04�
�
�
��
��	
�
 �
�)�
��
�.�
�
�
�<����
���
�����
���
�����
���
���_�_����27�
�	>�
����
�
	���
��
��	���
��
�+0�
�	�
��
��#��#�� �� �����4%�l�.,#�\,M�\�85�"�&*��*#�#rGc��eZdZUdZded<edd��Zeej	d	d
d���Z
dd�Zedd��Zedd��Z
						dd	�Zy
)r=rrrBc�R���fd�tt�j��D�S)Nc3�X�K�|]!}�jj|d�����#y�w)r4r�N)r@r�)r�rarTs  �rEr�z1FrameRowApply.series_generator.<locals>.<genexpr>ss%�����K�2J�Q����
�
�a�a�
�(�2J�s�'*)�ranger�r�rXs`rEr!zFrameRowApply.series_generatorqs���K�%��D�L�L�8I�2J�K�KrGc�����td�}ddlm�ddlm�|j
j
|��|j|||�����fd��}|S)Nr�rr���maybe_cast_str�r#r$r%c	���i}t|jd�D](}�|dd�|f|�||���}�|�||<�*|S)Nr4r�)r�rB)	r6�	col_names�df_indexr��j�serr.�
jitted_udfr�s	      ���rE�
numba_funcz;FrameRowApply.generate_numba_apply_func.<locals>.numba_func�sX����G��6�<�<��?�+����1�a�4�L��~�i�PQ�l�7S���(��_���
�,��NrG�rr�r.�pandas.core._numba.extensionsr��	extending�register_jitable�jit�	rAr#r$r%r�r�r.r�r�s	      @@@rEr&z'FrameRowApply.generate_numba_apply_funcusX���
+�7�3��!�	A��_�_�5�5�d�;�
�
�����H��	E�	�
F�	��rGc	��|jtt|j�fi|j��}ddlm}|jj}|jdk(r|jt�}|jj}|jdk(r|jt�}||�5}||�5}t||j||��}ddd�ddd�S#1swY�xYw#1swYSxYw)Nr��set_numba_data�string)r&r
rrAr9r�r�r@rzr,�astyperSr�r�r6�rT�nb_funcr�rzr�rbs      rEr(zFrameRowApply.apply_with_numba�s���0�$�0�0���4�9�9�%�
�)-�);�);�
��	A��������;�;�(�"��L�L��(�E��(�(�"�"���=�=�H�$��n�n�V�,�G��E�
"�e�^�G�-D���w�t�{�{�G�U�;�<�C�.E�
"��
�.E�-D��
"��
�s$�8	C=�C1�C=�1C:	�6C=�=Dc��|jSrW�r�rXs rEr�zFrameRowApply.result_index�����|�|�rGc��|jSrWrIrXs rErzFrameRowApply.result_columns�����z�z�rGc���|jdk(r$|jj|�}||_|S|j�Dt	d�|j�D��r$|jj|�}||_|S	|jj
|��}t|dt�s<t|j�t|j�k(r|j|_t|j�t|�k(r||_
|S#t$r<}dt|�vr)|jj|�}||_|cYd}~S�d}~wwxYw)zreturn the results for the rowsrPNc3�<K�|]}t|t����y�wrW)rcr�)r�r�s  rEr�z6FrameRowApply.wrap_results_for_axis.<locals>.<genexpr>�s����.
�)9�A�J�q�$��)9�s���dataz%All arrays must be of the same lengthr)r6r@rMrzr�r6rYrSrdrcr$r�r3r�)rTr�r0rbrr�s      rEr1z#FrameRowApply.wrap_results_for_axis�s4��
���x�'��(�(�.�.�w�7�C�!�C�I��J�
�
�
�
%�#�.
�)0���)9�.
�+
�
�(�(�.�.�w�7�C�!�C�I��J�
	��X�X�*�*��*�8�F��'�!�*�i�0��6�<�<� �C��(8�(8�$9�9�#�/�/����v�~�~��#�i�.�0�&�F�N��
��#�	�6�#�c�(�B��h�h�2�2�7�;��%��	��
���	�s$�D�	E�#0E�E�E�ENrtrurv�r�zdict[int, Any]rrw)r�rrrBrrr!rzr{r|r&r(r�rr1rOrGrEr=r=ns����D�'��
�L��L���_�_�27��	>�����6�(��������'��'�+0�'�	�'rGr=c���eZdZUdZded<d�fd�Zed
d��Zee	j	d	dd���Zdd�Zedd��Z
edd	��Z						dd
�Zdd�Z�xZS)r>r4rrBc�N��t�|�|j�}|jSrW)rrArq)rTr^rrs   �rErAz FrameColumnApply.apply_broadcast�s�����(����2���x�x�rGc#�K�|j}t|�}t|�dkDsJ�|jj	dd��}|j
}|jdjj�}t|jt�r;|j}tt|��D]}|j	|d�����yt||j�D]d\}}||_|j|�t j#|d|�|s*t%|jd�|jd_|���fy�w)Nrr��_name)r6r&r�r@r�r?�blocks�refs�
has_referencercr,r!r�r�rz�
set_valuesrS�__setattr__r
)	rTr6r��mgr�is_viewr@ra�arrr�s	         rEr!z!FrameColumnApply.series_generator�s��������/��7���6�{�Q�����h�h�m�m�A�A�m�&���h�h���*�*�Q�-�$�$�2�2�4���c�i�i��0��(�(�C��3�s�8�_���h�h�q�q�h�)�)�%�!�����4�	��T�������s�#��"�"�3���6��*9����A��)G�C�J�J�q�M�&��	�5�s�EE
c�����td�}ddlm�ddlm�|j
j
|��|j|||�����fd��}|S)Nr�rr�r�r�c	���i}t|jd�D]2}�||j�|�||���}�|�||<�4|S)Nrr�)r�rBrJ)	r6�col_names_indexrzr�rar�r.r�r�s	      ���rEr�z>FrameColumnApply.generate_numba_apply_func.<locals>.numba_funcs`����G��6�<�<��?�+����1�I�N�N�$�)�'��a��1���
(��_���
�,��NrGr�r�s	      @@@rEr&z*FrameColumnApply.generate_numba_apply_funcsS���
+�7�3��!�@��_�_�5�5�d�;�
�	�����H��	E�	�
F�	� �rGc	�h�|jtt|j�fi|j��}ddlm}||jj�5}||j�5}t||j||��}ddd�ddd�S#1swY�xYw#1swYSxYw)Nrr�)r&r
rrAr9r�r�r@rzr�r�r6r�s      rEr(z!FrameColumnApply.apply_with_numba!s���0�$�0�0���4�9�9�%�
�)-�);�);�
��	A��D�H�H�N�N�
+�u�n��L�L�7
�
��w�t�{�{�G�U�;�<�C�7
�
+�
�
�7
�7
��
+�
�
�s$�B'�+B�	B'�B$	� B'�'B1c��|jSrWrIrXs rEr�zFrameColumnApply.result_index1r�rGc��|jSrWr�rXs rErzFrameColumnApply.result_columns5r�rGc���|jdk(r|j||�}|St|dt�s$|jj|�}||_|S|j||�}|S)z"return the results for the columnsrRr)r6�infer_to_same_shapercr$r@rMrz�rTr�r0rs    rEr1z&FrameColumnApply.wrap_results_for_axis9sv�����x�'��-�-�g�y�A�F��
��G�A�J�	�2��X�X�1�1�'�:�F�$�F�L��
��-�-�g�y�A�F��
rGc��|jj|��}|j}||_|j	d��}|S)z7infer the results to the same shape as the input objectr�F�rJ)r@rYrqrz�
infer_objectsr�s    rEr�z$FrameColumnApply.infer_to_same_shapeNsE�����&�&�G�&�4������!����%�%�5�%�1���
rGryrtrurvr�rrw)r�rxr0r-r�r,)r�rrrBrrArr!rzr{r|r&r(r�rr1r�r}r~s@rEr>r>�s�����D�'����!��!�F��_�_�27��	>�����8� �����������+0��	��*rGr>c���eZdZUded<dZded<ded<ejdd	�									d�fd
�Zdd�Z�fd�Z	dd
�Z
d�Zdd�Z�xZ
S)rr.r@rrrBr�r7rJ)�
convert_dtyper7c	���|tjurd}n$tjdtt���||_t�|�!||dd|||��y)NTz�the convert_dtype parameter is deprecated and will be removed in a future version.  Do ``ser.astype(object).apply()`` instead if you want ``convert_dtype=False``.��
stacklevelF)r5r6r7r:r;)	r�
no_default�warnings�warn�
FutureWarningrr�rrU)rTr@rAr�r7r:r;rs       �rErUzSeriesApply.__init__asc����C�N�N�*� �M��M�M�?��+�-�
�+���
����������	�	
rGc�R�|j}t|�dk(r|j�St|j�r|j�St
|jt�r|j�S|jdk(r|j�S|j�S)NrrN)r@r�r<rrAr�rcrdrer7�apply_compatrD�rTr@s  rErYzSeriesApply.apply�s����h�h���s�8�q�=��*�*�,�,���	�	�"��/�/�1�1��d�i�i��%��>�>�#�#��;�;�)�#��$�$�&�&��"�"�$�$rGc����t�|��}|��|j}|j}t	|�sJ�	|j
|fd|ji|j��}d|�dt|�j�dt|�j�d�}tj|tt���|S|S#ttt f$r$||g|j��i|j��}Y|SwxYw)Nr:zusing z in z3.agg cannot aggregate and has been deprecated. Use z&.transform to keep behavior unchanged.r�)rrnr@rArhrYr:r;r�r�r�r�r�rrSr�rw)rTrr@rAr�rs     �rErnzSeriesApply.agg�s����������>��(�(�C��9�9�D��D�>�!�>�


Q�"����4�G�d�i�i�G�4�;�;�G��
�T�F�$�t�C�y�'9�'9�&:�;0�04�S�	�0B�0B�/C�D/�0��
�
�
�c�=�=M�=O�P��
�v�
����	�:�
>��c�=�D�I�I�=����=���
�
>�s�)B;�;4C3�2C3c��|j}|j|j|j��j	|d��S)N)r,rzrY�r�)r@rYr,rz�__finalize__r�s  rEr<zSeriesApply.apply_empty_result�sA���h�h�����c�i�i�s�y�y��A�N�N���O�
�	
rGc�T�|j}|j}t|�rBtj|�}|r+|j
s|js|j|d��S	|j|d��}|S#tttf$r|j|d��}Y|SwxYw)z�compat apply method for funcs in listlikes and dictlikes.

         Used for each callable when giving listlikes and dictlikes of callables to
         apply. Needed for compatibility with Pandas < v2.1.

        .. versionadded:: 2.1.0
        F)r7rJ)r@rArhrirjr:r;rYrSr�rw)rTr@rArmrs     rEr�zSeriesApply.apply_compat�s����h�h���y�y���D�>��#�#�D�)�A�����4�;�;��y�y��e�y�4�4�	3��Y�Y�t�H�Y�5�F��
���N�I�6�	3��Y�Y�t�E�Y�2�F��
�	3�s�'A<�<'B'�&B'c����tt�j���j}t	�t
j�r@tjd��5�|g�j��i�j��cddd�S�js �|g�j��i�j��S�js�jr��fd�}n�}t	|jt�rdnd}|j||�j��}t|�r9t	|dt �r&|j#t%|�|j&��S|j)||j&��j+|d��S#1swY��xYw)	Nr8r9c�D���|g�j��i�j��SrW)r:r;)r�rArTs ��rE�curriedz+SeriesApply.apply_standard.<locals>.curried�s ����A�9��	�	�9�T�[�[�9�9rG)�mapper�	na_action�convertrrIrYr�)r
rrAr@rcr�r=r>r:r;r7r,r �_map_valuesr�r�r$�_constructor_expanddimrsrzrYr�)rTr@r��action�mappedrAs`    @rErDzSeriesApply.apply_standard�s=����H�d�i�i�(���h�h���d�B�H�H�%�����*��C�;�$�)�)�;�t�{�{�;�+�*������7�d�i�i�7�4�;�;�7�7��9�9����
:��G�(��	�	�3C�D��$������f�d�6H�6H�!�
���v�;�:�f�Q�i��;��-�-�d�6�l�#�)�)�-�L�L��#�#�F�#�)�)�#�<�I�I��G�J��
�9+�*�s� E>�>F)
r@r.rArr�zbool | lib.NoDefaultr7r�r�r�r�)r�r.)r�rrrrBrr�rUrYrnr<r�rDr}r~s@rErr\ss���	�K��D�'��/�/�/2�n�n�6>�

�
�
��
�
,�
�4�

�
�
�@%�(�2
��,$rGrc�d��eZdZUded<						d�fd�Zd�Zd�Z				d	d�Z				d	d�Z�xZ	S)
�GroupByApplyz GroupBy | Resampler | BaseWindowr@c���|j�}|jj|jdd��|_t
�|�||dd||��y)NrBrF�r5r6r:r;)rJr@r<rlrBrrU�rTr@rAr:r;rs     �rErUzGroupByApply.__init__�sU���������G�G�,�,�V�Z�Z���-B�C��	�
���������
	�	
rGc��t�rW�r�rXs rErYzGroupByApply.apply���!�!rGc��t�rWr�rXs rErrzGroupByApply.transform
r�rGc	��|j}|j}|dk(ri|�ddi�}t|dd�dk(rtd��|jj
dk(r
|j}n|j}tj|dd	t|d��
�5|j|||�\}}ddd�|j�}|S#1swY�xYw)NrYr7FrBrr4r�as_indexT��	condition)r@r;rlr��
_selected_objrp�_obj_with_exclusionsri�temp_setattrr�r�r�)rTr]r@r;r�r�r�rs        rEr^z#GroupByApply.agg_or_apply_list_like
s����h�h�������g��0��0��%�0�F��3���"�a�'�%�&J�K�K����!�!�Q�&��,�,�L��3�3�L��
�
���T�W�S�*�-E�
�!�2�2�7�L�&�Q�M�D�'�
��,�,�T�7�;���
�
�
�s�C	�	Cc	�p�ddlm}m}|dvsJ�|j}i}|dk(r#|jrdnd}|jd|i�t
|dd�d	k(rtd
��|j}|j}t|||f�}	|	rL|jjdd�}
|jjdd�}|j|
|d
��tj|ddt|d���5|j!||||�\}}
ddd�|j#|
�}|S#1swY�xYw)Nrr�rrYrNFr7rBr4rr8r9r;r�Tr�)r�r�r�r@r7rrlr�r��
_selectionrcr;rlrir�r�r�r�)rTr]r�r�r@r;r7r�r�r�r8r9r�r�rs               rEraz#GroupByApply.agg_or_apply_dict_like's6��	
�
�*�*�*�*��h�h�����g��"&�+�+�Y�5�F��M�M�8�V�,�-��3���"�a�'�%�&J�K�K��(�(���N�N�	���&6�
�%F�G�
���[�[�_�_�X�t�4�F� �K�K�O�O�O�T�B�M��M�M�V�m�L�M�
�
�
���T�W�S�*�-E�
�)-�(>�(>���y�&�)�%�L�+�
��,�,�\�<��U���
�
�
�s�7D,�,D5)r@zGroupBy[NDFrameT]rArr�r�r�)
r�rrrrUrYrrr^rar}r~s@rEr�r��s^���	)�)�
�
�
��
�
�
�&"�"��.��	��4%�.�%�	�%rGr�c�R��eZdZUdZded<ded<						d	�fd�Zd�Zd�Z�xZS)
�ResamplerWindowApplyrrrB�Resampler | BaseWindowr@c�8��tt|�||dd||��y)NFr�)rr�rUr�s     �rErUzResamplerWindowApply.__init__Ss+���	�l�D�*�������
	+�	
rGc��t�rWr�rXs rErYzResamplerWindowApply.applydr�rGc��t�rWr�rXs rErrzResamplerWindowApply.transformgr�rG)r@r�rArr�r�)	r�rrrBrrUrYrrr}r~s@rEr�r�Os>����D�'��	��
�
#�
��
�
�
�""�"rGr�c��|duxrtdi|��}d}d}|sHt|t�r+t|�tt	|��kDrtd��|�t
d��|rt|�\}}}|�J�||||fS)a�
    This is the internal function to reconstruct func given if there is relabeling
    or not and also normalize the keyword to get new order of columns.

    If named aggregation is applied, `func` will be None, and kwargs contains the
    column and aggregation function information to be parsed;
    If named aggregation is not applied, `func` is either string (e.g. 'min') or
    Callable, or list of them (e.g. ['min', np.max]), or the dictionary of column name
    and str/Callable/list of them (e.g. {'A': 'min'}, or {'A': [np.min, lambda x: x]})

    If relabeling is True, will return relabeling, reconstructed func, column
    names, and the reconstructed order of columns.
    If relabeling is False, the columns and order will be None.

    Parameters
    ----------
    func: agg function (e.g. 'min' or Callable) or list of agg functions
        (e.g. ['min', np.max]) or dictionary (e.g. {'A': ['min', np.max]}).
    **kwargs: dict, kwargs used in is_multi_agg_with_relabel and
        normalize_keyword_aggregation function for relabelling

    Returns
    -------
    relabelling: bool, if there is relabelling or not
    func: normalized and mangled func
    columns: tuple of column names
    order: array of columns indices

    Examples
    --------
    >>> reconstruct_func(None, **{"foo": ("col", "min")})
    (True, defaultdict(<class 'list'>, {'col': ['min']}), ('foo',), array([0]))

    >>> reconstruct_func("min")
    (False, 'min', None, None)
    NzFFunction names must be unique if there is no new column names assignedz4Must provide 'func' or tuples of '(column, aggfunc).rO)�is_multi_agg_with_relabelrcrsr��setrrw�normalize_keyword_aggregation)rAr;�
relabelingr��orders     rEr?r?ks���N���E�";�"E�f�"E�J�&*�G�)-�E���d�D�!�c�$�i�#�c�$�i�.�&@�%���
��<��R�S�S�� =�� 
���g�u������t�W�e�+�+rGc�b�td�|j�D��xrt|�dkDS)ax
    Check whether kwargs passed to .agg look like multi-agg with relabeling.

    Parameters
    ----------
    **kwargs : dict

    Returns
    -------
    bool

    Examples
    --------
    >>> is_multi_agg_with_relabel(a="max")
    False
    >>> is_multi_agg_with_relabel(a_max=("a", "max"), a_min=("a", "min"))
    True
    >>> is_multi_agg_with_relabel()
    False
    c3�\K�|]$}t|t�xrt|�dk(���&y�w)r�N)rcr�r�)r�r}s  rEr�z,is_multi_agg_with_relabel.<locals>.<genexpr>�s(����M�_��z�!�U�#�3��A��!��3�_�s�*,r)r�r6r�)r;s rEr�r��s-��*�M�V�]�]�_�M�M���F��a��rGc
��ddlm}tt�}g}tt	|j���\}}|D]C\}}||j
|�|j
|tj|�xs|f��Et|�}|j�D��	�cgc]'\}}	|	D]}|tj|�xs|f���)}
}	}}t|
�}||�j|�}|||fScc}}	}w)aR
    Normalize user-provided "named aggregation" kwargs.
    Transforms from the new ``Mapping[str, NamedAgg]`` style kwargs
    to the old Dict[str, List[scalar]]].

    Parameters
    ----------
    kwargs : dict

    Returns
    -------
    aggspec : dict
        The transformed kwargs.
    columns : tuple[str, ...]
        The user-provided keys.
    col_idx_order : List[int]
        List of columns indices.

    Examples
    --------
    >>> normalize_keyword_aggregation({"output": ("input", "sum")})
    (defaultdict(<class 'list'>, {'input': ['sum']}), ('output',), array([0]))
    rr�)�pandas.core.indexes.baser-rrsr�r�r�rirt�_make_unique_kwarg_list�get_indexer)
r;r-�aggspecr�r��pairs�column�aggfunc�uniquified_order�aggfuncs�
aggspec_order�uniquified_aggspec�
col_idx_orders
             rEr�r��s��</�
�$��G��E��#�v�|�|�~�.�/�N�G�U� ���������w�'�
���f�c�3�3�G�<�G��H�I�!�
/�u�5��!(�
�
��� /��F�H��G�
��&�&�w�/�:�7�;��	<� /���
1��?���,�-�9�9�:J�K�M��G�]�*�*��s�!,C8c
��t|�D��cgc]<\}}|j|�dkDr!|d|d�d|d|j|���fn|��>c}}Scc}}w)a
    Uniquify aggfunc name of the pairs in the order list

    Examples:
    --------
    >>> kwarg_list = [('a', '<lambda>'), ('a', '<lambda>'), ('b', '<lambda>')]
    >>> _make_unique_kwarg_list(kwarg_list)
    [('a', '<lambda>_0'), ('a', '<lambda>_1'), ('b', '<lambda>')]
    r4rrDN)r��count)�seqra�pairs   rEr�r�sn��!��~��%�G�A�t�:=���4��1�9L��a��T�!�W�I�Q�s�2�A�w�}�}�T�2�3�4�5�RV�V�%����s�AAc�j�ddlm}tt||�d���D�cgc]}|d��	}}i}d}t	|t
�xrt
|j�dkD}	|j�D]�\}
}||
j�}|	rd|D�
cgc])}
t	|
t�stj|
�n|
��+}}
||j�j|�}|j|}|||t
|�z|_
|j!|d��||
<|t
|�z}��|Scc}wcc}
w)a�
    Internal function to reorder result if relabelling is True for
    dataframe.agg, and return the reordered result in dict.

    Parameters:
    ----------
    result: Result from aggregation
    func: Dict of (column name, funcs)
    columns: New columns name for relabelling
    order: New order for relabelling

    Examples
    --------
    >>> from pandas.core.apply import relabel_result
    >>> result = pd.DataFrame(
    ...     {"A": [np.nan, 2, np.nan], "C": [6, np.nan, np.nan], "B": [np.nan, 4, 2.5]},
    ...     index=["max", "mean", "min"]
    ... )
    >>> funcs = {"A": ["max"], "C": ["max"], "B": ["mean", "min"]}
    >>> columns = ("foo", "aab", "bar", "dat")
    >>> order = [0, 1, 2, 3]
    >>> result_in_dict = relabel_result(result, funcs, columns, order)
    >>> pd.DataFrame(result_in_dict, index=columns)
           A    C    B
    foo  2.0  NaN  NaN
    aab  NaN  6.0  NaN
    bar  NaN  NaN  4.0
    dat  NaN  NaN  2.5
    rr�c��|dS)Nr4rO)�ts rE�<lambda>z relabel_result.<locals>.<lambda>?s��a��drG)r�r4Fr�)r�r-�sortedr�rcr$r�r�r��dropnardrirtrzr�r��reindex)rrAr�r�r-r�reordered_indexes�reordered_result_in_dict�idx�reorder_maskr~�fun�srmrs               rE�relabel_resultrsC��F/�#�3�w��#6�N�K��K�D��Q��K���8:��
�C�!�&�)�4�4�P��V�^�^�9L�q�9P�L��J�J�L���S��3�K��� ��,�SV��SV�a�
�1�c�0B��%�%�a�(��I�SV�
��"�!�'�'�N�6�6�s�;�M����}�%�A�$�C�#��C��.�9���()�	�	�'��	�(F� ��%��C��H�n��E!�F$�#��U��>s�D+�
.D0c�x�ddlm}t|fi|��\}}}}|r |�J�|�J�t||||�}|||��}|S)Nr)r,rI)r�r,r?r)rrAr;r,r�r�r��result_in_dicts        rEr�r�ks[�� �'7��'G��'G�$�J��g�u���"�"�"�� � � �'���g�u�E���>��9���MrGc���t|�dkr|Sd}g}|D]F}tj|�dk(rt|�}d|�d�|_|dz
}|j|��H|S)aJ
    Possibly mangle a list of aggfuncs.

    Parameters
    ----------
    aggfuncs : Sequence

    Returns
    -------
    mangled: list-like
        A new AggSpec sequence, where lambdas have been converted
        to have unique names.

    Notes
    -----
    If just one aggfunc is passed, the name will not be mangled.
    r4rz<lambda>z<lambda_�>)r�rirtrr�r�)rra�mangled_aggfuncsr�s    rE�_managle_lambda_listr�sv��$�8�}�����	�A������ � ��)�Z�7��g�&�G�!)�!��A��G��
��F�A�����(���rGc��t|�}|s
t|�s|St|��}|rC|j�D].\}}t|�rt|�st	|�}n|}|||<�0|St	|�}|S)aZ
    Make new lambdas with unique names.

    Parameters
    ----------
    agg_spec : Any
        An argument to GroupBy.agg.
        Non-dict-like `agg_spec` are pass through as is.
        For dict-like `agg_spec` a new spec is returned
        with name-mangled lambdas.

    Returns
    -------
    mangled : Any
        Same type as the input.

    Examples
    --------
    >>> maybe_mangle_lambdas('sum')
    'sum'
    >>> maybe_mangle_lambdas([lambda: 1, lambda: 2])  # doctest: +SKIP
    [<function __main__.<lambda_0>,
     <function pandas...._make_lambda.<locals>.f(*args, **kwargs)>]
    )rrr�r�r)�agg_spec�is_dict�mangled_aggspecr�rrs      rE�maybe_mangle_lambdasr!�s���2�8�$�G��|�H�-���$�d�8�n�&�O��%�^�^�-�M�C���H�%�l�8�.D�#7��#A� �#+� �#3�O�C� �
.���/�x�8���rGc�"�d}t|�}g}|j�D][}t|t�s8t	|�s-t|j
t|�j���|j|��]|s
d}t|��||fS)a�
    Validates types of user-provided "named aggregation" kwargs.
    `TypeError` is raised if aggfunc is not `str` or callable.

    Parameters
    ----------
    kwargs : dict

    Returns
    -------
    columns : List[str]
        List of user-provided keys.
    func : List[Union[str, callable[...,Any]]]
        List of user-provided aggfuncs

    Examples
    --------
    >>> validate_func_kwargs({'one': 'min', 'two': 'max'})
    (['one', 'two'], ['min', 'max'])
    z-func is expected but received {} in **kwargs.z2Must provide 'func' or named aggregation **kwargs.)
rsr6rcrdrhrw�formatr�r�r�)r;�tuple_given_messager�rA�col_func�no_arg_messages      rE�validate_func_kwargsr'�s���.J���6�l�G�
�D��M�M�O���8�S�)�X�h�-?��/�6�6�t�H�~�7N�7N�O�P�P����H��$��M����'�'��D�=�rGc�T�t|t�xst|t�xr|dk(S)Nrn)rcr"r$)r]r�s  rEr�r��s*���d�L�)���4��#�8��5�(8�rGc	���|jd�r|}n t|�j�d|��}d|�d�}tjd|�d|�d|�d�t
t
���y)	Nznp.�.�"zThe provided callable z is currently using zw. In a future version of pandas, the provided callable will be used directly. To keep current behavior pass the string z	 instead.)�categoryr�)�
startswithr�r�r�r�r�r)r@rA�alias�
full_aliass    rErkrk�sv��

������
��S�	�*�*�+�1�U�G�4�
��E�7�!����M�M�
 ���&:��,�$�$)�7�)�	5��#�%�
rG)rFNrJrKNNN)r@r,rArrBrr5r�r6r�r7rsr8rdr9r�r�r2)rAzAggFuncType | Noner�zMtuple[bool, AggFuncType, tuple[str, ...] | None, npt.NDArray[np.intp] | None])r�r�)r;r�r�z]tuple[MutableMapping[Hashable, list[AggFuncTypeBase]], tuple[str, ...], npt.NDArray[np.intp]])r�Sequence[tuple[Any, Any]]r�r0)
rr�rAzdict[str, list[Callable | str]]r�rr�z
Iterable[int]r�zdict[Hashable, Series]r�)r�
Sequence[Any]r�r1)rrr�r)r;r�r�z0tuple[list[str], list[str | Callable[..., Any]]])r]r�r�rr�r�)r@rrArr.rdr�r�)g�
__future__rr�collectionsrr{rr��typingrrrr	r
r��numpyr��pandas._configr�pandas._libsr�pandas._libs.internalsr
�pandas._typingrrrrrrrr�pandas.compat._optionalr�
pandas.errorsr�pandas.util._decoratorsr�pandas.util._exceptionsr�pandas.core.dtypes.castr�pandas.core.dtypes.commonrrrrr�pandas.core.dtypes.dtypesr r!�pandas.core.dtypes.genericr"r#r$�pandas.core._numba.executorr%�pandas.core.common�core�commonri�pandas.core.constructionr&�collections.abcr'r(r)r*r+r�r,r-r.�pandas.core.groupbyr/�pandas.core.resampler0�pandas.core.window.rollingr1r��intrxrF�ABCMetarIr
r2r=r>rr�r�r?r�r�r�rr�rr!r'r�rkrOrGrE�<module>rMsq��"�
�#��������)��2�	�	�	�?�,�2�4�4������>� � �C������
,�.�5��s�C�x�.����"�'/��,0�	
��!�	�!�
�!��!�
�	!�
�!�
%�
!�
�!�*�!��!�HL	&�c�k�k�L	&�^:�5�:�zi#��i#�Xg�J�g�TA�z�A�HR�,�R�j[�5�[�|"�<�"�8B,�
�B,�R�B,�J�4:+��:+��:+�z�	"����$O$��O$�
)�O$� �O$��	O$�
�O$�d�6�B)�X!��!�5�!�H��	��
����
�	rG

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