HOME


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

���h�>���ddlmZddlZddlZddlZddlZddlZddlZ	ddl
mZddlm
Z
mZddlmZmZmZmZmZmZmZ	ddlZn
#e$reZYnwxYw	ddlmZdZn
#e$rdZYnwxYwgd	�Zgd
�Z gd�Z!e
se!�"d��d
dgZ#gd�Z$ddgZ%ddgZ&gd�Z'eddfd�Z(dOd�Z)e(d��Z*e(d��Z+e(de	��Z,e(de	��Z-e(d��Z.e(dd���Z/e(d��Z0e(d��Z1e(de��Z2e(d d�!��Z3e(d"ed�!��Z4e(d��Z5e(d��Z6d#�Z7dPd$�Z8dPd%�Zd&�Z9d'�Z:dQd*�Z;d+�Z<d,�Z=d-�Z>d.�Z?dRd/�Z@d0ZAdRd1�ZBd2�ZCejDfd3�ZEejFd4���ZGdSd5�ZHeHd6d�7��ZIeHd8d�7��ZJeHd9d�7��ZKeHd:d�7��ZLeHd;d�<��ZMeHd=d�<��ZNeHd>d�<��ZOeHd?d�<��ZPeHd@d�<��ZQee)dA�B��ZRe(dC��ZSdOdD�ZTdeT_UdRdE�ZVdRdF�ZWdG�ZXdH�ZYdI�ZZe[dJ�e!D����Z\dK�Z]dTdL�Z^dUdN�Z_dS)V�)�partialN�)�npcompat)�PY3�dask_array_type)�nanfirst�nanlast�interleaved_concat�array_eq�array_ne�_validate_axis�_calc_concat_shapeTF)�neg�pos�abs�invert)�lt�le�ge�gt)
�add�sub�mul�truediv�floordiv�mod�pow�and�xor�or�div�item�searchsorted)�astype�argsort�clip�conj�	conjugate�isnull�notnull�all�any)
�argmax�argmin�max�min�mean�prod�sum�std�var�medianc�:�����tr	����fd�}n��fd�}|S)Nc����r|dn|}td�|d��D����rt}n�}t|���|i|��S)Nrc3�JK�|]}t|tj��V��dS�N)�
isinstance�da�Array)�.0�as  �D/opt/cloudlinux/venv/lib/python3.11/site-packages/xarray/core/ops.py�	<genexpr>z1_dask_or_eager_func.<locals>.f.<locals>.<genexpr>9sB����:�:���a���*�*�:�:�:�:�:�:�)r,r<�getattr)�args�kwargs�
dispatch_args�module�eager_module�list_of_args�n_array_args�names    ����r@�fz_dask_or_eager_func.<locals>.f7sw���'3�=�D��G�G��M��:�:�)�-�<�-�8�:�:�:�:�:�
&����%��(�7�6�4�(�(�$�9�&�9�9�9rBc�8��t����|g|�Ri|��Sr:)rC)�datarDrErHrKs   ��r@rLz_dask_or_eager_func.<locals>.f@s-���.�7�<��.�.�t�E�d�E�E�E�f�E�E�ErB)�has_dask)rKrHrIrJrLs```` r@�_dask_or_eager_funcrP4se�������F�	:�	:�	:�	:�	:�	:�	:�	:�	:�	F�	F�	F�	F�	F�	F��HrBc��t|t��r7|�d}|�tj��dd}t	||z���dS)Nz'%r is not a valid method on dask arraysr�)r;r�inspect�stack�NotImplementedError)�values�msg�	func_names   r@�_fail_on_dask_array_inputrYEsU���&�/�*�*�3��;�;�C����
����*�1�-�I�!�#�	�/�2�2�2�3�3rB�around�isclose�	transpose�whererR)rJ�insert�take�broadcast_to�concatenate)rIrTc�.�d}|D]�}t|t��r!|jpd|ks	|jdvrdS|j}�8tj|��}tj|||jz��}||k�	��rdS|ddz}��dS)a�With dask, we care about data locality and would rather avoid splitting
    splitting up each arrays into single elements. This routine checks to see
    if we really need the "interleaved" part of interleaved_concat.

    We don't use for the pure numpy version of interleaved_concat, because it's
    just as fast or faster to directly do the interleaved concatenate rather
    than check if we could simply it.
    r)rNT���rF)
r;�slice�start�step�stop�np�asarray�arange�sizer,)�indices�
next_expected�ind�expecteds    r@�_interleaved_indices_requiredrp`s����M��(�(���c�5�!�!�
	(����a�M�1�1��H�I�-�-��t�t��H�M�M��*�S�/�/�C��y��
���0H�I�I�H��x��$�$�&�&�
��t�t���G�a�K�M�M��5rBc����t�d����t�����}|�}tj|t���}tj|t���}t|��D]Z\}}t
|t��r!tj|�	|���}t|��D]\}	}
|||
<|	||
<��[��fd�t||��D��}t|���S)zHA slow version of interleaved_concat that also works on dask arrays
    r��axis)�dtypec	�~��g|]9\}}�|td��f�zt||dz��fz��:S)Nr)rd)r>�n�m�arraysrss   ��r@�
<listcomp>z,_interleaved_concat_slow.<locals>.<listcomp>�s]���E�E�E���A��1�I�u�T�{�{�n�t�3�u�Q��A����6H�H�I�E�E�ErB)r
rrh�empty�int�	enumerater;rdrjrl�zipra)rxrlrs�result_shape�length�array_lookup�element_lookuprvrnrw�i�split_arrayss` `         r@�_interleaved_concat_slowr�ys%�����&��)�T�*�*�D�%�f�4�8�8�8�L�
�$�
�F��8�F�#�.�.�.�L��X�f�C�0�0�0�N��G�$�$�"�"���3��c�5�!�!�	2��)�S�[�[��0�0�1�C��c�N�N�	"�	"�D�A�q��L��O� !�N�1���	"�E�E�E�E�E�"%�l�N�"C�"C�E�E�E�L��|�T�*�*�*rBc���trUt|dtj��r5t	|��stj||��St
|||��St|||��S)z�Concatenate each array along the given axis, but also assign each array
    element into the location given by indices. This operation is used for
    groupby.transform.
    r)rOr;r<r=rprar��_interleaved_concat_numpy)rxrlrss   r@r
r
�sl��
�@�J�v�a�y�"�(�3�3�@�,�W�5�5�	C��>�&�$�/�/�/�+�F�G�T�B�B�B�(���$�?�?�?rBc�X�t|t��r|ntj|��Sr:)r;rrhri�rNs r@riri�s%���d�O�4�4�J�4�4�"�*�T�:J�:J�JrBc�j�td�|D����r|Std�|D����S)Nc3�@K�|]}t|t��V��dSr:)r;r�r>�ds  r@rAz!as_like_arrays.<locals>.<genexpr>�s,����
8�
8�a�:�a��)�)�
8�
8�
8�
8�
8�
8rBc3�>K�|]}tj|��V��dSr:)rhrir�s  r@rAz!as_like_arrays.<locals>.<genexpr>�s*����1�1�q�R�Z��]�]�1�1�1�1�1�1rB)r+�tupler�s r@�as_like_arraysr��sC��
�
8�
8�4�
8�
8�
8�8�8�2����1�1�D�1�1�1�1�1�1rB��h㈵��>�:�0�yE>c	��t||��\}}|j|jkrdStt||||d��������S)zFLike np.allclose, but also allows values to be NaN in both arrays
    FT)�rtol�atol�	equal_nan)r��shape�boolr[r+)�arr1�arr2r�r�s    r@�allclose_or_equivr��sX�� ��d�+�+�J�D�$��z�T�Z����u����d��D�D�I�I�I�M�M�O�O�P�P�PrBc���t||��\}}|j|jkrdSt||kt|��t|��zz�����S)zILike np.array_equal, but also allows values to be NaN in both arrays
    F)r�r�r�r)r+)r�r�s  r@�array_equivr��s_�� ��d�+�+�J�D�$��z�T�Z����u��$�$�,�6�$�<�<�&��,�,�#>�?�D�D�F�F�G�G�GrBc��	t||��}||i|��S#t$r9t||���t|d��rt|j|����wxYw)N)rXrN)rC�AttributeErrorrY�hasattrrN)�argrKrDrE�methods     r@�_call_possibly_missing_methodr��s���'���d�#�#���v�t�&�v�&�&�&��
����!�#��6�6�6�6��3����	@�%�c�h�$�?�?�?�?�
�	���s
��AAc�h���fd�}�|_ttj���j|_|S)Nc�2��t|j�||��Sr:)r�rN��selfrDrErKs   �r@�funcz$_values_method_wrapper.<locals>.func�s���,�T�Y��d�F�K�K�KrB��__name__rCrh�ndarray�__doc__�rKr�s` r@�_values_method_wrapperr��sC���L�L�L�L�L��D�M��2�:�t�,�,�4�D�L��KrBc�h���fd�}�|_ttj���j|_|S)Nc�(��t|�||��Sr:)r�r�s   �r@r�z_method_wrapper.<locals>.func�s���,�T�4��v�F�F�FrBr�r�s` r@�_method_wrapperr��sC���G�G�G�G�G��D�M��2�:�t�,�,�4�D�L��KrBc�N������j���fd�}�|_�j|_|S)Nc�j��	t|���|i|��S#t$r�|g|�Ri|��cYSwxYwr:)rCr�)r�rDrErLrKs   ��r@r�z(_func_slash_method_wrapper.<locals>.func�sh���	,�&�7�4��&�&��7��7�7�7���	,�	,�	,��1�T�+�D�+�+�+�F�+�+�+�+�+�	,���s��2�2)r�r�)rLrKr�s`` r@�_func_slash_method_wrapperr��sG�����|��z��,�,�,�,�,�,�
�D�M��9�D�L��KrBa�Reduce this {cls}'s data by applying `{name}` along some
        dimension(s).

        Parameters
        ----------
        {extra_args}
        skipna : bool, optional
            If True, skip missing values (as marked by NaN). By default, only
            skips missing values for float dtypes; other dtypes either do not
            have a sentinel missing value (int) or skipna=True has not been
            implemented (object, datetime64 or timedelta64).
        keep_attrs : bool, optional
            If True, the attributes (`attrs`) will be copied from the original
            object to the new one.  If False (default), the new object will be
            returned without attributes.
        **kwargs : dict
            Additional keyword arguments passed on to `{name}`.

        Returns
        -------
        reduced : {cls}
            New {cls} object with `{name}` applied to its data and the
            indicated dimension(s) removed.
        c�@�tt|��|���S)zJCount the number of non-NA in this array along the given axis or axes
    rr)r3r))rNrss  r@�countr�s����t���}�4�(�(�(�(rBc�>�tt|��||��S)z}Fill missing values in this object with data from the other object.
    Follows normal broadcasting and alignment rules.
    )r]r))rN�others  r@�fillnar�s�������u�d�+�+�+rBc�$�t|||��S)z�Select values from this object that are True in cond. Everything else
    gets masked with other. Follows normal broadcasting and alignment rules.
    )r])rN�condr�s   r@�where_methodr�s����t�U�#�#�#rBc#�K�|rFtj��5tjd��dV�ddd��dS#1swxYwYdSdV�dS)N�ignore)�warnings�catch_warnings�simplefilter)�	conditions r@�_ignore_warnings_ifr�s�������
�
$�
&�
&�	�	��!�(�+�+�+��E�E�E�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	�	�����s�>�A�Ac�&���d��fd�	}||_|S)Nc����|�dd��|�dd��t|��}�	r(|jjdvr|�t
��}|s|��|jjdvrw|jjdvrt
d�
�d|j�����d�
z}t|t��s|jj	st}nt}t||��}|tu}nt�
��}d	}t|��5	||fd
|i|��cddd��S#t$r4t|t��rd�
z}n	|sJ�d�
z}t
|���wxYw#1swxYwYdS)
Nrt�out�SU�cf)r�rL�cz$skipna=True not yet implemented for z with dtype �nanFrsz(%s is not yet implemented on dask arraysz�%s is not available with skipna=False with the installed version of numpy; upgrade to numpy 1.9 or newer to use skipna=True or skipna=None)�poprirt�kindr$�objectrUr;r��isnativerh�bnrPr�r�r)rVrs�skipnarE�nannamerHr��using_numpy_nan_funcrW�coerce_stringsrKs         ��r@rLz!_create_nan_agg_method.<locals>.f!s���	�
�
�7�D�!�!�!��
�
�5�$����������	+�f�l�/�4�7�7��]�]�6�*�*�F��	)�f�n���):�d�)B�)B��|� ��7�7�)�)��t�t�V�\�\�+�,�,�,��d�l�G��$��&�&�
"�f�l�.C�
"� "���!��&�w��=�=�D�#/�2�#5� � �&�t�,�,�D�#(� �
 �!5�
6�
6�	/�	/�

/��t�F�8�8��8��8�8�	/�	/�	/�	/�	/�	/�	/�	/��"�
/�
/�
/��f�o�6�6�P�D�t�K�C�C�/�/�/�/�H�JN�O�C�*�#�.�.�.�
/����	/�	/�	/�	/����	/�	/�	/�	/�	/�	/s$�E*�
D)�)>E'�'E*�*E.�1E.�NN��numeric_only)rKr�r�rLs` ` r@�_create_nan_agg_methodr� s6����'/�'/�'/�'/�'/�'/�'/�P"�A�N��HrBr-)r�r.r/r0r3r�r1r4r5r6z9%r with skipna=True is not yet implemented on dask arrays)rWr2c���|s|�X|jjdkrH|jjdvrtd|jz���t|��t	j|fd|i|��St
|fd|i|��S)NrL)r�rLz6skipna=True not yet implemented for prod with dtype %srs)rtr�rU� _fail_on_dask_array_input_skipnar�nanprod�_prod)rVrsr�rEs    r@r2r2`s���
�=�&�.�V�\�%6�#�%=�%=��<��J�.�.�%�H��,�� � �
 �	)��0�0�0����<�<�T�<�V�<�<�<���-�-�d�-�f�-�-�-rBc��|s|�-|jjdvrt|��t||��St	|d|���S)zHReturn the first non-NA elements in this array along the given axis
    N�iSUrrr)rtr�r�rr_�rVrsr�s   r@�firstr�lsR��	�&�&�.�f�l�&7�u�&D�&D�(��0�0�0����%�%�%�����%�%�%�%rBc��|s|�-|jjdvrt|��t||��St	|d|���S)zGReturn the last non-NA elements in this array along the given axis
    Nr�rcrr)rtr�r�r	r_r�s   r@�lastr�vsR��	�%�&�.�f�l�&7�u�&D�&D�(��0�0�0��v�t�$�$�$�����&�&�&�&rBc�N�d�tD��d�tD��zdtdfgz}|D]r\}}}t|dd��}|�|||��}||_t�||j|j���|_	t|||���sdS)Nc�B�g|]}|t��d|zdf��S)zarray_%sF��globals�r>rKs  r@ryz)inject_reduce_methods.<locals>.<listcomp>�s9��"�"�"���w�y�y��d�!2�3�U�;�"�"�"rBc�<�g|]}|t��|df��S)Tr�r�s  r@ryz)inject_reduce_methods.<locals>.<listcomp>�s'��M�M�M�$��w�y�y����-�M�M�MrBr�Fr�)rK�cls�
extra_args)�REDUCE_METHODS�NAN_REDUCE_METHODSr�rC�_reduce_methodr��_REDUCE_DOCSTRING_TEMPLATE�format�_reduce_extra_args_docstringr��setattr)r��methodsrKrL�include_skipnar�r�s       r@�inject_reduce_methodsr��s���"�"� �"�"�"�M�M�:L�M�M�M�N��%��'�(�)�G�$+�!�!���a���q�.�%�8�8���!�!�!�^�\�B�B����
�1�8�8��3�<��7�9�9�9���	��T�4� � � � �!�!rBc��d|zS)Nz__%s__��rKs r@�op_strr��s���d�?�rBc�F�ttt|����Sr:)rC�operatorr�r�s r@�get_opr��s���8�V�D�\�\�*�*�*rBc#�XK�|]%}td|z��t|��fV��&dS)r�N)r�r�s  r@rArA�sM����2�2���c�D�j�)�)�6�$�<�<�8�2�2�2�2�2�2rBc��t|Sr:)�NON_INPLACE_OP)rLs r@�inplace_to_noninplace_opr��s
���!��rBc�J�ttzD]@}t|t|��|�t|�������AdtfdtffD]6\}}t|t|��|�|�����7tt��}|�|dd���}t|d|��ttd��}t|d|�|����tD]�}t|td	|z��|�t|��d
�����|rDt|td|z��|�td|z��������dS)
N�eq�ne�leftF)�join�drop_na_vars�_fillnar]�_where�rT)�	reflexiver�)�CMP_BINARY_OPS�NUM_BINARY_OPSr�r��
_binary_opr�rrr�r�r��_inplace_binary_op)r��inplacerKrLr�s     r@�inject_binary_opsr
�s�����/�A�A����V�D�\�\�3�>�>�&��,�,�#?�#?�@�@�@�@��8�$�t�X�&6�7�6�6���a���V�D�\�\�3�>�>�!�#4�#4�5�5�5�5�	#�6�*�*�A�
�^�^�A�F��^�
?�
?�F��C��F�#�#�#�	#�<��9�9�A��C��3�>�>�!�,�,�-�-�-��@�@����V�C�$�J�'�'����v�d�|�|�t��<�<�	>�	>�	>��	@��C���d�
�+�+��*�*�6�#��*�+=�+=�>�>�
@�
@�
@��@�@rB�2c
���||_tD]@}t|t|��|�t|�������At
|d���tD]3}t|||�t|�������4tD]H}ttt|����}t|||�|�����Ittd���}t|d|�|����|r(tD] }t||t|�����!t!|��dS)NT)r�roundr�)�__array_priority__�	UNARY_OPSr�r��	_unary_opr�r
�NUMPY_UNARY_METHODSr��PANDAS_UNARY_FUNCTIONSr�rC�pdrZ�NUMPY_SAME_METHODSr�r�)r��priority�
array_onlyrKrLs     r@�!inject_all_ops_and_reduce_methodsr�s]��&�C���@�@����V�D�\�\�3�=�=�����#>�#>�?�?�?�?��c�4�(�(�(�(�$�A�A����T�3�=�=���)>�)>�?�?�@�@�@�@�&�-�-��&�w�r�4�'8�'8�9�9����T�3�=�=��+�+�,�,�,�,�"�6��8�8�8�A��C��#�-�-��*�*�+�+�+��=�'�	=�	=�D��C��5�d�;�;�<�<�<�<��#�����rBr�)r)r�r�r:)FF)F)rT)`�	functoolsr�
contextlibrSr�r��numpyrh�pandasr�r�pycompatrr�nputilsrr	r
r�rrr
r�
bottleneckr��ImportError�
dask.array�arrayr<rOrrr	�appendrrrr�r�rPrYrZr[r)r*r\r]r^r_r`rarT�	array_all�	array_anyrpr�rir�r�r�r�r�r�r�r�r�r�r�r��contextmanagerr�r�r-r.r/r0r3r1r4r5r6r�r�r2r�r�r�r�r�r��dictr�r�r
rr�rBr@�<module>r+s��������������������������������������*�*�*�*�*�*�*�*������������������������������	�B�B�B�������������H�H�������H�H�H�����
,�+�+�	�)�)�)��-�-�-��
�!����%� � � ��n�-��I�H�H��"�I�.������.�.�.��
,.�E�%&�
�
�
�
�"3�3�3�3�
�	�X�	&�	&��
�
�i�
(�
(��	�	�X�r�	*�	*��
�
�i��
,�
,�����,�,�	���G�!�4�4�4��	�	�X�	&�	&����6�"�"��"�"�>�8�<�<��!�!�-�d�C�C�C����G�X�D�A�A�A�����&�&�	����&�&�	����2+�+�+�+�,@�@�@�@�K�K�K�2�2�2�Q�Q�Q�Q�H�H�H�	'�	'�	'�����������$	��6)�)�)�)�,�,�,�$&�6�$�$�$�$��������*
�*
�*
�*
�Z
 �	���	>�	>�	>��	�	���	>�	>�	>����U�4�8�8�8����U�4�8�8�8����U��6�6�6����f�4�8�8�8����U��6�6�6����U��6�6�6��	�	��t�	<�	<�	<��$+�7��C�$E�$E�$E� �
	��F�#�#��.�.�.�.����&�&�&�&�'�'�'�'�!�!�!����+�+�+���2�2�"0�2�2�2�2�2�����@�@�@�@�2�����s$�A�A�A�A�A&�%A&