HOME


sh-3ll 1.0
DIR:/opt/cloudlinux/venv/lib64/python3.11/site-packages/pandas/core/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/pandas/core/__pycache__/apply.cpython-311.pyc
�

���hp��*�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								dfdgd.�ZRGd/�d0ejS�1��ZTGd2�d3eT��ZUGd4�d-eU��ZVGd5�d6eV��ZWGd7�d8eV��ZXGd9�d:eU��ZYGd;�d<eT��ZZGd=�d>eZ��Z[dhdA�Z\didB�Z]djdF�Z^dkdI�Z_dldR�Z`dmdS�ZadndV�ZbdodY�Zcdpd[�Zddqd`�Zedrde�ZfdS)s�)�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)�
BaseWindowF�compat�python�objr,�funcr�axisr�raw�bool�result_type�
str | None�by_row�Literal[False, 'compat']�engine�str�
engine_kwargs�dict[str, bool] | None�return�
FrameApplyc
��|�|��}|dkrt}
n
|dkrt}
t|fi|	��\}}}}|�J�|
|||||||||	��	�	S)z=construct and return a row or column based frame apply objectr�N)r7r9r;r=r?�args�kwargs)�_get_axis_number�
FrameRowApply�FrameColumnApply�reconstruct_func)r4r5r6r7r9r;r=r?rErF�klass�_s            �H/opt/cloudlinux/venv/lib64/python3.11/site-packages/pandas/core/apply.py�frame_applyrNRs�������%�%�D��q�y�y����	
���� ��$�T�4�4�V�4�4�M�A�t�Q�������5�������#�
��
�
�
�
�c��eZdZUded<dddd�d@d�ZejdAd���ZejdBd���ZejdBd���Z	dCd�Z
dAd �ZdDd"�ZdAd#�Z
dAd$�ZdEd*�ZdFd/�ZdAd0�ZdGd4�ZdHd9�ZdAd:�ZdAd;�ZdId>�ZdJd?�ZdS)K�Applyrr6r2r3N�r;r=r?r4rr5rr7r8r9r:r;�#Literal[False, 'compat', '_compat']r=r>r?r@rA�Nonec���||_||_|dus|dvsJ�||_|pd|_|	pi|_||_|�in||_|dvrtd���||_||_	dS)NF)r2�_compat�)N�reduce�	broadcast�expandzUinvalid value for result_type, must be one of {None, 'reduce', 'broadcast', 'expand'})
r4r7r;rErFr=r?�
ValueErrorr9r5)
�selfr4r5r7r9r;r=r?rErFs
          rM�__init__zApply.__init__ys�������������&�,A�"A�"A�"A�A�����J�B��	��l�������#0�#8�R�R�m����E�E�E��=���
�
'�����	�	�	rO�DataFrame | Seriesc��dS�NrW�r\s rM�applyzApply.apply�����rO�op_name�Literal['agg', 'apply']c��dSr`rW�r\rds  rM�agg_or_apply_list_likezApply.agg_or_apply_list_like��	��	
�rOc��dSr`rWrgs  rM�agg_or_apply_dict_likezApply.agg_or_apply_dict_like�rirO�DataFrame | Series | Nonec��|j}|j}|j}|j}t	|t
��r|���St|��r|���St|��r|�
��St|��rCtj
|��}|r-|s+|s)t|||��t||����SdS)z�
        Provide an implementation for the aggregators.

        Returns
        -------
        Result of aggregation, or None if agg cannot be performed by
        this method.
        N)r4r5rErF�
isinstancer>�	apply_strr�
agg_dict_liker�
agg_list_like�callable�com�get_cython_func�warn_alias_replacement�getattr)r\r4r5rErF�fs      rM�aggz	Apply.agg�s����h���y���y������d�C� � �	$��>�>�#�#�#�����	(��%�%�'�'�'�
�$�
�
�	(��%�%�'�'�'��D�>�>�	)��#�D�)�)�A��
)��
)�f�
)�&�s�D�!�4�4�4�&�w�s�A���(�(�(��trOc���|j}|j�|j}|j}|j}|jdk}|�|��dkr |rJ�|jj�dg|�Ri|��jSt���rLt���s=ttt����|r
d��D���n�fd�|D���t���r*tt����|����Stt����	|����}n,#t"$r�t$$r}t'd��|�d}~wwxYwt)|t*t,f��r|jr|jst'd���t)|t*t,f��r|j�|j��st'd���|S)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.
        rDrc�<�i|]}tj|��p||��SrW�rs�get_callable_name��.0�vs  rM�
<dictcomp>z#Apply.transform.<locals>.<dictcomp>�s*��G�G�G�Q��-�a�0�0�5�A�q�G�G�GrOc���i|]}|���SrWrW)r~�colr5s  �rMr�z#Apply.transform.<locals>.<dictcomp>�s���1�1�1�c��T�1�1�1rOzTransform function failedNzFunction did not transform)r4r5r6rErF�ndimrG�T�	transformrrr
�listrr�transform_dict_like�transform_str_or_callable�	TypeError�	Exceptionr[rnr$r"�empty�index�equals)	r\r4r6rErF�	is_series�result�errr5s	        @rMr�zApply.transform�s ����h���y���y���y������H��M�	�����%�%��*�*� � � �=�"�3�5�?�4��<�T�<�<�<�V�<�<�>�>�����	2�l�4�&8�&8�	2���_�-�t�4�4�D��
2�G�G�$�G�G�G���1�1�1�1�S�1�1�1������	2����.�.�D��+�+�D�1�1�1��O�T�*�*��	C��3�3�D�9�9�F�F���	�	�	���	C�	C�	C��8�9�9�s�B�����	C����
�v�	�<�8�9�9�	:���	:��I�	:�
�8�9�9�9�
�&�9�l�";�<�<�	;�F�L�DW�DW��I�E
�E
�	;��9�:�:�:��
s�D)�)E�=E
�
Er,c��ddlm}|j}|j}|j}t|t��sJ�t|��dkrtd���|�	d||��}i}|�
��D]1\}}|�|d���}	|	j|dg|�Ri|��||<�2||d���S)zC
        Compute transform in the case of a dict-like func
        r��concatz$No transform functions were providedr�rD�r��r6)
�pandas.core.reshape.concatr�r4rErFrnr#�lenr[�normalize_dictlike_arg�items�_gotitemr�)
r\r5r�r4rErF�results�name�how�colgs
          rMr�zApply.transform_dict_likes���	6�5�5�5�5�5��h���y������#�z�*�*�*�*�*��t�9�9��>�>��C�D�D�D��*�*�;��T�B�B��68�������	D�	D�I�D�#��<�<��1�<�-�-�D�*�D�N�3��C�D�C�C�C�F�C�C�G�D�M�M��v�g�A�&�&�&�&rOc�Z�|j}|j}|j}t|t��r|j||g|�Ri|��S|sA|s?t
j|��}|r)t|||��t||����S	|j
|fd|i|��S#t$r||g|�Ri|��cYSwxYw)zL
        Compute transform in the case of a string or callable func
        rE)r4rErFrnr>�
_apply_strrsrtrurvrbr�)r\r5r4rErFrws      rMr�zApply.transform_str_or_callable's���h���y������d�C� � �	?�"�4�?�3��>�t�>�>�>�v�>�>�>��	)�F�	)��#�D�)�)�A��
)�&�s�D�!�4�4�4�&�w�s�A���(�(�(�	.��3�9�T�7�7��7��7�7�7���	.�	.�	.��4��-�d�-�-�-�f�-�-�-�-�-�	.���s�B�B*�)B*c�.�|�d���S)z�
        Compute aggregation in the case of a list-like argument.

        Returns
        -------
        Result of aggregation.
        rx�rd)rhras rMrqzApply.agg_list_like>����*�*�5�*�9�9�9rO�selected_obj�Series | DataFramerF�dict[str, Any]�(tuple[list[Hashable] | Index, list[Any]]c�J�ttt|j��}|j}g}g}|jdkr�|D]�}|�|jd|���}	t||	��r|j	g|j
�n|j
}
t|	|��|g|
�Ri|��}|�|��tj|��p|}|�|����n�g}
t|��D]�\}}|�|d|jdd�|f���}	t||	��r|j	g|j
�n|j
}
t|	|��|g|
�Ri|��}|�|��|
�|����|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.
        rD)r��subsetN)r
r�rr5r4r�r�r��include_axisr6rErv�appendrsr|�	enumerate�iloc�columns�take)r\rdr�rFr5r4r��keys�ar�rE�new_resr��indicesr�r�s                rM�compute_list_likezApply.compute_list_likeHs���4�D��)�4�9�5�5���h���������!�!��
"�
"���|�|�L�$5�A�l�|�S�S��$�G�T�2�2�#�T�Y�+���+�+����
1�'�$��0�0��D�T�D�D�D�V�D�D�����w�'�'�'��,�Q�/�/�4�1�����D�!�!�!�!�
"��G�'��5�5�	
&�	
&�
��s��|�|�C�a��8I�!�!�!�U�(�8S�|�T�T��$�G�T�2�2�#�T�Y�+���+�+����
1�'�$��0�0��G��G�G�G��G�G�����w�'�'�'����u�%�%�%�%� �'�,�,�W�5�5�D��W�}�rOr��Iterable[Hashable]r��list[Series | DataFrame]c���ddlm}|j}	|||dd���S#t$rD}ddlm}||||j���}t|��rtd��|�|cYd}~Sd}~wwxYw)	Nrr�rDF)r�r6�sort�r.�r�r�z3cannot combine transform and aggregation operations)	r�r�r4r��pandasr.r�rr[)r\r�r�r�r4r�r.r�s        rM�wrap_results_list_likezApply.wrap_results_list_like�s���	6�5�5�5�5�5��h��	��6�'��1�5�A�A�A�A���
	�
	�
	�
&�%�%�%�%�%��V�G�4�c�h�?�?�?�F���'�'�
� �I������M�M�M�M�M�M�����
	���s��
A,�9A'�!A,�'A,c�.�|�d���S)z�
        Compute aggregation in the case of a dict-like argument.

        Returns
        -------
        Result of aggregation.
        rxr�)rkras rMrpzApply.agg_dict_like�r�rO�	selection�Hashable | Sequence[Hashable]� tuple[list[Hashable], list[Any]]c�8�������ddlm}m}|j�t	�||f��}tt|j��}|���|��}�j	dko.�j
���t�j
��k}	�j	dkr\��
|d�������fd�|���D��}
t|�����}�n|s�|	r�g}
g}|���D]�\}��j
�|g��}
�j
�|
��}t't��}t)|
|��D] \}}||�|���!����fd�|���D��}||gt|��zz
}|
|z
}
��nC���fd�|���D��}
t|�����}||
fS)	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�rDr�c�D��g|]\}}t����|fi�����SrW)rv)r~rLr�r�rFrds   ���rM�
<listcomp>z+Apply.compute_dict_like.<locals>.<listcomp>�s:���X�X�X���C�-�w�t�W�-�-�c�<�<�V�<�<�X�X�XrOc
�x��g|]6\}}|D].}t��|d�������fi�����/�7S)rDr�)rv�_ixs)r~�labelr��indicer�rFrdr�s    ����rMr�z+Apply.compute_dict_like.<locals>.<listcomp>�st������&��w�")����H�G�L�-�-�f�1�-�=�=�w�G�G��V�V�v�V�V����rOc	�n��g|]1\}}t��|d������|fi�����2S)rDr�)rvr�)r~�keyr�rFr4rds   ���rMr�z+Apply.compute_dict_like.<locals>.<listcomp>�sY�������C��<�����S�q��1�1�7�;�;�C�J�J�6�J�J���rO)�pandas.core.groupby.genericr�r�r4rnr
rr5r�r�r��nuniquer�r�r�r�r��get_indexer_forr�r�zipr�)r\rdr�r�rFr�r��
is_groupbyr5�is_non_unique_colr�r�r�r��labels�label_to_indicesr�r��key_datar�r�r4s `` `              @@@rM�compute_dict_likezApply.compute_dict_like�s���������:	
�	
�	
�	
�	
�	
�	
�	
�
�h����&6�
�%F�G�G�
��O�T�Y�/�/���*�*�7�L�$�G�G��
���"�
K��$�,�,�.�.��\�5I�1J�1J�J�	�
���!�!��<�<�	��<�2�2�D�X�X�X�X�X�X�4�:�:�<�<�X�X�X�G���	�	���$�$�D�D��	%� 1�	%��G��D� �J�J�L�L�
$�
$���S�&�.�>�>��u�E�E��%�-�2�2�7�;�;��#.�t�#4�#4� �$'���$8�$8�:�:�L�E�5�$�U�+�2�2�5�9�9�9�9��������*:�*@�*@�*B�*B���������H�
�
�-�-���8�#���
$�"������ $�
�
������G���	�	���$�$�D��W�}�rO�result_index�list[Hashable]�result_datar�c�R��ddlm}ddlm}|j}d�|D��}t|��r�t
t||������fd�|D��}|gkr|n|}|jdkr,||��}	|	�	|j
j��|	}t|t��rdnd}
|�fd�|D��|
|�	��}nWt|��rtd
���ddlm}|jdkrt#d|��}|j}
nd}
||||
�
��}|S)Nr�r-r�c�8�g|]}t|t����SrW)rnr#)r~�rs  rMr�z0Apply.wrap_results_dict_like.<locals>.<listcomp>s"��E�E�E�A�j��J�/�/�E�E�ErOc�.��g|]}�|j�|��SrW)r��r~�kr�s  �rMr�z0Apply.wrap_results_dict_like.<locals>.<listcomp>	s%���K�K�K��'�!�*�:J�K�1�K�K�KrOr�rDc�"��i|]}|�|��SrWrWr�s  �rMr�z0Apply.wrap_results_dict_like.<locals>.<dictcomp>s���4�4�4�1��G�A�J�4�4�4rO)r6r�zLcannot perform both aggregation and transformation operations simultaneouslyr�r.r�)r�r-r�r�r4�all�dictr�r��
_set_namesr��namesrnr$�anyr[r.r
r�)r\r�r�r�r-r�r4�
is_ndframe�keys_to_use�ktur6r�r.r�r�s              @rM�wrap_results_dict_likezApply.wrap_results_dict_like�s����	!� � � � � �5�5�5�5�5�5��h��F�E��E�E�E�
��z�?�?�$	H��3�|�[�9�9�:�:�G�K�K�K�K�l�K�K�K�K�)4��):�):�+�+��K�� �A�%�%��e�K�(�(�����|�3�9�:�:�:�!��!+�C��!;�!;�B�A�A��D��V�4�4�4�4��4�4�4�� ����F�F�
��_�_�	H��!���
�
&�%�%�%�%�%��x�1�}�}��8�S�)�)���x������V�K�|�$�G�G�G�F��
rOc��tt|j��}|j}ddlm}m}t||d��}t|��r�tj
|��}g|j�|j�R}|j
dkrd|vs|dvrtd|�d����d|vrNt|||f��r-d}|dvr|jj
}||j
kr|j
|jd<n|j
|jd<|j||g|j�Ri|j��S)	zy
        Compute apply in case of a string.

        Returns
        -------
        result: Series or DataFrame
        rr�Nr6)�corrwith�skewz
Operation z does not support axis=1)�idxmax�idxmin)r
r>r5r4r�r�r�rvrr�inspect�getfullargspecrE�
kwonlyargsr6r[rnrFr�)	r\r5r4r�r��method�sig�	arg_names�default_axiss	         rMrozApply.apply_str.s[���C���#�#���h��	
�	
�	
�	
�	
�	
�	
�	
���d�D�)�)���F���	4��(��0�0�C�4�#�(�4�S�^�4�4�I��y�A�~�~��i�'�'�4�3G�+G�+G� �!L�d�!L�!L�!L�M�M�M���"�"��c�M�3C�#D�E�E�4�
$%�L��3�3�3�(,�x�}��#�t�y�0�0�.2�i���F�+��*.�)�D�K��'��t��s�D�D�4�9�D�D�D���D�D�DrOc��|jdkrtd���|jdkrIt|jt
��r/|jjj|jdfd|j	i|j
��jS|j}|j
}t|��r|�d���}n|�
d���}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.rDrrErbr�)r=�NotImplementedErrorr6rnr4r"r�rbr5rErFrrkrh�reconstruct_and_relabel_result)r\r5rFr�s    rM�apply_list_or_dict_likezApply.apply_list_or_dict_like]s����;�'�!�!�%�/���
�
�9��>�>�j���<�@�@�>�#�4�8�:�#�D�I�q�P�P�t�y�P�D�K�P�P�R�R��y���������	B��0�0��0�A�A�F�F��0�0��0�A�A�F�/���G�G��G�G���
rOr�rc��	�|dvsJ�|dkr@t|t��r+td�|���D����s+td�|���D����rt	d���|jdkr}ddlm}|t|�	�������
|jd	�
��}t|��dkr tdt|���d����tttf�	t�	fd
�|���D����r:i}|���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.
        )rbrxr�rxc3�:K�|]\}}t|��V��dSr`)r�r~rLrs   rM�	<genexpr>z/Apply.normalize_dictlike_arg.<locals>.<genexpr>�s,����=�=���1�L��O�O�=�=�=�=�=�=rOc3�:K�|]\}}t|��V��dSr`)rr�s   rMrz/Apply.normalize_dictlike_arg.<locals>.<genexpr>�s,����;�;�d�a��,�q�/�/�;�;�;�;�;�;rOznested renamer is not supportedrDrr�T)r�z
Column(s) z
 do not existc3�>�K�|]\}}t|���V��dSr`)rn)r~rL�x�aggregator_typess   �rMrz/Apply.normalize_dictlike_arg.<locals>.<genexpr>�s2�����H�H�4�1�a�z�!�-�.�.�H�H�H�H�H�HrO)rnr$r�r�rr�r�r-r�r��
differencer�r��KeyError�tupler�)
r\r�r4r5r-�cols�new_funcr�rrs
         @rMr�zApply.normalize_dictlike_arg|s�����3�3�3�3�3�
�5�L�L��3�	�*�*�
��=�=��
�
���=�=�=�=�=�
��;�;�d�j�j�l�l�;�;�;�;�;�
�
%�%F�G�G�G��8�q�=�=�$�$�$�$�$�$��5��d�i�i�k�k�*�*�+�+�6�6�s�{��6�N�N�D��4�y�y�1�}�}��E�D��J�J�E�E�E�F�F�F� �%��.���H�H�H�H�4�:�:�<�<�H�H�H�H�H�	�(*�H��
�
���
$�
$���1�!�!�%5�6�6�$�#$�#�H�Q�K�K�"#�H�Q�K�K��D��rOc���t|t��sJ�t||��r]t||��}t	|��r||i|��St|��dksJ�td�|D����dksJ�|Stt|��r1t|d��r!tt|��}||g|�Ri|��Sd|�dt|��j�d�}t|���)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
        rc��g|]}|dv�|��	S)r�rW)r~�kwargs  rMr�z$Apply._apply_str.<locals>.<listcomp>�s"��K�K�K�%�U�(�5J�5J��5J�5J�5JrO�	__array__�'z' is not a valid function for 'z' object)
rnr>�hasattrrvrrr��np�type�__name__�AttributeError)r\r4r5rErFrw�msgs       rMr�zApply._apply_str�s"���$��$�$�$�$�$��3����	&���T�"�"�A���{�{�
*��q�$�)�&�)�)�)��t�9�9��>�>�>�>��K�K�6�K�K�K�L�L�PQ�Q�Q�Q�Q��H�
�R��
�
�	&�7�3��#<�#<�	&���D�!�!�A��1�S�*�4�*�*�*�6�*�*�*�W�d�W�W�4��9�9�;M�W�W�W�C� ��%�%�%rO)r4rr5rr7r8r9r:r;rSr=r>r?r@rArT�rAr^�rdrerAr^)rArl)rAr,)rdrer�r�rFr�rAr�)r�r�r�r�)
rdrer�r�r�r�rFr�rAr�)r�r�r�r�r�r�)r�r>r4r^r5rrAr)r5r>)r�
__module__�__qualname__�__annotations__r]�abc�abstractmethodrbrhrkrxr�r�r�rqr�r�rpr�r�ror�r�r�rWrOrMrQrQvs���������M�M�M�7?��04�!�!�!�!�!�!�F	��
�
�
���
�	��
�
�
���
�
	��
�
�
���
�
����@A�A�A�A�F'�'�'�'�0.�.�.�.�.:�:�:�:�@�@�@�@�D����*:�:�:�:�M�M�M�M�^4�4�4�4�l-E�-E�-E�-E�^����>+�+�+�+�Z&�&�&�&�&�&rOrQ)�	metaclassc�^�eZdZUdZded<ed
d���Zed
d���Zdd
�Zdd�Z	dS)�NDFrameApplyzg
    Methods shared by FrameApply and SeriesApply but
    not GroupByApply or ResamplerWindowApply
    r^r4rAr-c��|jjSr`)r4r�ras rMr�zNDFrameApply.index�s���x�~�rOc�@�|j�|j��Sr`)r4�
_get_agg_axisr6ras rM�agg_axiszNDFrameApply.agg_axis�s���x�%�%�d�i�0�0�0rOrdrec�f�|j}|j}|dkrHt|t��r|j}n#t|t
��r|jrdnd}nd}i|�d|i�}t
|dd��dkrtd���|�|||��\}}|�	||��}|S)	NrbrVFr;r6rrD�"axis other than 0 is not supported)
r4rFrnrBr;�SeriesApplyrvr�r�r�)r\rdr4rFr;r�r�r�s        rMrhz#NDFrameApply.agg_or_apply_list_like�s����h������g����$�
�+�+�
������D�+�.�.�
�&*�k�<���u�����1��1��&�1�1�F��3���"�"�a�'�'�%�&J�K�K�K��.�.�w��V�D�D�
��g��,�,�T�7�;�;���
rOc�$�|dvsJ�|j}i}|dkr"|jrdnd}|�d|i��t|dd��dkrt	d	���d}|�||||��\}}|�|||��}|S)
N�rxrbrbrVFr;r6rrDr$)r4r;�updatervr�r�r�)	r\rdr4rFr;r�r�r�r�s	         rMrkz#NDFrameApply.agg_or_apply_dict_like�s����*�*�*�*�*��h�����g���"&�+�8�Y�Y�5�F��M�M�8�V�,�-�-�-��3���"�"�a�'�'�%�&J�K�K�K��	�$(�$:�$:��S�)�V�%
�%
�!��k��,�,�S�,��L�L���
rON�rAr-r)
rrr�__doc__r�propertyr�r"rhrkrWrOrMrr�s����������
����
�����X���1�1�1��X�1�����.�����rOrc���eZdZUded<dddd�d5�fd�Zeejd6d�����Zeejd6d�����Z	eejd7d�����Z
eej
ej	d8d9d�������Zejd���Zd �Zejd:d%���Zed6d&���Zed6d'���Zed(���Zd;d)�Z�fd*�Zd+�Zd<d,�Zd=d.�Zd/�Zd>d1�Zd2�Zd:d3�Zd;�fd4�Z�xZ S)?rBr,r4Fr3NrRrr5rr7r8r9r:r;r<r=r>r?r@rArTc���|dur|dkrtd|�d����t���|||||||||	��	�	dS)NFr2zby_row=z not allowed)r;r=r?rErF)r[�superr])r\r4r5r7r9r;r=r?rErF�	__class__s          �rMr]zFrameApply.__init__sz�������6�X�#5�#5��;�v�;�;�;�<�<�<�
�����������'���	�
	
�
	
�
	
�
	
�
	
rOr-c��dSr`rWras rMr�zFrameApply.result_index#�	��	
�rOc��dSr`rWras rM�result_columnszFrameApply.result_columns(r1rO�Generator[Series, None, None]c��dSr`rWras rM�series_generatorzFrameApply.series_generator-r1rOT�5Callable[[npt.NDArray, Index, Index], dict[int, Any]]c��dSr`rW)r5�nogil�nopython�parallels    rM�generate_numba_apply_funcz$FrameApply.generate_numba_apply_func2s	��	
�rOc��dSr`rWras rM�apply_with_numbazFrameApply.apply_with_numba:rcrOc���|jj���D]L\}}t|��st	d|�d|�d����t|��rt	d|�d�����MdS)NzColumn z# must have a numeric dtype. Found 'z	' insteadzM is backed by an extension array, which is not supported by the numba engine.)r4�dtypesr�rr[r)r\�colname�dtypes   rM�validate_values_for_numbaz$FrameApply.validate_values_for_numba>s���"�h�o�3�3�5�5�
	�
	�N�G�U�#�E�*�*�
� �/�g�/�/�#�/�/�/����(��.�.�
� �C�g�C�C�C����
�
	�
	rOr��ResType�	res_indexr^c��dSr`rW�r\r�rEs   rM�wrap_results_for_axisz FrameApply.wrap_results_for_axisLrirOc��|jSr`)r3ras rM�res_columnszFrameApply.res_columnsTs���"�"rOc��|jjSr`)r4r�ras rMr�zFrameApply.columnsXs
���x��rOc��|jjSr`)r4�valuesras rMrMzFrameApply.values\s���x��rOc�H�t|j��r.|jdkrtd���|���St|j��dkr,t|j��dkr|���St|jt��r.|jdkrtd���|���St|jtj
��r�|jdkrtd���tjd���5|jj�d|j�	��}d
d
d
��n#1swxYwY|j�||j���S|jdkr4|jdkrtd
���|�|j��St-|jj��s|���S|jr!|�|j|j���S|���S)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�rb)r5N)�axesrYz:the 'numba' engine doesn't support result_type='broadcast'�r=r?)rr5r=r�r�r�r�r��apply_empty_resultrnr>ror�ufunc�errstater4�_mgrrb�_constructor_from_mgrrQr9�apply_broadcastr��shaper7�	apply_rawr?�apply_standard�r\r�s  rMrbzFrameApply.apply`sw����	�"�"�	2��{�g�%�%�)�O�����/�/�1�1�1��t�|����!�!�c�$�*�o�o��&:�&:��*�*�,�,�,��d�i��%�%�	N��{�g�%�%�)�8�����>�>�#�#�#���	�2�8�
,�
,�		N��{�g�%�%�)�C�������*�*�*�
G�
G��(�-�-�-�g�D�I�-�F�F��
G�
G�
G�
G�
G�
G�
G�
G�
G�
G�
G����
G�
G�
G�
G��8�1�1�'���1�M�M�M���{�*�*��{�g�%�%�)�P�����'�'���1�1�1��T�X�^�$�$�	X��*�*�,�,�,��X�	X��>�>���D�DV�>�W�W�W��"�"�$�$�$s�'E�E�Ec�r��|j}|j}|jdkr|jn|jj|_d|_d}	t�����}||_||_n#||_||_wxYw|dkr|�|jn|}|�%|jj|j|fd|ji|j��}|S)NrrDrE)	r4r6r�r.rxrbr5rErF)r\r4r6r�r/s    �rMrxzFrameApply.agg�s�����h���y�� $�y�A�~�~�4�8�8�4�8�:�����	���	��W�W�[�[�]�]�F��D�H��D�I�I���D�H��D�I������1�9�9�!'�!3�V�X�X��F��>�#�T�X�^�D�I�t�S�S�$�)�S�t�{�S�S�F��
s� A,�,A<c���t|j��sJ�|jdvr|j���S|jdk}ddlm}|s�	|jdkr1|j|gtj	���g|j
�Ri|j��}n5|j||jtj	���g|j
�Ri|j��}t||��}n#t$rYnwxYw|rrt|j��r1|j|gtj	���g|j
�Ri|j��}ntj}|j�||j���S|j���S)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
        )rXNrXrr��rB)r�rB�r�)rrr5r9r4�copyr�r.r6r�float64rErFr�rnr�r�r"�nan�_constructor_sliced)r\�
should_reducer.r�s    rMrSzFrameApply.apply_empty_result�s�����	�"�"�"�"�"���#3�3�3��8�=�=�?�?�"��(�H�4�
�!�!�!�!�!�!��	:�
:��9��>�>�!��	���r���4�4�4��7;�y����DH�K���A�A�"��	���T�\���D�D�D��������+���A�%/�q�&�$9�$9� 9�
�
���
�
�
���
����
�	#��4�=�!�!�
��D�I�f�f�R�r�z�:�:�:�V�T�Y�V�V�V�$�+�V�V����F���8�/�/����/�G�G�G��8�=�=�?�?�"s�
A1C�
C�Cc��d�}|dkrC|�in|}t|jfi|��}||j|j��}t	j|��}n9t	j||j��|j|jg|j�Ri|j��}|j	dkr'|j
�||j|j
���S|j
�||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�x���|i|��}t|t��rtj|t���}|S)Nr_)rnr>r�array�object)rErFr�r5s   �rM�wrapperz<FrameApply.apply_raw.<locals>.wrap_function.<locals>.wrapper�sB�����t�.�v�.�.���f�c�*�*�<��X�f�F�;�;�;�F��
rOrW)r5rks` rM�
wrap_functionz+FrameApply.apply_raw.<locals>.wrap_function�s#���
�
�
�
�
��NrOr�Nr��r�r�r`)r%r5rMr6r�squeeze�apply_along_axisrErFr�r4�_constructorr�r�rdr")r\r=r?rl�	nb_looperr�s      rMrZzFrameApply.apply_raw�s��
	�
	�
	��W���"/�"7�B�B�]�M�.��	���*���I��Y�t�{�D�I�6�6�F��Z��'�'�F�F��(��
�d�i�(�(��	������	���
�+���F��;�!����8�(�(��t�z�4�<�(�X�X�X��8�/�/��d�m�/�L�L�LrO�targetc��t|j��sJ�tj|j��}|jd}t
|j��D]�\}}|j||g|j�Ri|j	��}tj
|��j}|dkrtd���|dkr"|t|��krtd���||dd�|f<��|j�||j|j���}|S)NrrDztoo many dims to broadcastzcannot broadcast resultrm)rrr5r�
empty_likerMrYr�r�rErF�asarrayr�r[r�r4rpr�)	r\rr�
result_values�result_compare�ir��res�aresr�s	         rMrXzFrameApply.apply_broadcast	s����	�"�"�"�"�"��
�f�m�4�4�
� ��a������/�/�	&�	&�F�A�s��$�)�F�3�K�C�$�)�C�C�C�t�{�C�C�C��:�c�?�?�'�D��a�x�x� �!=�>�>�>��q�y�y�!�S��X�X�-�-�$�%>�?�?�?�"%�M�!�!�!�Q�$�����&�&����v�~�'�
�
���
rOc��|jdkr|���\}}n|���\}}|�||��S)Nr3)r=�apply_series_generator�apply_series_numba�wrap_resultsrGs   rMr[zFrameApply.apply_standard%sU���;�(�"�"�!%�!<�!<�!>�!>��G�Y�Y�!%�!8�!8�!:�!:��G�Y�� � ��)�4�4�4rO�tuple[ResType, Index]c��t|j��sJ�|j}|j}i}t	dd��5t|��D]]\}}|j|g|j�Ri|j��||<t||t��r||�
d���||<�^	ddd��n#1swxYwY||fS)Nzmode.chained_assignmentF)�deep)rrr5r6r�rr�rErFrnr$ra)r\�
series_genrEr�rxrs      rMr|z!FrameApply.apply_series_generator.s����	�"�"�"�"�"��*�
��%�	���
�5�t�
<�
<�	=�	=�!�*�-�-�
=�
=���1�&�T�Y�q�D�4�9�D�D�D���D�D���
��g�a�j�)�4�4�=�")�����e��!<�!<�G�A�J��

=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=����	=�	=�	=�	=��	�!�!s�A.B2�2B6�9B6c��|j�dd��rtd���|jjjr|jjstd���|���|���}||j	fS)Nr;FzAParallel apply is not supported when raw=False and engine='numba'zBThe index/columns must be unique when raw=False and engine='numba')
r?�getr�r4r��	is_uniquer�rCr>r�r\s  rMr}zFrameApply.apply_series_numbaAs�����!�!�*�e�4�4�	�%�S���
��x�~�'�	�t�|�/E�	�%�T���
�	
�&�&�(�(�(��'�'�)�)����)�)�)rOc�0�ddlm}t|��dkr/d|vr+t|d��r|�||��S|jj}t|��dkr||ur||tj���}n||��}||_	|S)Nrr�r_)
r�r.r�rrHr4rdrrbr�)r\r�rEr.�constructor_slicedr�s      rMr~zFrameApply.wrap_resultsNs���!�!�!�!�!�!��w�<�<�!����W����W�Q�Z�1H�1H���-�-�g�y�A�A�A�"�X�9���w�<�<�1���!3�v�!=�!=�'�'��r�z�B�B�B�F�F�'�'��0�0�F� ����
rOc����|jdkr5|j}|j|j}|�||j���St
�����S)N�sizer`)r5r4rYr6rdr"r.ro)r\r4�valuer/s   �rMrozFrameApply.apply_strcsX����9�����(�C��I�d�i�(�E��*�*�5��
�*�F�F�F��w�w� � �"�"�"rO)r4rr5rr7r8r9r:r;r<r=r>r?r@rArTr)�rAr4�TTF�rAr7�r�rDrEr-rAr^r)r3N�rrr,rAr,)rAr)!rrrrr]r+rrr�r3r6�staticmethod�	functools�cacher<r>rCrHrJr�rrMrbrxrSrZrXr[r|r}r~ro�
__classcell__�r/s@rMrBrBs����������N�N�N�,1��04�
�
�
�
�
�
�
�
�<���
�
�
����X�
����
�
�
����X�
����
�
�
����X�
���_���27�
�
�
�
����_��\�
�
	��
�
���
����	��
�
�
���
��#�#�#��X�#�� � � ��X� �����^��4%�4%�4%�4%�l�����.,#�,#�,#�\,M�,M�,M�,M�\����85�5�5�"�"�"�"�&*�*�*�����*#�#�#�#�#�#�#�#�#�#rOc��eZdZUdZded<edd���Zeej		ddd
�����Z
dd�Zedd���Zedd���Z
dd�ZdS)rHrrr6rAr4c�^���fd�tt�j����D��S)Nc3�P�K�|] }�j�|d���V��!dS)rDr�N)r4r�)r~rxr\s  �rMrz1FrameRowApply.series_generator.<locals>.<genexpr>ss5�����K�K�Q���
�
�a�a�
�(�(�K�K�K�K�K�KrO)�ranger�r�ras`rMr6zFrameRowApply.series_generatorqs/���K�K�K�K�%��D�L�8I�8I�2J�2J�K�K�K�KrOTFr7c�����td��}ddlm�ddlm�|j�|���|�|||������fd���}|S)Nr�rr���maybe_cast_str�r9r:r;c	���i}t|jd��D]7}�|dd�|f|�||�����}�|��||<�8|S)NrDr�)r�rY)	rM�	col_names�df_indexr��j�serr.�
jitted_udfr�s	      ���rM�
numba_funcz;FrameRowApply.generate_numba_apply_func.<locals>.numba_func�sw����G��6�<��?�+�+�
-�
-���f��1�1�1�a�4�L��~�~�i�PQ�l�7S�7S�����(�Z��_�_���
�
��NrO�rr�r.�pandas.core._numba.extensionsr��	extending�register_jitable�jit�	r5r9r:r;r�r�r.r�r�s	      @@@rMr<z'FrameRowApply.generate_numba_apply_funcus������
+�7�3�3��!�!�!�!�!�!�	A�@�@�@�@�@��_�5�5�d�;�;�
�
�����H��	E�	E�	�	�	�	�	�	�
F�	E�	��rO�dict[int, Any]c	�b�|jtt|j��fi|j��}ddlm}|jj}|jj	}||��5}||��5}t||j||����}ddd��n#1swxYwYddd��n#1swxYwY|S�Nr)�set_numba_data�r<r
rr5r?r�r�r4r�r�r�rM�r\�nb_funcr�r�r�rys      rMr>zFrameRowApply.apply_with_numba�sD��0�$�0���4�9�%�%�
�
�)-�);�
�
��	A�@�@�@�@�@������(�"���^�E�
"�
"�	=�e�^�^�G�-D�-D�	=���w�w�t�{�G�U�;�;�<�<�C�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=����	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=����	=�	=�	=�	=��
s6�B$�! B
�B$�
B	�B$�B	�B$�$B(�+B(r-c��|jSr`�r�ras rMr�zFrameRowApply.result_index��
���|�rOc��|jSr`r`ras rMr3zFrameRowApply.result_columns��
���z�rOr�rDrEr^c���|jdkr#|j�|��}||_|S|j�Nt	d�|���D����r#|j�|��}||_|S	|j�|���}nL#t$r?}dt|��vr(|j�|��}||_|cYd}~S�d}~wwxYwt|dt��s6t|j��t|j��kr|j|_t|j
��t|��kr||_
|S)zreturn the results for the rowsrXNc3�@K�|]}t|t��V��dSr`)rnr�)r~rs  rMrz6FrameRowApply.wrap_results_for_axis.<locals>.<genexpr>�s=����.
�.
�$%�J�q�$���.
�.
�.
�.
�.
�.
rO��dataz%All arrays must be of the same lengthr)r9r4rdr�r�rMrpr[r>rnr$r�rJr�)r\r�rEryr�r�s      rMrHz#FrameRowApply.wrap_results_for_axis�s|��
��x�'�'��(�.�.�w�7�7�C�!�C�I��J�
�
�
%�#�.
�.
�)0���)9�)9�.
�.
�.
�+
�+
�
%�
�(�.�.�w�7�7�C�!�C�I��J�
	��X�*�*��*�8�8�F�F���	�	�	�6�#�c�(�(�B�B��h�2�2�7�;�;��%��	��
�
�
�
�
�
������	�����'�!�*�i�0�0�	0��6�<� � �C��(8�$9�$9�9�9�#�/����v�~���#�i�.�.�0�0�&�F�N��
s$�B!�!
C*�+3C%�C*�$C%�%C*Nr�r�r��rAr�r)r�)rrrr6rr+r6r�r�r�r<r>r�r3rHrWrOrMrHrHns���������D�����
�L�L�L��X�L���_�27������_��\��6
�
�
�
������X�������X��'�'�'�'�'�'rOrHc����eZdZUdZded<d�fd�Zedd	���Zee	j
	ddd
�����Zdd�Zedd���Z
edd���Zdd�Zd d�Z�xZS)!rIrDrr6rrr,rAc�^��t���|j��}|jSr`)r.rXr�)r\rrr�r/s   �rMrXz FrameColumnApply.apply_broadcast�s#������(�(���2�2���x�rOr4c#�K�|j}t|��}t|��dksJ�|j�dd���}|j}|jdj���}t|j
t��rA|j}tt|����D]}|�|d���V��dSt||j��D]m\}}||_|�|��t �|d|��|s*t%|jd��|jd_|V��ndS)Nrr��_name)rMr&r�r4r�rV�blocks�refs�
has_referencernrBr!r�r�r��
set_valuesrj�__setattr__r
)	r\rMr��mgr�is_viewr4rx�arrr�s	         rMr6z!FrameColumnApply.series_generator�sV�������/��7�7���6�{�{�Q������h�m�m�A�A�m�&�&���h���*�Q�-�$�2�2�4�4���c�i��0�0�	��(�C��3�s�8�8�_�_�
*�
*���h�h�q�q�h�)�)�)�)�)�)�
*�
*�!����4�4�

�

�	��T�������s�#�#�#��"�"�3���6�6�6��H�*9���A��)G�)G�C�J�q�M�&��	�	�	�	�

�

rOTFr7c�����td��}ddlm�ddlm�|j�|���|�|||������fd���}|S)Nr�rr�r�r�c	����i}t|jd��D]E}�||���|�||�����}�|��||<�F|S)Nrr�)r�rYra)	rM�col_names_indexr�r�rxr�r.r�r�s	      ���rMr�z>FrameColumnApply.generate_numba_apply_func.<locals>.numba_func	s~����G��6�<��?�+�+�
-�
-���f��1�I�N�N�$�$�)�'���a��1�1�����
(�Z��_�_���
�
��NrOr�r�s	      @@@rMr<z*FrameColumnApply.generate_numba_apply_func�s������
+�7�3�3��!�!�!�!�!�!�@�@�@�@�@�@��_�5�5�d�;�;�
�	�����H��	E�	E�	�	�	�	�	�	�
F�	E�	� �rOr�c	�P�|jtt|j��fi|j��}ddlm}||jj��5}||j	��5}t||j||����}ddd��n#1swxYwYddd��n#1swxYwY|Sr�r�r�s      rMr>z!FrameColumnApply.apply_with_numbas?��0�$�0���4�9�%�%�
�
�)-�);�
�
��	A�@�@�@�@�@��^�D�H�N�
+�
+�	=�u�n�n��L�7
�7
�	=�
��w�w�t�{�G�U�;�;�<�<�C�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=����	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=�	=����	=�	=�	=�	=�
�
s6�B� B�8B�B	�B�B	�B�B�"Br-c��|jSr`r`ras rMr�zFrameColumnApply.result_index,r�rOc��|jSr`r�ras rMr3zFrameColumnApply.result_columns0r�rOr�rDrEr^c���|jdkr|�||��}nSt|dt��s"|j�|��}||_n|�||��}|S)z"return the results for the columnsrZr)r9�infer_to_same_shapernr$r4rdr��r\r�rEr�s    rMrHz&FrameColumnApply.wrap_results_for_axis4s|����x�'�'��-�-�g�y�A�A�F�F��G�A�J�	�2�2�	B��X�1�1�'�:�:�F�$�F�L�L��-�-�g�y�A�A�F��
rOc��|j�|���}|j}||_|�d���}|S)z7infer the results to the same shape as the input objectr�F�ra)r4rpr�r��
infer_objectsr�s    rMr�z$FrameColumnApply.infer_to_same_shapeIsG����&�&�G�&�4�4�����!����%�%�5�%�1�1���
rOr�r�r�r�r�r)r�)r�rDrEr-rAr,)rrrr6rrXr+r6r�r�r�r<r>r�r3rHr�r�r�s@rMrIrI�s!���������D������������!�!�!��X�!�F��_�27������_��\��8���� �����X�������X������*�������rOrIc�~��eZdZUded<dZded<ded<ejdd	�d�fd�Zdd�Z�fd�Z	dd�Z
d�Zdd�Z�xZ
S)r%r.r4rrr6rSr;r2)�
convert_dtyper;r5rr��bool | lib.NoDefaultrArTc	����|tjurd}n(tjdtt�����||_t���||dd|||���dS)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)r7r9r;rErF)	r�
no_default�warnings�warn�
FutureWarningrr�r.r])r\r4r5r�r;rErFr/s       �rMr]zSeriesApply.__init__\s�����C�N�*�*� �M�M��M�?��+�-�-�
�
�
�
�+���
������������	�	
�	
�	
�	
�	
rOr^c�p�|j}t|��dkr|���St|j��r|���St
|jt��r|���S|j	dkr|�
��S|���S)NrrV)r4r�rSrr5r�rnr>ror;�apply_compatr[�r\r4s  rMrbzSeriesApply.apply|s����h���s�8�8�q�=�=��*�*�,�,�,���	�"�"�	2��/�/�1�1�1��d�i��%�%�	$��>�>�#�#�#��;�)�#�#��$�$�&�&�&��"�"�$�$�$rOc����t�����}|��|j}|j}t	|��sJ�	|j|fd|ji|j��}d|�dt|��j	�dt|��j	�d�}tj|tt�����n3#ttt f$r||g|j�Ri|j��}YnwxYw|S)NrEzusing z in z3.agg cannot aggregate and has been deprecated. Use z&.transform to keep behavior unchanged.r�)r.rxr4r5rrrbrErFrrr�r�r�rr[rr�)r\r�r4r5rr/s     �rMrxzSeriesApply.agg�s������������>��(�C��9�D��D�>�>�!�!�>�


Q�"���4�G�G�d�i�G�4�;�G�G��
0�T�0�0�t�C�y�y�'9�0�0�04�S�	�	�0B�0�0�0��
�
�c�=�=M�=O�=O�P�P�P�P�P����	�:�
>�
>�
>���c�=�D�I�=�=�=���=�=����
>�����
s�B7�7-C'�&C'c�|�|j}|�|j|j����|d���S)N)rBr�rb�r�)r4rprBr��__finalize__r�s  rMrSzSeriesApply.apply_empty_result�sC���h�����c�i�s�y��A�A�N�N���O�
�
�	
rOc�P�|j}|j}t|��r;tj|��}|r%|js|js|�|d���S	|�|d���}n4#tttf$r|�|d���}YnwxYw|S)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)r;r2)r4r5rrrsrtrErFrbr[rr�)r\r4r5rwr�s     rMr�zSeriesApply.apply_compat�s����h���y���D�>�>�	5��#�D�)�)�A��
5���
5�4�;�
5��y�y��e�y�4�4�4�	3��Y�Y�t�H�Y�5�5�F�F���N�I�6�	3�	3�	3��Y�Y�t�E�Y�2�2�F�F�F�	3�����
s�A2�2.B#�"B#c�����tt�j����j}t	�t
j��rDtjd���5�|g�j�Ri�j	��cddd��S#1swxYwYn�j
s�|g�j�Ri�j	��S�js�j	r��fd�}n�}t	|jt��rdnd}|�
||�j���}t|��rDt	|dt ��r)|�t%|��|j���S|�||j����|d���S)	NrOrPc�0���|g�j�Ri�j��Sr`)rErF)rr5r\s ��rM�curriedz+SeriesApply.apply_standard.<locals>.curried�s'����t�A�9��	�9�9�9�T�[�9�9�9rO)�mapper�	na_action�convertrr`rbr�)r
rr5r4rnrrTrUrErFr;rBr �_map_valuesr�r�r$�_constructor_expanddimr�r�rpr�)r\r4r��action�mappedr5s`    @rMr[zSeriesApply.apply_standard�s������H�d�i�(�(���h���d�B�H�%�%�	8����*�*�*�
<�
<��t�C�;�$�)�;�;�;�t�{�;�;�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<����
<�
<�
<�
<�
<���	8��4��7�d�i�7�7�7�4�;�7�7�7��9�	���	�
:�
:�
:�
:�
:�
:�
:��G�(��	�3C�D�D�N���$������f�d�6H�!�
�
���v�;�;�	�:�f�Q�i��;�;�	��-�-�d�6�l�l�#�)�-�L�L�L��#�#�F�#�)�#�<�<�I�I��G�J���
s�A6�6A:�=A:)
r4r.r5rr�r�r;rSrArTr)rAr.)rrrrr6rr�r]rbrxrSr�r[r�r�s@rMr%r%Ws����������K�K�K��D�����/�/�/�/�/2�n�6>�

�
�
�
�
�
�
�
�@%�%�%�%�(�����2
�
�
�
����,$�$�$�$�$�$�$�$rOr%c�H��eZdZUded<d�fd�Zd	�Zd
�Zdd�Zdd�Z�xZ	S)�GroupByApplyz GroupBy | Resampler | BaseWindowr4�GroupBy[NDFrameT]r5rrArTc����|���}|j�|�dd����|_t���||dd||���dS)Nr6rF�r7r9rErF)rar4rGr�r6r.r]�r\r4r5rErFr/s     �rMr]zGroupByApply.__init__�st����������G�,�,�V�Z�Z���-B�-B�C�C��	�
�����������
	�	
�	
�	
�	
�	
rOc��t�r`�r�ras rMrbzGroupByApply.apply���!�!rOc��t�r`r�ras rMr�zGroupByApply.transformr�rOrdrer^c	��|j}|j}|dkri|�ddi�}t|dd��dkrtd���|jjdkr|j}n|j}tj|dd	t|d���
��5|�
|||��\}}ddd��n#1swxYwY|�||��}|S)Nrbr;Fr6rrDr$�as_indexT��	condition)r4rFrvr��
_selected_objr��_obj_with_exclusionsrs�temp_setattrrr�r�)r\rdr4rFr�r�r�r�s        rMrhz#GroupByApply.agg_or_apply_list_likesF���h������g���0��0��%�0�0�F��3���"�"�a�'�'�%�&J�K�K�K���!�Q�&�&��,�L�L��3�L��
���T�W�S�*�-E�-E�
�
�
�	R�	R�!�2�2�7�L�&�Q�Q�M�D�'�	R�	R�	R�	R�	R�	R�	R�	R�	R�	R�	R����	R�	R�	R�	R��,�,�T�7�;�;���
s�B-�-B1�4B1c	��ddlm}m}|dvsJ�|j}i}|dkr"|jrdnd}|�d|i��t
|dd��d	krtd
���|j}|j	}t|||f��}	|	rN|j�dd��}
|j�dd��}|�|
|d
���tj|ddt|d�����5|�||||��\}}
ddd��n#1swxYwY|�|||
��}|S)Nrr�r'rbrVFr;r6rDr$r=r?rRr�Tr�)r�r�r�r4r;r(rvr�r��
_selectionrnrFr�rsr�rr�r�)r\rdr�r�r4rFr;r�r�r�r=r?r�r�r�s               rMrkz#GroupByApply.agg_or_apply_dict_like"s���	
�	
�	
�	
�	
�	
�	
�	
�
�*�*�*�*�*��h�����g���"&�+�8�Y�Y�5�F��M�M�8�V�,�-�-�-��3���"�"�a�'�'�%�&J�K�K�K��(���N�	���&6�
�%F�G�G�
��	N��[�_�_�X�t�4�4�F� �K�O�O�O�T�B�B�M��M�M�V�m�L�L�M�M�M�
�
���T�W�S�*�-E�-E�
�
�
�	�	�)-�(>�(>���y�&�)�)�%�L�+�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��,�,�\�<��U�U���
s�:D"�"D&�)D&)r4r�r5rrArTr)
rrrrr]rbr�rhrkr�r�s@rMr�r��s���������)�)�)�)�
�
�
�
�
�
�&"�"�"�"�"�"�����4%�%�%�%�%�%�%�%rOr�c�F��eZdZUdZded<ded<d
�fd
�Zd�Zd�Z�xZS)�ResamplerWindowApplyrrr6�Resampler | BaseWindowr4r5rrArTc�d��tt|���||dd||���dS)NFr�)r.r�r]r�s     �rMr]zResamplerWindowApply.__init__NsH���	�l�D�!�!�*�*�������
	+�	
�	
�	
�	
�	
rOc��t�r`r�ras rMrbzResamplerWindowApply.apply_r�rOc��t�r`r�ras rMr�zResamplerWindowApply.transformbr�rO)r4rr5rrArT)	rrrr6rr]rbr�r�r�s@rMrrJsz���������D���������
�
�
�
�
�
�""�"�"�"�"�"�"�"�"�"rOr�AggFuncType | None�Mtuple[bool, AggFuncType, tuple[str, ...] | None, npt.NDArray[np.intp] | None]c�0�|duotdi|��}d}d}|sbt|t��r<t|��tt	|����krtd���|�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).rW)�is_multi_agg_with_relabelrnr�r��setrr��normalize_keyword_aggregation)r5rF�
relabelingr��orders     rMrJrJfs���N���E�";�"E�"E�f�"E�"E�J�&*�G�)-�E��
T��d�D�!�!�	�c�$�i�i�#�c�$�i�i�.�.�&@�&@�%����
��<��R�S�S�S��
� =�� 
� 
���g�u������t�W�e�+�+rOc�~�td�|���D����ot|��dkS)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�fK�|],}t|t��ot|��dkV��-dS)r�N)rnrr�r}s  rMrz,is_multi_agg_with_relabel.<locals>.<genexpr>�s;����M�M��z�!�U�#�#�3��A���!��M�M�M�M�M�MrOr)r�rMr�)rFs rMrr�s=��*�M�M�V�]�]�_�_�M�M�M�M�M���F���a��rOrFr��]tuple[MutableMapping[Hashable, list[AggFuncTypeBase]], tuple[str, ...], npt.NDArray[np.intp]]c���ddlm}tt��}g}tt	|������\}}|D]K\}}||�|��|�|tj|��p|f���Lt|��}d�|���D��}	t|	��}
||
���
|��}|||fS)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�c�N�g|]"\}}|D]}|tj|��p|f���#SrWr{)r~�column�aggfuncs�aggfuncs    rMr�z1normalize_keyword_aggregation.<locals>.<listcomp>�sX������F�H����
�
��&�w�/�/�:�7�;����rO)�pandas.core.indexes.baser-rr�r�r�r�rsr|�_make_unique_kwarg_list�get_indexer)rFr-�aggspecrr��pairsrr�uniquified_order�
aggspec_order�uniquified_aggspec�
col_idx_orders            rMr
r
�s��</�.�.�.�.�.�
�$���G��E��#�v�|�|�~�~�.�/�/�N�G�U� �J�J���������w�'�'�'�
���f�c�3�G�<�<�G��H�I�I�I�I�/�u�5�5��
�� '�
�
������M�
1��?�?���E�,�-�-�9�9�:J�K�K�M��G�]�*�*rO�seq�Sequence[tuple[Any, Any]]c�:���fd�t���D��S)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>')]
    c���g|]P\}}��|��dkr0|d|d�d�d|��|����fn|��QS)rDrrLN)�count)r~rx�pairr!s   �rMr�z+_make_unique_kwarg_list.<locals>.<listcomp>sv�������A�t�:=���4���1�9L�9L��a��T�!�W�4�4�s�2�A�2�w�}�}�T�2�2�4�4�5�5�RV���rO)r�)r!s`rMrrs4������� ��~�~����rOr�r^�dict[str, list[Callable | str]]r�r�r�
Iterable[int]�dict[Hashable, Series]c�D�ddlm}d�tt||��d����D��}i}d}t	|t
��ot
|j��dk}|���D]�\}	}
||	�	��}|r<d�|
D��}
||j
���|
��}|j|}|||t
|
��z�|_
|�
|d�	��||	<|t
|
��z}��|S)
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��g|]
}|d��S)rrW)r~r&s  rMr�z"relabel_result.<locals>.<listcomp>9s)�������Q����rOc��|dS)NrDrW)�ts rM�<lambda>z relabel_result.<locals>.<lambda>:s
��a��d�rO)r�rDc�d�g|]-}t|t��stj|��n|��.SrW)rnr>rsr|)r~rws  rMr�z"relabel_result.<locals>.<listcomp>XsD�����NO�
�1�c�0B�0B�I��%�a�(�(�(����rOFr�)rr-�sortedr�rnr$r�r�r��dropnar�rr��reindex)
r�r5r�rr-�reordered_indexes�reordered_result_in_dict�idx�reorder_maskr��fun�sr s
             rM�relabel_resultr9sT��F/�.�.�.�.�.���"�3�w��#6�#6�N�N�K�K�K�����8:��
�C�!�&�)�4�4�4�P��V�^�9L�9L�q�9P�L��J�J�L�L�"�"���S��3�K��� � ��,�	&���SV����C�"�E�!�'�N�N�6�6�s�;�;�M���}�%�A�$�C�#��C���.�$8�9���()�	�	�'��	�(F�(F� ��%��C��H�H�n���#�#rOc��ddlm}t|fi|��\}}}}|r'|�J�|�J�t||||��}|||���}|S)Nr)r,r`)r�r,rJr9)r�r5rFr,rr�r�result_in_dicts        rMr�r�fs��� � � � � � �'7��'G�'G��'G�'G�$�J��g�u��
:��"�"�"�� � � �'���g�u�E�E����>��9�9�9���MrOr�
Sequence[Any]c���t|��dkr|Sd}g}|D]N}tj|��dkrt|��}d|�d�|_|dz
}|�|���O|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.
    rDrz<lambda>z<lambda_�>)r�rsr|rrr�)rrx�mangled_aggfuncsrs    rM�_managle_lambda_listr@�s���$�8�}�}������	�A����)�)��� ��)�)�Z�7�7��g�&�&�G�.�!����G��
��F�A�����(�(�(�(��rO�agg_specrc�:�t|��}|st|��s|St|����}|rP|���D]:\}}t|��rt|��st	|��}n|}|||<�;nt	|��}|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)>]
    )rrrr�r@)rA�is_dict�mangled_aggspecr�rr?s      rM�maybe_mangle_lambdasrE�s���2�8�$�$�G���|�H�-�-����$�d�8�n�n�&�&�O��	9�%�^�^�-�-�	4�	4�M�C���H�%�%�
,�l�8�.D�.D�
,�#7��#A�#A� � �#+� �#3�O�C� � �
	4�/�x�8�8���rO�0tuple[list[str], list[str | Callable[..., Any]]]c�^�d}t|��}g}|���D]o}t|t��sCt	|��s4t|�t|��j�����|�	|���p|sd}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.)
r�rMrnr>rrr��formatrrr�)rF�tuple_given_messager�r5�col_func�no_arg_messages      rM�validate_func_kwargsrL�s���.J���6�l�l�G�
�D��M�M�O�O�����8�S�)�)�	Q�X�h�-?�-?�	Q��/�6�6�t�H�~�~�7N�O�O�P�P�P����H������(�M����'�'�'��D�=�rOrdrer�r�c�b�t|t��pt|t��o|dkS)Nrx)rnr"r$)rdr�s  rMr�r��s0���d�L�)�)���4��#�#�8��5�(8�rOrr�aliasrTc	���|�d��r|}nt|��j�d|��}d|�d�}tjd|�d|�d|�d�t
t
�����dS)	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�)�
startswithrrr�r�r�r)r4r5rN�
full_aliass    rMruru�s���

��������
�
��S�	�	�*�4�4�U�4�4�
��E������M�	5��	5�	5��	5�	5�%*�	5�	5�	5��#�%�%�
�����rO)rFNr2r3NNN)r4r,r5rr6rr7r8r9r:r;r<r=r>r?r@rArB)r5rrAr	)rAr8)rFr�rAr)r!r"rAr")
r�r^r5r'r�r�rr(rAr)r)rr<rAr<)rArrAr)rFr�rArF)rdrer�r�rAr8)r4rr5rrNr>rArT)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�commonrs�pandas.core.constructionr&�collections.abcr'r(r)r*r+r�r,r-r.�pandas.core.groupbyr/�pandas.core.resampler0�pandas.core.window.rollingr1r��intrDrN�ABCMetarQrrBrHrIr%r�rrJrr
rr9r�r@rErLr�rurWrOrM�<module>rps��"�"�"�"�"�"�
�
�
�
�#�#�#�#�#�#�������������������������������������)�)�)�)�)�)�������2�2�2�2�2�2�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�?�>�>�>�>�>�,�,�,�,�,�,�2�2�2�2�2�2�4�4�4�4�4�4�4�4�4�4�4�4���������������������������������>�=�=�=�=�=� � � � � � � � � �C�C�C�C�C�C��6�������������������������
,�+�+�+�+�+�.�.�.�.�.�.�5�5�5�5�5�5��s�C�x�.����"�'/��,0�	
��!�!�!�!�!�HL	&�L	&�L	&�L	&�L	&�c�k�L	&�L	&�L	&�L	&�^:�:�:�:�:�5�:�:�:�zi#�i#�i#�i#�i#��i#�i#�i#�Xb�b�b�b�b�J�b�b�b�JA�A�A�A�A�z�A�A�A�HR�R�R�R�R�,�R�R�R�j[�[�[�[�[�5�[�[�[�|"�"�"�"�"�<�"�"�"�8B,�B,�B,�B,�J����4:+�:+�:+�:+�z����$O$�O$�O$�O$�d����6����B)�)�)�)�X!�!�!�!�H���������rO