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__/utils.cpython-311.pyc
�

���hO0���dZddlZddlZddlZddlZddlZddlZddlmZm	Z	ddl
ZddlZ
ddlmZddlmZmZd*d�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zefd�Zefd�Zd�Zd�Zd�Zejejej fZ!d�Z"d�Z#d�Z$efd�Z%efd�Z&Gd�de'��Z(Gd�dee(��Z)d�Z*Gd�de	e(��Z+Gd �d!e	e(��Z,Gd"�d#e'��Z-Gd$�d%e-��Z.ej/d&���Z0d'�Z1d(�Z2d)�Z3dS)+z(Internal utilties; not for external use
�N)�Mapping�MutableMapping�)�ops)�	iteritems�OrderedDict�c�H�tj|�d|��t|���dS)Nz$ has been deprecated and renamed to )�
stacklevel)�warnings�warn�
FutureWarning)�old_name�new_namers   �F/opt/cloudlinux/venv/lib/python3.11/site-packages/xarray/core/utils.py�
alias_warningrs:���M��X�X�x�x�)��J�8�8�8�8�8�8�c�J���tj�����fd���}|S)Nc�>��t��j���|i|��S�N)r�__name__)�args�kwargs�objrs  ��r�wrapperzfunction_alias.<locals>.wrappers*����h���-�-�-��s�D�#�F�#�#�#r)�	functools�wraps)rrrs`` r�function_aliasrs>�����_�S���$�$�$�$�$���$��Nrc�H����G���fd�d�����j�_�S)Nc�&���eZdZ����fd�Z�xZS)�class_alias.<locals>.Wrapperc�l��t��j��t�|��j|g|�Ri|��Sr)rr�super�__new__)�clsrr�Wrapper�	__class__rrs   ����rr$z$class_alias.<locals>.Wrapper.__new__"sB����(�C�L�1�1�1�.�5��#�&�&�.�s�D�T�D�D�D�V�D�D�Dr)r�
__module__�__qualname__r$�
__classcell__)r'r&rrs@���rr&r!!sT��������	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	Err&)r)rrr&s``@r�class_aliasr+ s`�����E�E�E�E�E�E�E�E�E�#�E�E�E��|�G���Nrc�*�t|tj��r|}nut|d��r|���}nPi}t|d��r|jjdkr
t|d<tjtj	|��fi|��}|S)a9Given an array, safely cast it to a pandas.Index.

    If it is already a pandas.Index, return it unchanged.

    Unlike pandas.Index, if the array has dtype=object or dtype=timedelta64,
    this function will not attempt to do automatic type conversion but will
    always return an index with dtype=object.
    �to_index�dtype�O)
�
isinstance�pd�Index�hasattrr-r.�kind�object�np�asarray)�array�indexrs   r�safe_cast_to_indexr:)s����%���"�"�6����	��
�	#�	#�6���� � ������5�'�"�"�	%�u�{�'7�3�'>�'>�$�F�7�O�����E�*�*�5�5�f�5�5���Lrc��t|tj��r%|j|jkr|�|��S|S)z�Wrap a transformed array with __array_wrap__ is it can be done safely.

    This lets us treat arbitrary functions that take and return ndarray objects
    like ufuncs, as long as they return an array with the same shape.
    )r0r6�ndarray�shape�__array_wrap__)�original�	new_arrays  r�maybe_wrap_arrayrA>s@���)�R�Z�(�(��Y�_���-N�-N��&�&�y�1�1�1��rc��t|tj��st|tj��rtj||��S||up||kS)zuCompare two objects for equivalence (identity or equality), using
    array_equiv if either object is an ndarray
    )r0r6r<r�array_equiv)�first�seconds  r�
equivalentrFKsP���%���$�$�2�
�6�2�:�(F�(F�2���u�f�-�-�-����1�%�6�/�1rc�n�t|��}t|��}|tj|g|��fS)zxReturns the first value from iterable, as well as a new iterable with
    the same content as the original iterable
    )�iter�next�	itertools�chain)�iterable�gen�peeks   r�peek_atrOUs3���x�.�.�C���9�9�D����$���-�-�-�-rc��t|��D]-\}}||vr$||||��std|z����.dS)aHCheck the safety of updating one dictionary with another.

    Raises ValueError if dictionaries have non-compatible values for any key,
    where compatibility is determined by identity (they are the same item) or
    the `compat` function.

    Parameters
    ----------
    first_dict, second_dict : dict-like
        All items in the second dictionary are checked against for conflicts
        against items in the first dictionary.
    compat : function, optional
        Binary operator to determine if two values are compatible. By default,
        checks for equivalence.
    zJunsafe to merge dictionaries without overriding values; conflicting key %rN)r�
ValueError)�
first_dict�second_dict�compat�k�vs     r�update_safety_checkrW^so�� �+�&�&�J�J���1��
�?�?�6�6�!�Z��]�#;�#;�?��E�GH�I�J�J�
J��J�Jrc�p�t|��D]%}||vs||vr|||||��s||=�&dS)a�Remove incompatible items from the first dictionary in-place.

    Items are retained if their keys are found in both dictionaries and the
    values are compatible.

    Parameters
    ----------
    first_dict, second_dict : dict-like
        Mappings to merge.
    compat : function, optional
        Binary operator to determine if two values are compatible. By default,
        checks for equivalence.
    N)�list)rRrSrTrUs    r�remove_incompatible_itemsrZts_���*�
�
����
�[� � �
�+�
�
��F�:�a�=�+�a�.�9�9���1�
��	�rc�B�t|d��ot|d��S)N�__getitem__�keys)r3��values r�is_dict_liker`�s!���5�-�(�(�C�W�U�F�-C�-C�Crc�R�t|t��o|td��kSr)r0�slicer^s r�
is_full_slicerc�s"���e�U�#�#�<���t���(<�<rc�x�|�7t|��std|z���|rtd|z���|S|S)Nz.the first argument to .%s must be a dictionaryz;cannot specify both keyword and positional arguments to .%s)r`rQ)�
pos_kwargs�	kw_kwargs�	func_names   r�combine_pos_and_kw_argsrh�sh�����J�'�'�	*��M�(�)�*�*�
*��	=��0�2;�<�=�=�
=����rc��t|d��r|jdkStj|��pt	|t
��p|duS)z�np.isscalar only works on primitive numeric types and (bizarrely)
    excludes 0-d ndarrays; this version does more comprehensive checks
    �ndimrN)r3rjr6�isscalarr0�
_SCALAR_TYPESr^s r�	is_scalarrm�sR���u�f�����z�Q����K����
��u�m�,�,�
��T�M�rc�`�	tj|��dS#ttf$rYdSwxYw)NTF)r6r.�	TypeErrorrQ�r.s r�is_valid_numpy_dtyperq�sD���
�������t��
�z�"�����u�u����s��-�-c�Z�tjdt���}|g|dd�<d|_|S)N)rrp�)r6�emptyr5r=)r_�results  r�tuple_to_0darrayrv�s1��
�X�d�&�
)�
)�
)�F���F�1�1�1�I��F�L��Mrc�f�|D]!}||vs|||||��sdS�"|D]	}||vrdS�
dS)a�Test equivalence of two dict-like objects. If any of the values are
    numpy arrays, compare them correctly.

    Parameters
    ----------
    first, second : dict-like
        Dictionaries to compare for equality
    compat : function, optional
        Binary operator to determine if two values are compatible. By default,
        checks for equivalence.

    Returns
    -------
    equals : bool
        True if the dictionaries are equal
    FTrs)rDrErTrUs    r�
dict_equivrx�si��"�����F�?�?�&�&��q��6�!�9�"=�"=�?��5�5��
�����E�>�>��5�5���4rc�F�t|��}t|||��|S)a�Return the intersection of two dictionaries as a new OrderedDict.

    Items are retained if their keys are found in both dictionaries and the
    values are compatible.

    Parameters
    ----------
    first_dict, second_dict : dict-like
        Mappings to merge.
    compat : function, optional
        Binary operator to determine if two values are compatible. By default,
        checks for equivalence.

    Returns
    -------
    intersection : OrderedDict
        Intersection of the contents.
    )rrZ)rRrSrT�new_dicts    r�ordered_dict_intersectionr{�s(��&�:�&�&�H��h��V�<�<�<��Orc��eZdZdZd�Zd�ZdS)�SingleSlotPickleMixinz�Mixin class to add the ability to pickle objects whose state is defined
    by a single __slots__ attribute. Only necessary under Python 2.
    c�8�t||jd��S�Nr)�getattr�	__slots__��selfs r�__getstate__z"SingleSlotPickleMixin.__getstate__�s���t�T�^�A�.�/�/�/rc�>�t||jd|��dSr)�setattrr�)r��states  r�__setstate__z"SingleSlotPickleMixin.__setstate__�s!����d�n�Q�'��/�/�/�/�/rN)rr(r)�__doc__r�r�rsrrr}r}�s<��������0�0�0�0�0�0�0�0rr}c�<�eZdZdZdgZd�Zd�Zd�Zd�Zd�Z	d�Z
d	S)
�Frozenz�Wrapper around an object implementing the mapping interface to make it
    immutable. If you really want to modify the mapping, the mutable version is
    saved under the `mapping` attribute.
    �mappingc��||_dSr�r��r�r�s  r�__init__zFrozen.__init__s
������rc��|j|Srr��r��keys  rr\zFrozen.__getitem__����|�C� � rc�*�t|j��Sr)rHr�r�s r�__iter__zFrozen.__iter__s���D�L�!�!�!rc�*�t|j��Sr��lenr�r�s r�__len__zFrozen.__len__	����4�<� � � rc��||jvSrr�r�s  r�__contains__zFrozen.__contains__����d�l�"�"rc�@�t|��j�d|j�d�S�N�(�)��typerr�r�s r�__repr__zFrozen.__repr__�"����:�:�.�.�.�����=�=rN)rr(r)r�r�r�r\r�r�r�r�rsrrr�r��s�����������I����!�!�!�"�"�"�!�!�!�#�#�#�>�>�>�>�>rr�c�4�tt|i|����Sr)r�r)rrs  r�FrozenOrderedDictr�s���+�t�.�v�.�.�/�/�/rc�P�eZdZdZdgZd
d�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
dS)�SortedKeysDictz�An wrapper for dictionary-like objects that always iterates over its
    items in sorted order by key but is otherwise equivalent to the underlying
    mapping.
    r�Nc��|�in||_dSrr�r�s  rr�zSortedKeysDict.__init__s��$�_�r�r�'����rc��|j|Srr�r�s  rr\zSortedKeysDict.__getitem__!r�rc��||j|<dSrr��r�r�r_s   r�__setitem__zSortedKeysDict.__setitem__$s��!���S���rc��|j|=dSrr�r�s  r�__delitem__zSortedKeysDict.__delitem__'s���L����rc�D�tt|j����Sr)rH�sortedr�r�s rr�zSortedKeysDict.__iter__*s���F�4�<�(�(�)�)�)rc�*�t|j��Srr�r�s rr�zSortedKeysDict.__len__-r�rc��||jvSrr�r�s  rr�zSortedKeysDict.__contains__0r�rc�@�t|��j�d|j�d�Sr�r�r�s rr�zSortedKeysDict.__repr__3r�rc�`�t|��|j�����Sr)r�r��copyr�s rr�zSortedKeysDict.copy6s&���t�D�z�z�$�,�+�+�-�-�.�.�.rr)rr(r)r�r�r�r\r�r�r�r�r�r�r�rsrrr�r�s�����������I�:�:�:�:�!�!�!�"�"�"����*�*�*�!�!�!�#�#�#�>�>�>�/�/�/�/�/rr�c�<�eZdZdZdgZd�Zd�Zd�Zd�Zd�Z	d�Z
d	S)
�ChainMapz�Partial backport of collections.ChainMap from Python>=3.3

    Don't return this from any public APIs, since some of the public methods
    for a MutableMapping are missing (they will raise a NotImplementedError)
    �mapsc��||_dSr�r�)r�r�s  rr�zChainMap.__init__Bs
����	�	�	rc�h�|jD]}	||cS#t$rY�wxYwt|���r)r��KeyError)r�r�r�s   rr\zChainMap.__getitem__EsT���y�	�	�G�
��s�|�#�#�#���
�
�
���
�����s�m�m�s��
"�"c�&�||jd|<dSrr�r�s   rr�zChainMap.__setitem__Ms��!��	�!��S���rc��t�r)�NotImplementedError)r�r_s  rr�zChainMap.__delitem__Ps��!�!rc#�~K�t��}|jD]$}|D]}||vr|V�|�|��� �%dSr)�setr��add)r��seenr��items    rr�zChainMap.__iter__Ssb�����u�u���y�	#�	#�G��
#�
#���t�#�#��J�J�J��H�H�T�N�N�N��
#�	#�	#rc�:�tt|�����r)r�rHr�s rr�zChainMap.__len__[s���$�t�*�*�o�o�rN)rr(r)r�r�r�r\r�r�r�r�rsrrr�r�:s���������
��I�������"�"�"�"�"�"�#�#�#�����rr�c�D�eZdZdZed���Zed���Zd�ZdS)�NdimSizeLenMixinz�Mixin class that extends a class that defines a ``shape`` property to
    one that also defines ``ndim``, ``size`` and ``__len__``.
    c�*�t|j��Sr)r�r=r�s rrjzNdimSizeLenMixin.ndimcs���4�:���rc�N�ttj|j����Sr)�intr6�prodr=r�s r�sizezNdimSizeLenMixin.sizegs���2�7�4�:�&�&�'�'�'rc�X�	|jdS#t$rtd���wxYw)Nrzlen() of unsized object)r=�
IndexErrorror�s rr�zNdimSizeLenMixin.__len__ls=��	7��:�a�=� ���	7�	7�	7��5�6�6�6�	7���s��)N)rr(r)r��propertyrjr�r�rsrrr�r�_sc������������X���(�(��X�(�7�7�7�7�7rr�c�R�eZdZdZed���Zed���Zdd�Zd�Zd�Z	dS)	�NDArrayMixinaMixin class for making wrappers of N-dimensional arrays that conform to
    the ndarray interface required for the data argument to Variable objects.

    A subclass should set the `array` property and override one or more of
    `dtype`, `shape` and `__getitem__`.
    c��|jjSr)r8r.r�s rr.zNDArrayMixin.dtypez�
���z��rc��|jjSr)r8r=r�s rr=zNDArrayMixin.shape~r�rNc�:�tj|d|���S)N.rp)r6r7)r�r.s  r�	__array__zNDArrayMixin.__array__�s���z�$�s�)�5�1�1�1�1rc��|j|Sr)r8r�s  rr\zNDArrayMixin.__getitem__�s���z�#��rc�@�t|��j�d|j�d�S)Nz(array=r�)r�rr8r�s rr�zNDArrayMixin.__repr__�s"��!%�d���!4�!4�!4�d�j�j�j�A�Arr)
rr(r)r�r�r.r=r�r\r�rsrrr�r�ss���������� � ��X� �� � ��X� �2�2�2�2����B�B�B�B�Brr�c#�ZK�	dV�dS#t$r|����wxYw)z�Context manager to ensure that a file opened by xarray is closed if an
    exception is raised before the user sees the file object.
    N)�	Exception�close)�fs r�close_on_errorr��sC����
�
�����������	���	�	�	�
����s�
� *c�F�ttjd|����S)Nz^https?\://)�bool�re�search)�paths r�
is_remote_urir��s����	�-��.�.�/�/�/rc���tj|t���}tj|��}tj|���|���fi|��S)z�Return True if values of an array are uniformly spaced and sorted.

    >>> is_uniform_spaced(range(5))
    True
    >>> is_uniform_spaced([-4, 0, 100])
    False

    kwargs are additional arguments to ``np.isclose``
    rp)r6r8�float�diff�isclose�min�max)�arrr�diffss   r�is_uniform_spacedr��sO��
�(�3�e�
$�
$�
$�C��G�C�L�L�E�
�:�e�i�i�k�k�5�9�9�;�;�9�9�&�9�9�9rc�J�	t|��n#t$rYdSwxYwdS)z$Determine whether `v` can be hashed.FT)�hashro)rVs r�hashabler��s;����Q�����������u�u������4s��
 � )r	)4r��
contextlib�datetimerrJr�r�collectionsrr�numpyr6�pandasr1�r�pycompatrrrrr+r:rArFrOrWrZr`rcrh�date�	timedeltarlrmrqrvrxr{r5r}r�r�r�r�r�r��contextmanagerr�r�r�r�rsrr�<module>r�si��������������������	�	�	�	�����/�/�/�/�/�/�/�/���������������,�,�,�,�,�,�,�,�8�8�8�8����������*
�
�
�2�2�2�.�.�.�9C�J�J�J�J�,?I�����*D�D�D�=�=�=�
�
�
��"�H�M�8�3E�F�
����������&0�����4?I�����00�0�0�0�0�F�0�0�0�>�>�>�>�>�W�+�>�>�>�40�0�0� /� /� /� /� /�^�%:� /� /� /�F"�"�"�"�"�~�4�"�"�"�J7�7�7�7�7�v�7�7�7�(B�B�B�B�B�#�B�B�B�2�������0�0�0�:�:�:�����r