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

���h)D���dZddlmZddlZddlmZmZddlmZm	Z	m
Z
mZmZddl
Z
ddlmZddlZddlmZmZmZmZmZddlZddlZddlmZdd	lmZdd
lmZddl m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'dd
l(m)Z)erddl*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1d�Z2d�Z3dmd�Z4d�Z5d�Z6dnd�Z7dnd�Z8dnd�Z9dnd�Z:dod�Z;e	dpdqd%���Z<edpdrd(���Z<dsdrd)�Z<	dsdtd,�Z=d-�Z>dud1�Z?dnd2�Z@dnd3�ZAdvd5�ZBdwd7�ZCd8�ZDd9�ZEd:�ZFedxd=���ZGedyd@���ZGdsdzdB�ZGd{dF�ZHdG�ZId|dJ�ZJe
jK	d}d~dP���ZLddT�ZMejNejNejOejPjQejRejSjQiZTejNdUejOdVejRdWiZUiejNdX�ejOdY�ejRdZ�ejVd[�ejWd\�ejNdX�ejXdX�ejYd]�ejZd]�ej[d^�ej\d^�ej]d_�ej^d_�ej_d`�ej`d`�ejada�ejbda�ejOdYejcdYejRdZejddZejedbejfdbejgdcejhdci�Zid�dg�Zjdh�Zkd�dl�ZldS)�zh
Misc tools for implementing data structures

Note: pandas.core.common is *not* part of the public API.
�)�annotationsN)�abc�defaultdict)�
Collection�	Generator�Hashable�Iterable�Sequence)�partial)�
TYPE_CHECKING�Any�Callable�cast�overload)�lib)�np_version_gte1p24)�'construct_1d_object_array_from_listlike)�
is_bool_dtype�
is_integer)�ABCExtensionArray�ABCIndex�
ABCMultiIndex�	ABCSeries)�iterable_not_string)�AnyArrayLike�	ArrayLike�NpDtype�RandomState�T)�Indexc#�fK�|D]+}t|��rt|��Ed{V���'|V��,dS)a
    Flatten an arbitrarily nested sequence.

    Parameters
    ----------
    line : sequence
        The non string sequence to flatten

    Notes
    -----
    This doesn't consider strings sequences.

    Returns
    -------
    flattened : generator
    N)r�flatten)�line�elements  �I/opt/cloudlinux/venv/lib64/python3.11/site-packages/pandas/core/common.pyr"r">s_����"�����w�'�'�	��w�'�'�'�'�'�'�'�'�'�'��M�M�M�M�	��c�z�|dj}|dd�D]"}	|j|krd}�#t$rd}Y�wxYw|S)Nr�)�name�
ValueError)�objsr)�objs   r%�consensus_name_attrr-Vse����7�<�D��A�B�B�x����	��x�4��������	�	�	��D�D�D�	�����Ks�
)�8�8�keyr
�return�boolc�J�t|ttjtt
f��r�t|t��s|jtjkrStj	|��}tj|��s)d}tj|d���rt|���dSdSt|j��rdSnat|t��rLt|��dkr9t!|��turt|��}tj|��SdS)a�
    Check whether `key` is a valid boolean indexer.

    Parameters
    ----------
    key : Any
        Only list-likes may be considered boolean indexers.
        All other types are not considered a boolean indexer.
        For array-like input, boolean ndarrays or ExtensionArrays
        with ``_is_boolean`` set are considered boolean indexers.

    Returns
    -------
    bool
        Whether `key` is a valid boolean indexer.

    Raises
    ------
    ValueError
        When the array is an object-dtype ndarray or ExtensionArray
        and contains missing values.

    See Also
    --------
    check_array_indexer : Check that `key` is a valid array to index,
        and convert to an ndarray.
    z=Cannot mask with non-boolean array containing NA / NaN valuesT)�skipnaFr)�
isinstancer�np�ndarrayrrr�dtype�object_�asarrayr�
is_bool_arrayr*r�list�len�type�is_bool_list)r.�	key_array�na_msgs   r%�is_bool_indexerr@as��8��i���X�/@�
A���)���m�,�,�)��9��
�"�"��
�3���I��$�Y�/�/�
�X���$�Y�t�<�<�<�-�%�V�,�,�,��u��4�
�3�9�
%�
%�	��4�	�	�C��	�	�)��s�8�8�a�<�<��C�y�y��$�$��3�i�i���#�C�(�(�(��5r&c�t�tj|��r#|���rtd���|S)z�
    Disallow indexing with a float key, even if that key is a round number.

    Parameters
    ----------
    val : scalar

    Returns
    -------
    outval : scalar
    zYIndexing with a float is no longer supported. Manually convert to an integer key instead.)r�is_floatr�
IndexError)�vals r%�cast_scalar_indexerrE�sE���|�C���
�S�^�^�-�-�
��
)�
�
�	
�
�Jr&c��d�|D��S)zL
    Returns a generator consisting of the arguments that are not None.
    c3�K�|]}|�|V��	dS�N���.0�args  r%�	<genexpr>znot_none.<locals>.<genexpr>�s"����3�3�C�3�?�C�?�?�?�?�3�3r&rI��argss r%�not_nonerP�s��4�3�4�3�3�3�3r&c�4�td�|D����S)z?
    Returns a boolean indicating if any argument is None.
    c3�K�|]}|duV��	dSrHrIrJs  r%rMzany_none.<locals>.<genexpr>��&����+�+�s�s�d�{�+�+�+�+�+�+r&��anyrNs r%�any_nonerV��!���+�+�d�+�+�+�+�+�+r&c�4�td�|D����S)zA
    Returns a boolean indicating if all arguments are None.
    c3�K�|]}|duV��	dSrHrIrJs  r%rMzall_none.<locals>.<genexpr>�rSr&��allrNs r%�all_noner\�rWr&c�4�td�|D����S)zC
    Returns a boolean indicating if any argument is not None.
    c3�K�|]}|duV��	dSrHrIrJs  r%rMzany_not_none.<locals>.<genexpr>��&����/�/�3�s�$��/�/�/�/�/�/r&rTrNs r%�any_not_noner`��!���/�/�$�/�/�/�/�/�/r&c�4�td�|D����S)zE
    Returns a boolean indicating if all arguments are not None.
    c3�K�|]}|duV��	dSrHrIrJs  r%rMzall_not_none.<locals>.<genexpr>�r_r&rZrNs r%�all_not_nonerd�rar&�intc�4�td�|D����S)z;
    Returns the count of arguments that are not None.
    c3�K�|]}|duV��	dSrHrI�rK�xs  r%rMz!count_not_none.<locals>.<genexpr>�s&����+�+��q��}�+�+�+�+�+�+r&)�sumrNs r%�count_not_nonerk�rWr&.�values�ArrayLike | list | tuple | zipr6�NpDtype | None�
np.ndarrayc��dSrHrI�rlr6s  r%�asarray_tuplesaferr�s	���Cr&r	rc��dSrHrIrqs  r%rrrr�����Cr&c�0�t|ttf��s t|d��st|��}n8t|t��r|jSt|t��r|jSt|t��r$|tjtfvrt|��S	tj��5tstjdtj��tj||���}ddd��n#1swxYwYn#t"$rt|��cYSwxYwt%|jjt*��rtj|t���}|jdkrd�|D��}t|��}|S)N�	__array__�ignore�r6�c�,�g|]}t|����SrI)�tuplerhs  r%�
<listcomp>z%asarray_tuplesafe.<locals>.<listcomp>s��+�+�+�q�%��(�(�+�+�+r&)r3r:r{�hasattrr�_valuesrr4r7�objectr�warnings�catch_warningsr�simplefilter�VisibleDeprecationWarningr8r*�
issubclassr6r<�str�ndim)rlr6�results   r%rrrr�s����v��e�}�-�-�����1M�1M���f�����	�F�H�	%�	%���~��	�F�I�	&�	&���~���&�$���?�E�b�j�&�-A�$A�$A�6�v�>�>�>�?�
�
$�
&�
&�	5�	5�%�
N��%�h��0L�M�M�M��Z��e�4�4�4�F�		5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5���
�?�?�?�
7�v�>�>�>�>�>�?�����&�,�#�S�)�)�2���F�&�1�1�1��
�{�a���+�+�F�+�+�+��8��@�@���Ms6�/D�=D�?D�D�D�D�D�D3�2D3�labels�np.ndarray | Iterablec���t|ttf��r|g}t|ttjf��s$	t|��}n#t$r|g}YnwxYwt||���}|S)z�
    Transform label or iterable of labels to array, for use in Index.

    Parameters
    ----------
    dtype : dtype
        If specified, use as dtype of the resulting array, otherwise infer.

    Returns
    -------
    array
    rx)r3r�r{r:r4r5�	TypeErrorrr)r�r6s  r%�index_labels_to_arrayr�
s����&�3��,�'�'������f�t�R�Z�0�1�1��	��&�\�\�F�F���	�	�	��X�F�F�F�	�����v�U�
3�
3�
3�F��Ms�A�
A"�!A"c�H�|�t|ttf��s|gS|SrH)r3r{r:�r,s r%�maybe_make_listr�'s%��
��z�#��t�}�=�=���u���Jr&r,�Iterable[T] | T�Collection[T] | Tc��t|tj��r)t|tj��st	|��Stt|��}|S)zB
    If obj is Iterable but not list-like, consume into list.
    )r3rr	�Sizedr:rrr�s r%�maybe_iterable_to_listr�-sK���#�s�|�$�$��Z��S�Y�-G�-G���C�y�y��
�z�3�
�
�C��Jr&c�b�t|t��o|jduo|jduo|jduS)z
    We have a null slice.
    N�r3�slice�start�stop�stepr�s r%�
is_null_slicer�7sE��
	�3����	��I���	��H���	�
�H���	r&c�p�t|t��o!|jduo|jduo|j|jkS)z>
    We have an empty slice, e.g. no values are selected.
    N)r3r�r�r�r�s r%�is_empty_slicer�CsG��
	�3����	"��I�T�!�	"��H�D� �	"�
�I���!�	r&�
list[bool]c��d�|D��S)zX
    Find non-trivial slices in "line": return a list of booleans with same length.
    c�X�g|]'}t|t��ot|����(SrI)r3r�r�)rK�ks  r%r|z"is_true_slices.<locals>.<listcomp>Ss2��H�H�H�a�J�q�%� � �9��q�)9�)9�%9�H�H�Hr&rI)r#s r%�is_true_slicesr�Os��I�H�4�H�H�H�Hr&r#c�j�t|t��o|jdko|j|ko|jduS)z&
    We have a full length slice.
    rNr�)r,r#s  r%�
is_full_slicer�WsD��
	�3����	��I��N�	��H���	�
�H���	r&c���t|d��rt|d��St|t��rt	|j��St
|��rt|��jSdS)N�__name__)	r}�getattrr3r�get_callable_name�func�callabler<r�r�s r%r�r�csj���s�J���(��s�J�'�'�'��#�w���+� ���*�*�*���}�}�"��C�y�y�!�!�
�4r&c�6�t|��r	||fi|��S|S)z�
    Evaluate possibly callable input using obj and kwargs if it is callable,
    otherwise return as it is.

    Parameters
    ----------
    maybe_callable : possibly a callable
    obj : NDFrame
    **kwargs
    )r�)�maybe_callabler,�kwargss   r%�apply_if_callabler�ts2������-��~�c�,�,�V�,�,�,��r&c�6�tj|��s>t|t��rt	t|j��St
|��}t|tj	��std|�����|tkrtd���|S)a
    Helper function to standardize a supplied mapping.

    Parameters
    ----------
    into : instance or subclass of collections.abc.Mapping
        Must be a class, an initialized collections.defaultdict,
        or an instance of a collections.abc.Mapping subclass.

    Returns
    -------
    mapping : a collections.abc.Mapping subclass or other constructor
        a callable object that can accept an iterator to create
        the desired Mapping.

    See Also
    --------
    DataFrame.to_dict
    Series.to_dict
    zunsupported type: z/to_dict() only accepts initialized defaultdicts)�inspect�isclassr3rr�default_factoryr<r�r�Mappingr�)�intos r%�standardize_mappingr��s���*�?�4� � ���d�K�(�(�	>��;��(<�=�=�=��D�z�z���d�C�K�(�(�5��3�T�3�3�4�4�4��{����I�J�J�J��Kr&�state�np.random.Generatorc��dSrHrI�r�s r%�random_stater��rtr&�Hint | np.ndarray | np.random.BitGenerator | np.random.RandomState | None�np.random.RandomStatec��dSrHrIr�s r%r�r��s	���Cr&�RandomState | Nonec�r�t|��s+t|tjtjjf��rtj�|��St|tjj��r|St|tjj��r|S|�tjStd���)aq
    Helper function for processing random_state arguments.

    Parameters
    ----------
    state : int, array-like, BitGenerator, Generator, np.random.RandomState, None.
        If receives an int, array-like, or BitGenerator, passes to
        np.random.RandomState() as seed.
        If receives an np.random RandomState or Generator, just returns that unchanged.
        If receives `None`, returns np.random.
        If receives anything else, raises an informative ValueError.

        Default None.

    Returns
    -------
    np.random.RandomState or np.random.Generator. If state is None, returns np.random

    Nzdrandom_state must be an integer, array-like, a BitGenerator, Generator, a numpy RandomState, or None)	rr3r4r5�random�BitGeneratorrrr*r�s r%r�r��s���(�%���
�J�u�r�z�2�9�;Q�.R�S�S�
��y�$�$�U�+�+�+�	�E�2�9�0�	1�	1�

���	�E�2�9�.�	/�	/�
���	���y���
+�
�
�	
r&r��/Callable[..., T] | tuple[Callable[..., T], str]rc��t|t��r*|\}}||vr|�d�}t|���|||<||i|��S||g|�Ri|��S)as
    Apply a function ``func`` to object ``obj`` either by passing obj as the
    first argument to the function or, in the case that the func is a tuple,
    interpret the first element of the tuple as a function and pass the obj to
    that function as a keyword argument whose key is the value of the second
    element of the tuple.

    Parameters
    ----------
    func : callable or tuple of (callable, str)
        Function to apply to this object or, alternatively, a
        ``(callable, data_keyword)`` tuple where ``data_keyword`` is a
        string indicating the keyword of ``callable`` that expects the
        object.
    *args : iterable, optional
        Positional arguments passed into ``func``.
    **kwargs : dict, optional
        A dictionary of keyword arguments passed into ``func``.

    Returns
    -------
    object : the return type of ``func``.
    z/ is both the pipe target and a keyword argument)r3r{r*)r,r�rOr��target�msgs      r%�piper��s���4�$����*����f��V����L�L�L�C��S�/�/�!���v���t�T�$�V�$�$�$��t�C�)�$�)�)�)�&�)�)�)r&c�X���fd�}t�tjtf��r|n�S)zv
    Returns a function that will map names/labels, dependent if mapper
    is a dict, Series or just a function.
    c� ��|�vr�|S|SrHrI)ri�mappers �r%�fzget_rename_function.<locals>.f�s�����;�;��!�9���Hr&)r3rr�r)r�r�s` r%�get_rename_functionr��s>���������6�C�K��#;�<�<�H�1�1�&�Hr&�"Hashable | Iterable | AnyArrayLike�list | AnyArrayLikec���t|ttjtt
tf��r|St|tj��r$t|t��st|��S|gS)z�
    Convert list-like or scalar input to list-like. List, numpy and pandas array-like
    inputs are returned unmodified whereas others are converted to list.
    )
r3r:r4r5rrrrr	r�)rls r%�convert_to_list_liker�sa���&�4���X�y�BS�T�U�U���
�	�F�C�L�	)�	)��*�V�S�2I�2I���F�|�|���8�Or&T�attrr��	condition�Generator[None, None, None]c#�K�|r!t||��}t|||��	|V�|rt|||��dSdS#|rt|||��wwxYw)a�
    Temporarily set attribute on an object.

    Parameters
    ----------
    obj : object
        Object whose attribute will be modified.
    attr : str
        Attribute to modify.
    value : Any
        Value to temporarily set attribute to.
    condition : bool, default True
        Whether to set the attribute. Provided in order to not have to
        conditionally use this context manager.

    Yields
    ------
    object : obj with modified attribute.
    N)r��setattr)r,r��valuer��	old_values     r%�temp_setattrr�s�����.�"��C��&�&�	���T�5�!�!�!�*��	�	�	��	*��C��y�)�)�)�)�)�	*�	*��9�	*��C��y�)�)�)�)�	*���s�A�A�indexr �Nonec��t|��t|��kr0tdt|���dt|���d����dS)zC
    Check the length of data matches the length of the index.
    zLength of values (z") does not match length of index (�)N)r;r*)�datar�s  r%�require_length_matchr�8sg���4�y�y�C��J�J����
��D�	�	�
�
��E�
�
�
�
�
�
�
�	
��r&znp.sumznp.maximum.reduceznp.minimum.reducerj�max�minr[rU�mean�prod�std�var�median�cumprod�cumsumrLr�
str | Nonec�6�t�|��S)zH
    if we define an internal function for this argument, return it
    )�
_cython_table�get�rLs r%�get_cython_funcr�rs�����S�!�!�!r&c�8�t�||��S)zd
    if we define a builtin function for this argument, return it,
    otherwise return the arg
    )�_builtin_tabler�r�s r%�is_builtin_funcr�ys��
���c�3�'�'�'r&�names�Sequence[Hashable | None]�list[Hashable]c�4�d�t|��D��S)a,
    If a name is missing then replace it by level_n, where n is the count

    .. versionadded:: 1.4.0

    Parameters
    ----------
    names : list-like
        list of column names or None values.

    Returns
    -------
    list
        list of column names with the None values replaced.
    c�&�g|]\}}|�d|��n|��S)N�level_rI)rK�ir)s   r%r|z&fill_missing_names.<locals>.<listcomp>�s*��S�S�S�w�q�$�D�L�L�Q�L�L�L�d�S�S�Sr&)�	enumerate)r�s r%�fill_missing_namesr��s!�� T�S�)�E�BR�BR�S�S�S�Sr&)r.r
r/r0)r/r0)r/re).)rlrmr6rnr/ro)rlr	r6rnr/rrH)r�r�r6rnr/ro)r,r�r/r�)r/r�)r#rer/r0)r�r�r/r�)r�r�r/r�)r�r�)r�r�r/r)rlr�r/r�)T)r�r�r�r0r/r�)r�r r/r�)rLrr/r�)r�r�r/r�)m�__doc__�
__future__r�builtins�collectionsrr�collections.abcrrrr	r
�
contextlib�	functoolsrr��typingrr
rrrr��numpyr4�pandas._libsr�pandas.compat.numpyr�pandas.core.dtypes.castr�pandas.core.dtypes.commonrr�pandas.core.dtypes.genericrrrr�pandas.core.dtypes.inferencer�pandas._typingrrrrr�pandasr r"r-r@rErPrVr\r`rdrkrrr�r�r�r�r�r�r�r�r�r�r�r�r�r��contextmanagerr�r�rjr��maximum�reducer��minimumr��_builtin_table_aliasr[rU�nansumr��nanmeanr��nanprodr��nanstdr��nanvarr��	nanmedian�nanmax�nanminr��
nancumprodr��	nancumsumr�r�r�r�rIr&r%�<module>rs�����
#�"�"�"�"�"���������������������������������������������������������������������2�2�2�2�2�2�K�K�K�K�K�K���������������������=�<�<�<�<�<��	������������������������0���4�4�4�4�n���,4�4�4�,�,�,�,�,�,�,�,�0�0�0�0�0�0�0�0�,�,�,�,�
�DG�����
���
�����
��� � � � � �H<@������:�������	�	�	�	�	�	�	�	�I�I�I�I�	�	�	�	����"���"���@
����
���
����
��� 
� 
� 
� 
� 
�F"*�"*�"*�"*�JI�I�I�������-1�*�*�*�*���*�@

�

�

�

�"
�L�"�&��L�"�*�#��L�"�*�#���
�L�(��L�%��L�%�����L�%���L�%��
�L�%���F�E�	�
�F�E���F�E�
��I�u���G�V���J����G�V���J����F�E���I�u���F�E���I�u�� �I�x�!�"�L�(�#�$�F�E��I�u��F�E��I�u��J�	��M�9��I�x��L�(�3��
�:"�"�"�"�(�(�(�T�T�T�T�T�Tr&