Sindbad~EG File Manager

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

�

Mٜg�>���dZddlmZddlmZmZddlZddlm	Z	ddl
mZmZm
Z
mZmZddlmZddlmZmZerdd	lmZdd
lmZddlmZdd�Zdd
�Zdd�Zdd�Zdd�Zdd�Z ddd�Z!dd d�Z"d!d�Z#d�Z$d"d�Z%d#d�Z&d$d�Z'y)%z$
Low-dependency indexing utilities.
�)�annotations)�
TYPE_CHECKING�AnyN)�lib)�
is_array_like�
is_bool_dtype�
is_integer�is_integer_dtype�is_list_like)�ExtensionDtype)�ABCIndex�	ABCSeries)�AnyArrayLike)�	DataFrame)�Indexc���tj|j�xr@tj|j�xrtj|j�S)a(
    Check if a slice object can be interpreted as a positional indexer.

    Parameters
    ----------
    slc : slice

    Returns
    -------
    bool

    Notes
    -----
    A valid positional slice may also be interpreted as a label-based slice
    depending on the index being sliced.
    )r�is_int_or_none�start�stop�step)�slcs �E/usr/local/lib/python3.12/site-packages/pandas/core/indexers/utils.py�is_valid_positional_slicer&sI��$	���3�9�9�%�	)����s�x�x�(�	)����s�x�x�(��c�d�t|�xr$t|t�xrt|�tuS)z�
    Check if we have a list-like indexer that is *not* a NamedTuple.

    Parameters
    ----------
    key : object

    Returns
    -------
    bool
    )r�
isinstance�tuple�type)�keys r�is_list_like_indexerr >s-�����X�j��e�&<�&W��c��RW�AW�!X�Xrc��|dk(rt|�ryt|t�r t|�|k(rt	d�|D��Sy)z�
    Return True if we are all scalar indexers.

    Parameters
    ----------
    indexer : object
    ndim : int
        Number of dimensions in the object being indexed.

    Returns
    -------
    bool
    �Tc3�2K�|]}t|����y�w�N)r	)�.0�xs  r�	<genexpr>z$is_scalar_indexer.<locals>.<genexpr>`s����2�'�Q�:�a�=�'�s�F)r	rr�len�all)�indexer�ndims  r�is_scalar_indexerr,Ns>���q�y�Z��(���'�5�!�c�'�l�d�&:��2�'�2�2�2�rc�z�t|�rt|�syt|t�s|f}t	d�|D��S)z�
    Check if we have an empty indexer.

    Parameters
    ----------
    indexer : object

    Returns
    -------
    bool
    Tc3�pK�|].}t|tj�xrt|�dk(���0y�w)rN)r�np�ndarrayr()r%�idxs  rr'z#is_empty_indexer.<locals>.<genexpr>ts,����P���z�#�r�z�z�*�<�s�3�x�1�}�<��s�46)rr(rr�any)r*s r�is_empty_indexerr3ds7���G��S��\���g�u�%��*���P��P�P�Prc��d}t|tjtf�r�t	|�r�t|�t|�k7r�|jdk(r�t|t�rtj|�}t|tj�r9|jtjk(r|j�t|�k(std��t|�sd}|St|t�rJt	|�r?t|�t||�k7r|jdk(rtd��t|�sd}|S)a�
    Validate that value and indexer are the same length.

    An special-case is allowed for when the indexer is a boolean array
    and the number of true values equals the length of ``value``. In
    this case, no exception is raised.

    Parameters
    ----------
    indexer : sequence
        Key for the setitem.
    value : array-like
        Value for the setitem.
    values : array-like
        Values being set into.

    Returns
    -------
    bool
        Whether this is an empty listlike setting which is a no-op.

    Raises
    ------
    ValueError
        When the indexer is an ndarray or list and the lengths don't match.
    Fr"zKcannot set using a list-like indexer with a different length than the valueTzGcannot set using a slice indexer with a different length than the value)rr/r0�listrr(r+�array�dtype�bool_�sum�
ValueError�slice�length_of_indexer)r*�value�values�no_ops    r�check_setitem_lengthsr@{s
��6
�E��'�B�J�J��-�.�����7�|�s�5�z�)�f�k�k�Q�.>��g�t�,� �h�h�w�/�G��w��
�
�3��
�
����1����
��U��3�$�A����w�<����L�
�G�U�	#�����5�z�.�w��?�?�F�K�K�ST�DT� �6����u�:����Lrc��t|�rG|j�}|dkrd|�d�}t|��|j�}||k\rt	d��yy)a+
    Perform bounds-checking for an indexer.

    -1 is allowed for indicating missing values.

    Parameters
    ----------
    indices : ndarray
    n : int
        Length of the array being indexed.

    Raises
    ------
    ValueError

    Examples
    --------
    >>> validate_indices(np.array([1, 2]), 3) # OK

    >>> validate_indices(np.array([1, -2]), 3)
    Traceback (most recent call last):
        ...
    ValueError: negative dimensions are not allowed

    >>> validate_indices(np.array([1, 2, 3]), 3)
    Traceback (most recent call last):
        ...
    IndexError: indices are out-of-bounds

    >>> validate_indices(np.array([-1, -1]), 0) # OK

    >>> validate_indices(np.array([0, 1]), 0)
    Traceback (most recent call last):
        ...
    IndexError: indices are out-of-bounds
    ���z-'indices' contains values less than allowed (z < -1)�indices are out-of-boundsN)r(�minr:�max�
IndexError)�indices�n�min_idx�msg�max_idxs     r�validate_indicesrL�s^��J�7�|��+�+�-���R�<�A�'��&�Q�C��S�/�!��+�+�-���a�<��8�9�9��rc�j�t|t�rHtj|�}t	|�dk(r%tj
dtj��S|dk}|j�r|j�}||xx|z
cc<|r&||k\|dkz}|j�rtd��|S)a&
    Attempt to convert indices into valid, positive indices.

    If we have negative indices, translate to positive here.
    If we have indices that are out-of-bounds, raise an IndexError.

    Parameters
    ----------
    indices : array-like
        Array of indices that we are to convert.
    n : int
        Number of elements in the array that we are indexing.
    verify : bool, default True
        Check that all entries are between 0 and n - 1, inclusive.

    Returns
    -------
    array-like
        An array-like of positive indices that correspond to the ones
        that were passed in initially to this function.

    Raises
    ------
    IndexError
        One of the converted indices either exceeded the number of,
        elements (specified by `n`), or was still negative.
    r�r7rC)
rr5r/r6r(�empty�intpr2�copyrF)rGrH�verify�masks    r�maybe_convert_indicesrT�s���8�'�4� ��(�(�7�#���w�<�1���8�8�A�R�W�W�-�-��Q�;�D��x�x�z��,�,�.����
���
�
��1���1��-���8�8�:��8�9�9��Nrc��|��t|t�rwt|�}|j}|j}|j
}|�d}n
|dkr||z
}|�||kDr|}n
|dkr||z
}|�d}n|dkr
|dz|dz}}|}||z
|zdz
|zSt|tttjtf�rSt|t�rtj|�}|jtk(r|j�St|�St|t�r&|j|jz
|j
zSt!|�syt#d��)zX
    Return the expected length of target[indexer]

    Returns
    -------
    int
    rr"z%cannot find the length of the indexer)rr;r(rrrrr
r/r0r5r6r7�boolr9�ranger �AssertionError)r*�target�
target_lenrrrs      rr<r<"sD����j��%�8���[�
��
�
���|�|���|�|���=��E�
�Q�Y��Z��E��<�4�*�,��D�
�A�X��J��D��<��D�
�A�X���(�E�A�I�4�E��5�D��u��t�#�a�'�D�0�0�	�G�i��2�:�:�t�D�	E��g�t�$��h�h�w�'�G��=�=�D� ��;�;�=� ��7�|��	�G�U�	#����w�}�}�,����=�=�
!�'�
*��
�@�
A�Arc�J�tj|�dkDrtd��y)z�
    Helper function to disallow multi-dimensional indexing on 1D Series/Index.

    GH#27125 indexer like idx[:, None] expands dim, but we cannot do that
    and keep an index, so we used to return ndarray, which was deprecated
    in GH#30588.
    r"zzMulti-dimensional indexing (e.g. `obj[:, None]`) is no longer supported. Convert to a numpy array before indexing instead.N)r/r+r:)�results r�disallow_ndim_indexingr]Ls,��
�w�w�v�����
K�
�	
�rc��t|�dk(r3t|dt�r t|t�rt	d��|dS|S)z�
    If we have a length-1 tuple/list that contains a slice, unpack to just
    the slice.

    Notes
    -----
    The list case is deprecated.
    r"rzYIndexing with a single-item list containing a slice is not allowed. Pass a tuple instead.)r(rr;r5r:)�tups r�
unpack_1tupler`[sJ���3�x�1�}��C��F�E�2��c�4� ��>��
�
�1�v�
��Jrc���|jr-t|j�t|�k7rtd��yt|j	|�d�t|j�k7rtd��y)a�
    Checks if a key used as indexer has the same length as the columns it is
    associated with.

    Parameters
    ----------
    columns : Index The columns of the DataFrame to index.
    key : A list-like of keys to index with.
    value : DataFrame The value to set for the keys.

    Raises
    ------
    ValueError: If the length of key is not equal to the number of columns in value
                or if the number of columns referenced by key is not equal to number
                of columns.
    z"Columns must be same length as keyrN)�	is_uniquer(�columnsr:�get_indexer_non_unique)rcrr=s   r�check_key_lengthressm��"����u�}�}���S��)��A�B�B�*��w�-�-�c�2�1�5�6�#�e�m�m�:L�L��A�B�B�Mrc��t|�dkDr!|dtur|dd}n|dtur|dd}t|�dkDrtd��|d}|S)z/
    Possibly unpack arr[..., n] to arr[n]
    r"rNrBztoo many indices for array.)r(�EllipsisrF)�items r�unpack_tuple_and_ellipsesri�sb���4�y�1�}���7�h�����8�D�
�"�X��
!����9�D�
�4�y�1�}��6�7�7���7�D��Krc��ddlm}t|�rt|t�r|S|St|�s;||�}t
|�dk(r%tjgtj��}|j}t|�rt|t�r|jtd��}ntj|t��}t
|�t
|�k7r#tdt
|��dt
|�����|St!|�r(	tj|tj��}|Std
��#t"$r}t#d�|�d	}~wwxYw)a�
    Check if `indexer` is a valid array indexer for `array`.

    For a boolean mask, `array` and `indexer` are checked to have the same
    length. The dtype is validated, and if it is an integer or boolean
    ExtensionArray, it is checked if there are missing values present, and
    it is converted to the appropriate numpy array. Other dtypes will raise
    an error.

    Non-array indexers (integer, slice, Ellipsis, tuples, ..) are passed
    through as is.

    Parameters
    ----------
    array : array-like
        The array that is being indexed (only used for the length).
    indexer : array-like or list-like
        The array-like that's used to index. List-like input that is not yet
        a numpy array or an ExtensionArray is converted to one. Other input
        types are passed through as is.

    Returns
    -------
    numpy.ndarray
        The validated indexer as a numpy array that can be used to index.

    Raises
    ------
    IndexError
        When the lengths don't match.
    ValueError
        When `indexer` cannot be converted to a numpy ndarray to index
        (e.g. presence of missing values).

    See Also
    --------
    api.types.is_bool_dtype : Check if `key` is of boolean dtype.

    Examples
    --------
    When checking a boolean mask, a boolean ndarray is returned when the
    arguments are all valid.

    >>> mask = pd.array([True, False])
    >>> arr = pd.array([1, 2])
    >>> pd.api.indexers.check_array_indexer(arr, mask)
    array([ True, False])

    An IndexError is raised when the lengths don't match.

    >>> mask = pd.array([True, False, True])
    >>> pd.api.indexers.check_array_indexer(arr, mask)
    Traceback (most recent call last):
    ...
    IndexError: Boolean index has wrong length: 3 instead of 2.

    NA values in a boolean array are treated as False.

    >>> mask = pd.array([True, pd.NA])
    >>> pd.api.indexers.check_array_indexer(arr, mask)
    array([ True, False])

    A numpy boolean mask will get passed through (if the length is correct):

    >>> mask = np.array([True, False])
    >>> pd.api.indexers.check_array_indexer(arr, mask)
    array([ True, False])

    Similarly for integer indexers, an integer ndarray is returned when it is
    a valid indexer, otherwise an error is  (for integer indexers, a matching
    length is not required):

    >>> indexer = pd.array([0, 2], dtype="Int64")
    >>> arr = pd.array([1, 2, 3])
    >>> pd.api.indexers.check_array_indexer(arr, indexer)
    array([0, 2])

    >>> indexer = pd.array([0, pd.NA], dtype="Int64")
    >>> pd.api.indexers.check_array_indexer(arr, indexer)
    Traceback (most recent call last):
    ...
    ValueError: Cannot index with an integer indexer containing NA values

    For non-integer/boolean dtypes, an appropriate error is raised:

    >>> indexer = np.array([0., 2.], dtype="float64")
    >>> pd.api.indexers.check_array_indexer(arr, indexer)
    Traceback (most recent call last):
    ...
    IndexError: arrays used as indices must be of integer or boolean type
    r)r6rNF)r7�na_valuez Boolean index has wrong length: z instead of z9Cannot index with an integer indexer containing NA valuesNz9arrays used as indices must be of integer or boolean type)�pandas.core.constructionr6rrrrr(r/rPr7rr�to_numpyrV�asarrayrFr
r:)r6r*�pd_arrayr7�errs     r�check_array_indexerrq�s8��x;��G���g�u�%��N�����!��7�#���w�<�1���h�h�r����1�G��M�M�E��U���e�^�,��&�&�T�E�&�B�G��j�j���5�G��w�<�3�u�:�%��2��w�<�.��S��Z�L�:��
��N�
�%�	 �	��j�j�����8�G��N��T�U�U���	��K���
��	�s�%E�	E�	E�E)rr;�returnrV)rrrV)r+�intrrrV)rG�
np.ndarrayrHrsrr�None)T)rHrsrRrVrrrtr$)rrrs)rrru)rcrr=rrrru)rhr)r6rr*rrrr)(�__doc__�
__future__r�typingrr�numpyr/�pandas._libsr�pandas.core.dtypes.commonrrr	r
r�pandas.core.dtypes.dtypesr�pandas.core.dtypes.genericr
r�pandas._typingr�pandas.core.framer�pandas.core.indexes.baserrr r,r3r@rLrTr<r]r`rerirq�rr�<module>r�s����#��
����5��
�+�+�.��0
Y� �,Q�.=�@-:�h,�f'B�T
��0C�4�,Fr

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