Sindbad~EG File Manager

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

�

Mٜg�0���ddlmZddlZddlmZmZmZddlZddl	m
Z
mZddl
mZddlmZddlmZddlmZdd	lmZdd
lmZmZerddlZddlmZmZmZmZm Z eGd�d
e��Z!	d			dd�Z"Gd�de�Z#y)�)�annotationsN)�
TYPE_CHECKING�ClassVar�cast)�lib�missing)�is_list_like)�register_extension_dtype)�isna)�ops)�masked_accumulations)�BaseMaskedArray�BaseMaskedDtype)�Dtype�DtypeObj�Self�npt�type_tc��eZdZUdZdZded<edd��Zedd��Zedd��Z	e
dd��Zdd	�Zedd
��Z
edd��Z				dd�Zy
)�BooleanDtypeaI
    Extension dtype for boolean data.

    .. warning::

       BooleanDtype is considered experimental. The implementation and
       parts of the API may change without warning.

    Attributes
    ----------
    None

    Methods
    -------
    None

    Examples
    --------
    >>> pd.BooleanDtype()
    BooleanDtype
    �booleanz
ClassVar[str]�namec�"�tjS�N)�np�bool_��selfs �E/usr/local/lib/python3.12/site-packages/pandas/core/arrays/boolean.py�typezBooleanDtype.typeDs���x�x��c��y)N�b�rs r�kindzBooleanDtype.kindHs��r!c�,�tjd�S)N�bool)r�dtypers r�numpy_dtypezBooleanDtype.numpy_dtypeLs���x�x���r!c��tS)zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        )�BooleanArray)�clss r�construct_array_typez!BooleanDtype.construct_array_typePs
���r!c��y)Nrr$rs r�__repr__zBooleanDtype.__repr__[s��r!c��y�NTr$rs r�_is_booleanzBooleanDtype._is_boolean^���r!c��yr1r$rs r�_is_numericzBooleanDtype._is_numericbr3r!c��ddl}|j|j�k7r>|jj	|j�std|j�d���t
||j�r|g}t|�}n|j}|j�}|jj	|j�rBtj|t��}tj|t��}t||�Sg}|D�]	}|j!�}	|jj#|jt|�d|	dg|j$��j'd�	�}|j(dk7rU|jj#|jt|�d|	dg|j$��j'd�	�}|}n$tj*t|�t��}t||�}
|j-|
���|sRttj.gtj��tj.gtj���Stj1|�S)
zI
        Construct BooleanArray from pyarrow Array/ChunkedArray.
        rNz$Expected array of boolean type, got z instead�r(�)�offsetF)�zero_copy_only)�pyarrowr r�types�is_null�	TypeError�
isinstance�Array�len�chunks�lengthr�onesr'�emptyr+�buffers�from_buffersr9�to_numpy�
null_count�zeros�append�array�_concat_same_type)rrLr;rBrC�mask�data�results�arr�buflist�bool_arrs           r�__from_arrow__zBooleanDtype.__from_arrow__fs���	��:�:������(����1F�1F�u�z�z�1R��B�5�:�:�,�h�W�X�X��e�W�]�]�+��W�F���Z�F��\�\�F��\�\�^�F��=�=� � ����,��7�7�6��.�D��8�8�F�$�/�D���d�+�+����C��k�k�m�G��'�'�4�4����#�c�(�T�7�1�:�$6�s�z�z�5���h�e�h�,�
��~�~��"��+�+�8�8��H�H�c�#�h��w�q�z�(:�3�:�:�9���(�%�(�0���u���x�x��C���5��#�D�$�/�H��N�N�8�$�� ������2�8�8�,�b�h�h�r����.J��
� �1�1�'�:�:r!N)�returnr )rU�str)rUznp.dtype)rUztype_t[BooleanArray]�rUr')rLz$pyarrow.Array | pyarrow.ChunkedArrayrUr+)�__name__�
__module__�__qualname__�__doc__r�__annotations__�propertyr r%r)�classmethodr-r/r2r5rTr$r!rrr(s����,$�D�-�#���������� �� ��������������/;�9�/;�	�/;r!rc�V�t|t�rK|�td��|j|j}}|r |j�}|j�}||fSd}t|tj�r2|jtjk(r|�r�|j�}�n�t|tj�r�|jjdvr�t|�}t
jt|�t��}||jt�||<t
j ||j|j�||k(�st#d��|}n�t
j$|t&��}t)j*|d��}d}|d	|zvrt#d��t-d
t|��}t
jt|�t��}||jt�||<||vrQt
j ||jt.�||jt.�k(�st#d��|�(|�&t
j|j0t��}ny|�|}ntt|tj�r8|jtjk(r|�||z}n5|r3|j�}n"t
j2|t��}|�||z}|j0|j0k7rtd��||fS)a
    Coerce the input values array to numpy arrays with a mask.

    Parameters
    ----------
    values : 1D list-like
    mask : bool 1D array, optional
    copy : bool, default False
        if True, copy the input

    Returns
    -------
    tuple of (values, mask)
    Nz'cannot pass mask for BooleanArray input�iufcbr7zNeed to pass bool-like valuesT��skipna)�floating�integerzmixed-integer-float)rrE�npt.NDArray[np.bool_]z&values.shape and mask.shape must match)r?r+�
ValueError�_data�_mask�copyr�ndarrayr(rr%rrJrAr'�astype�allr>�asarray�objectr�infer_dtyper�float�shaperL)�valuesrNri�mask_values�values_bool�
values_object�inferred_dtype�integer_likes        r�coerce_to_arrayrx�s���"�&�,�'����F�G�G��|�|�V�\�\�����[�[�]�F��9�9�;�D��t�|���K��&�"�*�*�%�&�,�,�"�(�(�*B���[�[�]�F�	�F�B�J�J�	'�F�L�L�,=�,=��,H��6�l���h�h�s�6�{�$�7��$*�K�<�$8�$?�$?��$E��[�L�!��v�v����%�,�,�V�\�\�:�f�k�\�>R�R�
��;�<�<����
�
�6��8�
�����t�D��E���!5��!D�D��;�<�<��2�D��4G�H�����#�f�+�T�2��,�k�\�:�A�A�$�G���|��
�l�*��F�F���|�$�+�+�E�2� �+��.�5�5�e�<�=�
�
�;�<�<��|��+��x�x����D�1��	
�����d�B�J�J�'�D�J�J�"�(�(�,B��&��k�)����9�9�;�D��8�8�D��-�D��&��k�)��
�|�|�t�z�z�!��A�B�B��4�<�r!c�6��eZdZdZdZdZdZhd�Zhd�Ze	d�fd��Z
	d							d�fd�
Zedd��Z
e	d	dd	d	d
�											dd��Zej ej$eej(fZe	dd�					dd
��Zd�Zdd�					dd�Z�xZS)r+a=
    Array of boolean (True/False) data with missing values.

    This is a pandas Extension array for boolean data, under the hood
    represented by 2 numpy arrays: a boolean array with the data and
    a boolean array with the mask (True indicating missing).

    BooleanArray implements Kleene logic (sometimes called three-value
    logic) for logical operations. See :ref:`boolean.kleene` for more.

    To construct an BooleanArray from generic array-like input, use
    :func:`pandas.array` specifying ``dtype="boolean"`` (see examples
    below).

    .. warning::

       BooleanArray is considered experimental. The implementation and
       parts of the API may change without warning.

    Parameters
    ----------
    values : numpy.ndarray
        A 1-d boolean-dtype array with the data.
    mask : numpy.ndarray
        A 1-d boolean-dtype array indicating missing values (True
        indicates missing).
    copy : bool, default False
        Whether to copy the `values` and `mask` arrays.

    Attributes
    ----------
    None

    Methods
    -------
    None

    Returns
    -------
    BooleanArray

    Examples
    --------
    Create an BooleanArray with :func:`pandas.array`:

    >>> pd.array([True, False, None], dtype="boolean")
    <BooleanArray>
    [True, False, <NA>]
    Length: 3, dtype: boolean
    FT>�1.0�1�TRUE�True�true>�0.0�0�FALSE�False�falsec�F��t�|�||�}t�|_|Sr)�super�_simple_newr�_dtype)r,rrrN�result�	__class__s    �rr�zBooleanArray._simple_new-s"�����$�V�T�2��$���
��
r!c����t|tj�r|jtjk(std��t
�|_t�|�%|||��y)NzIvalues should be boolean numpy array. Use the 'pd.array' function instead�ri)
r?rrjr(rr>rr�r��__init__)rrrrNrir�s    �rr�zBooleanArray.__init__3sS����6�2�:�:�.�6�<�<�2�8�8�3K��2��
�#�n���
�����D��1r!c��|jSr)r�rs rr(zBooleanArray.dtype>s���{�{�r!N)r(ri�true_values�false_valuesc�>�	�
�|jj|xsg��
|jj|xsg��	d�	�
fd�}tj|t
��}t
|�}tt|||��||<|j|||��S)Nc�4��|�vry|�vryt|�d���)NTFz cannot be cast to bool)rf)�s�false_values_union�true_values_unions ��r�
map_stringz:BooleanArray._from_sequence_of_strings.<locals>.map_stringOs.����%�%���(�(�� �A�3�&=�!>�?�?r!r7)r(rirW)
�_TRUE_VALUES�union�
_FALSE_VALUESrrLrnr�list�map�_from_sequence)r,�stringsr(rir�r�r��scalarsrNr�r�s         @@r�_from_sequence_of_stringsz&BooleanArray._from_sequence_of_stringsBs���� �,�,�2�2�;�3D�"�E�� �.�.�4�4�\�5G�R�H��	@��(�(�7�&�1���G�}���c�*�g�t�e�n�=�>������!�!�'��T�!�B�Br!r�c�.�|r|dk(sJ�t||��S)Nrr�)rx)r,�valuer(ris    r�_coerce_to_arrayzBooleanArray._coerce_to_array^s"����I�%�%�%��u�4�0�0r!c���|jdvsJ�tj|�}d}t|t�r|j
|j}}nwt|�rBtj|d��}|jdkDrtd��t|d��\}}n*t|tj�r|j�}|rI|tj ur7tj"|�s"t%dt'|�j�d	���|s"t)|�t)|�k7rt+d
��|jdvr0t-j.|j
||j|�\}}nm|jdvr0t-j0|j
||j|�\}}n/t-j2|j
||j|�\}}|j5||�S)
N>�or_�xor�and_�ror_�rxor�rand_r'r7r8z(can only perform ops with 1-d structuresFr�z+'other' should be pandas.NA or a bool. Got z	 instead.zLengths must match>r�r�>r�r�)rXr�	is_scalarr?r+rgrhr	rrm�ndim�NotImplementedErrorrxr�item�
libmissing�NA�is_boolr>r rArfr�	kleene_or�
kleene_and�
kleene_xor�_maybe_mask_result)r�other�op�other_is_scalarrNr�s      r�_logical_methodzBooleanArray._logical_methodfs����{�{�M�M�M�M��-�-��.�����e�\�*��+�+�u�{�{�4�E�
�%�
 ��J�J�u�F�3�E��z�z�A�~�)�*T�U�U�)�%�e�<�K�E�4�
��r�x�x�
(��J�J�L�E��u�J�M�M�9�#�+�+�e�BT����E�{�+�+�,�I�7��
�
�3�t�9��E�
�#:��1�2�2�
�;�;�/�)��=�=����U�D�J�J��M�L�F�D�
�[�[�-�
-��>�>�$�*�*�e�T�Z�Z��N�L�F�D��>�>�$�*�*�e�T�Z�Z��N�L�F�D��&�&�v�t�4�4r!rac��|j}|j}|dvr1tt|�}|||fd|i|��\}}|j	||�Sddlm}||jt�|�j|fd|i|��S)N)�cummin�cummaxrbr)�IntegerArray)
rgrh�getattrr
r��pandas.core.arraysr�rk�int�_accumulate)rrrb�kwargsrOrNr�r�s        rr�zBooleanArray._accumulate�s����z�z���z�z���'�'��-�t�4�B��D�$�@�v�@��@�J�D�$��#�#�D�$�/�/�7�C�<����C� 0�$�7�C�C���#��'-��
r!)rr�
np.ndarrayrNrerUr)F)rrr�rNr�rir'rU�None)rUr)r�z	list[str]r(zDtype | Nonerir'r��list[str] | Noner�r�rUr+)r(rrir'rU�tuple[np.ndarray, np.ndarray])rrVrbr'rUr)rXrYrZr[�_internal_fill_value�
_truthy_value�
_falsey_valuer�r�r^r�r�r]r(r�rrj�numbers�Numberr'r�_HANDLED_TYPESr�r�r��
__classcell__)r�s@rr+r+�sN���1�h!���M��M�7�L�;�M�����BG�	2� �	2�(2�	2�:>�	2�	
�	2������
#��(,�)-�C��C��	C�
�C�&�
C�'�C�
�C��C�2�j�j�'�.�.�$����A�N��5:�1�&�1�.2�1�	&�1��1�!5�H,0����$(��	�r!r+)NF)rir'rUr�)$�
__future__rr��typingrrr�numpyr�pandas._libsrrr��pandas.core.dtypes.commonr	�pandas.core.dtypes.dtypesr
�pandas.core.dtypes.missingr�pandas.corer�pandas.core.array_algosr
�pandas.core.arrays.maskedrrr;�pandas._typingrrrrrrrxr+r$r!r�<module>r�s���"������
3�>�+��8��
�����l;�?�l;��l;�`%*�T�!�T�"�T�nh�?�hr!

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