o
    $j0                     @  s   d dl mZ d dlZd dlmZmZmZ d dlZd dl	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ erZd dlZd dlmZmZmZmZm Z  eG dd deZ!	ddddZ"G dd deZ#dS )    )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                   @  s   e Zd ZU dZdZded< edddZed d
dZed!ddZ	e
d"ddZd ddZed#ddZed#ddZd$ddZdS )%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]namereturntypec                 C  s   t jS N)npbool_self r   [/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pandas/core/arrays/boolean.pyr   D      zBooleanDtype.typestrc                 C     dS )Nbr   r   r   r   r   kindH      zBooleanDtype.kindnp.dtypec                 C  s
   t dS )Nbool)r   dtyper   r   r   r   numpy_dtypeL   s   
zBooleanDtype.numpy_dtypetype_t[BooleanArray]c                 C  s   t S )zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        )BooleanArray)clsr   r   r   construct_array_typeP   s   	z!BooleanDtype.construct_array_typec                 C  r"   )Nr   r   r   r   r   r   __repr__[   s   zBooleanDtype.__repr__r'   c                 C  r"   NTr   r   r   r   r   _is_boolean^   r%   zBooleanDtype._is_booleanc                 C  r"   r/   r   r   r   r   r   _is_numericb   r%   zBooleanDtype._is_numericarray$pyarrow.Array | pyarrow.ChunkedArrayr+   c                 C  sj  ddl }|j| kr|j|jstd|j dt||jr)|g}t|}n|j	}|
 }|j|jrJtj|td}tj|td}t||S g }|D ]N}| }	|jj|jt|d|	d g|jdjdd	}|jdkr|jj|jt|d|	d g|jdjdd	}| }n	tjt|td}t||}
||
 qN|sttjg tjdtjg tjdS t|S )
zI
        Construct BooleanArray from pyarrow Array/ChunkedArray.
        r   Nz$Expected array of boolean type, got z insteadr(      )offsetF)Zzero_copy_only)pyarrowr   r   typesZis_null	TypeError
isinstanceArraylenchunkslengthr   Zonesr'   emptyr+   buffersZfrom_buffersr6   Zto_numpyZ
null_countzerosappendr2   Z_concat_same_type)r   r2   r7   r=   r>   maskdataresultsZarrZbuflistZbool_arrr   r   r   __from_arrow__f   sF   




zBooleanDtype.__from_arrow__N)r   r   )r   r!   )r   r&   )r   r*   r   r'   )r2   r3   r   r+   )__name__
__module____qualname____doc__r   __annotations__propertyr   r$   r)   classmethodr-   r.   r0   r1   rF   r   r   r   r   r   (   s"   
 

r   Fcopyr'   r   tuple[np.ndarray, np.ndarray]c                 C  s,  t | tr"|durtd| j| j} }|r|  } | }| |fS d}t | tjr7| jtj	kr7|r6|  } nt | tjrs| jj
dv rst| }tjt| td}| |  t|| < t||  | j| |  ksptd|} nPtj| td}tj|dd}d}|d	| vrtdtd
t|}tjt| td} ||  t| | < ||v rt| |  t||  tkstd|du r|du rtj| jtd}n3|du r|}n,t |tjr|jtj	kr|dur||B }n|r| }ntj|td}|dur||B }| j|jkrtd| |fS )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 inputZiufcbr4   zNeed to pass bool-like valuesTskipna)Zfloatingintegerzmixed-integer-float)r   r?   npt.NDArray[np.bool_]z&values.shape and mask.shape must match)r:   r+   
ValueError_data_maskrO   r   ndarrayr(   r   r$   r
   rA   r<   r'   astypeallr9   asarrayobjectr   Zinfer_dtyper   floatshaper2   )valuesrC   rO   Zmask_valuesZvalues_boolZvalues_objectZinferred_dtypeZinteger_liker   r   r   coerce_to_array   sl   


r`   c                      s   e Zd ZdZdZdZdZh dZh dZe	d/ fddZ
	d0d1 fddZed2ddZe	dddddd3dd ZejejeejfZe	dd!d4d$d%Zd&d' Zdd(d5d-d.Z  ZS )6r+   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>   TrueTRUE1z1.0true>   z0.0falseFalseFALSE0r_   
np.ndarrayrC   rT   r   r   c                   s   t  ||}t |_|S r   )super_simple_newr   _dtype)r,   r_   rC   result	__class__r   r   rk   -  s   zBooleanArray._simple_newrO   r'   Nonec                   s>   t |tjr|jtjkstdt | _t j	|||d d S )NzIvalues should be boolean numpy array. Use the 'pd.array' function insteadrO   )
r:   r   rX   r(   r   r9   r   rl   rj   __init__)r   r_   rC   rO   rn   r   r   rr   3  s   zBooleanArray.__init__r   c                 C  s   | j S r   )rl   r   r   r   r   r(   >  r    zBooleanArray.dtypeN)r(   rO   true_valuesfalse_valuesstrings	list[str]r(   Dtype | Noners   list[str] | Nonert   c          	        sp   | j |pg | j|pg  d fdd}tj|td}t|}tt|||  || < | j	|||dS )Nr   r'   c                   s&   | v rdS |  v rdS t |  d)NTFz cannot be cast to bool)rU   )sZfalse_values_unionZtrue_values_unionr   r   
map_stringO  s
   z:BooleanArray._from_sequence_of_strings.<locals>.map_stringr4   )r(   rO   rG   )
_TRUE_VALUESunion_FALSE_VALUESr   r2   r\   r
   listmapZ_from_sequence)	r,   ru   r(   rO   rs   rt   r{   ZscalarsrC   r   rz   r   _from_sequence_of_stringsB  s   
z&BooleanArray._from_sequence_of_stringsrq   r   rP   c                C  s   |r|dksJ t ||dS )Nr   rq   )r`   )r,   valuer(   rO   r   r   r   _coerce_to_array^  s   zBooleanArray._coerce_to_arrayc                 C  s:  |j dv sJ t|}d }t|tr|j|j}}n't|r8tj	|dd}|j
dkr/tdt|dd\}}n
t|tjrB| }|rY|tjurYt|sYtdt|j  d	|sgt| t|krgtd
|j dv ryt| j|| j|\}}n|j dv rt| j|| j|\}}nt| j|| j|\}}| ||S )N>   Zrxorand_ror_rand_or_xorr'   r4   r5   z(can only perform ops with 1-d structuresFrq   z+'other' should be pandas.NA or a bool. Got z	 instead.zLengths must match>   r   r   >   r   r   )rH   r   Z	is_scalarr:   r+   rV   rW   r   r   r[   ndimNotImplementedErrorr`   r   item
libmissingZNAZis_boolr9   r   r<   rU   r   Z	kleene_orZ
kleene_andZ
kleene_xorZ_maybe_mask_result)r   otheropZother_is_scalarrC   rm   r   r   r   _logical_methodf  s4   




zBooleanArray._logical_methodrQ   r   r!   rR   r   c                K  sr   | j }| j}|dv r"tt|}|||fd|i|\}}| ||S ddlm} ||t|j	|fd|i|S )N)ZcumminZcummaxrR   r   )IntegerArray)
rV   rW   getattrr   rk   Zpandas.core.arraysr   rY   int_accumulate)r   r   rR   kwargsrD   rC   r   r   r   r   r   r     s   
zBooleanArray._accumulate)r_   ri   rC   rT   r   r   )F)r_   ri   rC   ri   rO   r'   r   rp   )r   r   )ru   rv   r(   rw   rO   r'   rs   rx   rt   rx   r   r+   )r(   r   rO   r'   r   rP   )r   r!   rR   r'   r   r   )rH   rI   rJ   rK   Z_internal_fill_valueZ_truthy_valueZ_falsey_valuer|   r~   rN   rk   rr   rM   r(   r   r   rX   numbersNumberr'   r   Z_HANDLED_TYPESr   r   r   __classcell__r   r   rn   r   r+      s4    4$r+   )NF)rO   r'   r   rP   )$
__future__r   r   typingr   r   r   numpyr   Zpandas._libsr   r   r   Zpandas.core.dtypes.commonr   Zpandas.core.dtypes.dtypesr	   Zpandas.core.dtypes.missingr
   Zpandas.corer   Zpandas.core.array_algosr   Zpandas.core.arrays.maskedr   r   r7   Zpandas._typingr   r   r   r   r   r   r`   r+   r   r   r   r   <module>   s&    	pW