
    Pif4                    f   d dl mZ d dlZd dlmZ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 d dlmZmZ erd dlZd dlmZm Z m!Z! d dlm"Z" e ed           G d de                                  Z#	 dddZ$ ed           G d de                      Z%dS )    )annotationsN)TYPE_CHECKINGClassVarSelfcast)libmissing)
set_module)is_list_like)register_extension_dtype)isna)ops)masked_accumulations)BaseMaskedArrayBaseMaskedDtype)DtypeObjnpttype_t)ExtensionDtypepandasc                      e Zd ZU dZdZded<   dZedd            Zedd
            Z	edd            Z
ddZddZedd            Zedd            ZddZdS )BooleanDtypeaP  
    Extension dtype for boolean data.

    This is a pandas Extension dtype for boolean data with support for
    missing values. BooleanDtype is the dtype companion to :class:`.BooleanArray`,
    which implements Kleene logic (sometimes called three-value logic) for
    logical operations. See :ref:`boolean.kleene` for more.

    .. warning::

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

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

    Methods
    -------
    None

    See Also
    --------
    arrays.BooleanArray : Array of boolean (True/False) data with missing values.
    Int64Dtype : Extension dtype for int64 integer data.
    StringDtype : Extension dtype for string data.

    Examples
    --------
    >>> pd.BooleanDtype()
    BooleanDtype

    >>> pd.array([True, False, None], dtype=pd.BooleanDtype())
    <BooleanArray>
    [True, False, <NA>]
    Length: 3, dtype: boolean

    >>> pd.array([True, False, None], dtype="boolean")
    <BooleanArray>
    [True, False, <NA>]
    Length: 3, dtype: boolean
    booleanzClassVar[str]nameFreturntypec                    t           j        S N)npbool_selfs    n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/arrays/boolean.pyr   zBooleanDtype.type_   s	    x    strc                    dS )Nb r!   s    r#   kindzBooleanDtype.kindc   s    sr$   np.dtypec                *    t          j        d          S )Nbool)r   dtyper!   s    r#   numpy_dtypezBooleanDtype.numpy_dtypeg   s    xr$   type_t[BooleanArray]c                    t           S )zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        )BooleanArrayr!   s    r#   construct_array_typez!BooleanDtype.construct_array_typek   s
     r$   c                    dS )Nr   r(   r!   s    r#   __repr__zBooleanDtype.__repr__u   s    ~r$   r,   c                    dS NTr(   r!   s    r#   _is_booleanzBooleanDtype._is_booleanx       tr$   c                    dS r6   r(   r!   s    r#   _is_numericzBooleanDtype._is_numeric|   r8   r$   array$pyarrow.Array | pyarrow.ChunkedArrayr1   c                   ddl }|j         |j                    k    r7|j                            |j                  st          d|j         d          t          ||j                  r|g}t          |          }n|j	        }|
                                }|j                            |j                  rFt          j        |t                    }t          j        |t                    }t          ||          S g }|D ]}|                                }	|j                            |j        t          |          d|	d         g|j                                      d	          }|j        dk    rU|j                            |j        t          |          d|	d         g|j                                      d	          }| }n(t          j        t          |          t                    }t          ||          }
|                    |
           |sLt          t          j        g t          j                  t          j        g t          j                            S t                              |          S )
zI
        Construct BooleanArray from pyarrow Array/ChunkedArray.
        r   Nz$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,   emptyr1   buffersfrom_buffersr@   to_numpy
null_countzerosappendr;   _concat_same_type)r"   r;   rB   rI   rJ   maskdataresultsarrbuflistbool_arrs              r#   __from_arrow__zBooleanDtype.__from_arrow__   sK    	:((1F1Fuz1R1R(W5:WWWXXXeW]++ 	$WFZZFF \F\\^^F=  ,, 	,76...D8F$///Dd+++ 	% 	%CkkmmG'44#c((T71:$6sz 5  heh,,  ~""+88Hc#hhwqz(:3: 9  (%(00  uxC555#D$//HNN8$$$$ 	;28,,,bhr.J.J.J    11':::r$   N)r   r   )r   r%   )r   r*   )r   r/   )r   r,   )r;   r<   r   r1   )__name__
__module____qualname____doc__r   __annotations___internal_fill_valuepropertyr   r)   r.   r2   r4   r7   r:   rZ   r(   r$   r#   r   r   *   s        ) )V $D#### !    X    X       X           X    X/; /; /; /; /; /;r$   r   Fcopyr,   r   tuple[np.ndarray, np.ndarray]c                   t          | t                    rM|t          d          | j        | j        }} |r(|                                 } |                                }| |fS d}t          | t          j                  r-| j        t          j	        k    r|r|                                 } nt          | t          j                  r| j        j
        dv rt          |           }t          j        t          |           t                    }| |                              t                    || <   t          j        ||                              | j                  | |          k              st#          d          |} nt          j        | t&                    }t)          j        |d          }d}|d	d
g|R vrt#          d          t-          dt          |                    }t          j        t          |           t                    } ||                              t                    | | <   ||v ret          j        | |                              t.                    ||                              t.                    k              st#          d          |#|!t          j        | j        t                    }nu||}npt          |t          j                  r4|j        t          j	        k    r|||z  }n9|r|                                }n"t          j        |t                    }|||z  }| 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 inputiufcbr>   zNeed to pass bool-like valuesTskipna)floatingintegerzmixed-integer-floatr   rL   npt.NDArray[np.bool_]z&values.shape and mask.shape must match)rF   r1   
ValueError_data_maskrb   r   ndarrayr-   r    r)   r   rQ   rH   r,   astypeallrE   asarrayobjectr   infer_dtyper   floatshaper;   )valuesrT   rb   mask_valuesvalues_boolvalues_objectinferred_dtypeinteger_likes           r#   coerce_to_arrayr|      s0   " &,'' FGGG|V\ 	[[]]F99;;Dt|K&"*%% $=&,"(*B*B 	#[[]]F	FBJ	'	' !=FL,=,H,H6llhs6{{$777$*K<$8$?$?$E$E[L!v%,,V\::fk\>RR
 
 	= ;<<<
6888tDDDE)W!D|!D!DDD;<<< 2D4G4GHH#f++T222,k\:AA$GG| l**F|$++E22 +.55e<<=  + ;<<<|+xD111		D"*	%	% &$**@*@"+%DD 	99;;DxD)))"+%D|tz!!ABBB4<r$   zpandas.arraysc                       e Zd ZdZh dZh dZed) fd
            Z	 d*d+ fdZe	d,d            Z
edddddd-d            Zej        ej        eej        fZeddd.d             Zd! Zd"d#d/d(Z xZS )0r1   as  
    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 a 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

    See Also
    --------
    array : Create an array from data with the appropriate dtype.
    BooleanDtype : Extension dtype for boolean data.
    Series : One-dimensional ndarray with axis labels (including time series).
    DataFrame : Two-dimensional, size-mutable, potentially heterogeneous tabular data.

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

    >>> pd.array([True, False, None], dtype="boolean")
    <BooleanArray>
    [True, False, <NA>]
    Length: 3, dtype: boolean
    >   1.01TRUETruetrue>   0.00FALSEFalsefalserv   
np.ndarrayrT   rj   r   r   c                r    t                                          ||          }t                      |_        |S r   )super_simple_newr   _dtype)clsrv   rT   result	__class__s       r#   r   zBooleanArray._simple_newF  s,    $$VT22$r$   Frb   r,   Nonec                    t          |t          j                  r|j        t          j        k    st          d          t                      | _        t                      	                    |||           d S )NzIvalues should be boolean numpy array. Use the 'pd.array' function insteadrb   )
rF   r   rn   r-   r    rE   r   r   r   __init__)r"   rv   rT   rb   r   s       r#   r   zBooleanArray.__init__L  sp     62:.. 	6<283K3K2   #nnD11111r$   r   c                    | j         S r   )r   r!   s    r#   r-   zBooleanArray.dtypeW  s
    {r$   N)rb   true_valuesfalse_valuesnone_valuesstrings	list[str]r-   r   r   list[str] | Noner   r   c               d  
 | j                             |pg           | j                            |pg           
g d
fd}t          j        |t
                    }t          |          }	t          t          |||	                              ||	 <   | 	                    |||          S )Nr   bool | Nonec                L    | v rdS | v rdS | v rd S t          |  d          )NTFz cannot be cast to bool)rk   )sfalse_values_unionr   true_values_unions    r#   
map_stringz:BooleanArray._from_sequence_of_strings.<locals>.map_stringl  sL    %%%t(((uk!!t A!>!>!>???r$   r>   )r-   rb   )r   r   )
_TRUE_VALUESunion_FALSE_VALUESr   r;   rr   r   listmap_from_sequence)r   r   r-   rb   r   r   r   r   scalarsrT   r   r   s         `   @@r#   _from_sequence_of_stringsz&BooleanArray._from_sequence_of_strings[  s      ,22;3D"EE .44\5GRHHK	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ (7&111G}}c*gten==>>!!'T!BBBr$   r   r   rc   c               8    |r|dk    sJ t          ||          S )Nr   r   )r|   )r   valuer-   rb   s       r#   _coerce_to_arrayzBooleanArray._coerce_to_array}  s0      	&I%%%%u40000r$   c                   |j         dv sJ t          j        |          }d }t          |t                    r|j        |j        }}nzt          |          r=t          j	        |d          }|j
        dk    rt          S t          |d          \  }}n.t          |t          j                  r|                                }|rG|t          j        ur9t          j        |          s%t%          dt'          |          j          d          |s/t)          |           t)          |          k    rt+          d	          |j         d
v r%t-          j        | j        || j        |          \  }}nR|j         dv r%t-          j        | j        || j        |          \  }}n$t-          j        | j        || j        |          \  }}|                     ||          S )N>   or_xorand_ror_rxorrand_r,   r>   r?   Fr   z+'other' should be pandas.NA or a bool. Got z	 instead.zLengths must match>   r   r   >   r   r   )r[   r   	is_scalarrF   r1   rl   rm   r   r   rq   ndimNotImplementedr|   r    item
libmissingNAis_boolrE   r   rH   rk   r   	kleene_or
kleene_and
kleene_xor_maybe_mask_result)r"   otheropother_is_scalarrT   r   s         r#   _logical_methodzBooleanArray._logical_method  s   {MMMMM-..e\** 	!+u{4EE%   	!JuF333EzA~~%%)%e<<<KE44rx(( 	!JJLLE 	uJM99#+eBTBT97E{{+7 7 7  
  	33t99E

#:#:1222;/))=UDJMMLFDD[--->$*eTZNNLFDD >$*eTZNNLFD &&vt444r$   Trf   r   r%   rg   r   c               
   | j         }| j        }|dv r:t          t          |          } |||fd|i|\  }}|                     ||          S ddlm}   ||                    t                    |          j	        |fd|i|S )N)cummincummaxrg   r   )IntegerArray)
rl   rm   getattrr   r   pandas.core.arraysr   ro   int_accumulate)r"   r   rg   kwargsrU   rT   r   r   s           r#   r   zBooleanArray._accumulate  s     zz'''-t44BD$@@v@@@JD$##D$///777777C<<C 0 0$77C #'-  r$   )rv   r   rT   rj   r   r   )F)rv   r   rT   r   rb   r,   r   r   )r   r   )r   r   r-   r   rb   r,   r   r   r   r   r   r   r   r1   )r-   r   rb   r,   r   rc   )r   r%   rg   r,   r   r   )r[   r\   r]   r^   r   r   classmethodr   r   ra   r-   r   r   rn   numbersNumberr,   r    _HANDLED_TYPESr   r   r   __classcell__)r   s   @r#   r1   r1     sf       8 8t 877L;;;M     [ BG	2 	2 	2 	2 	2 	2 	2    X  (,)-(,C C C C C [C> j'.$AN5:1 1 1 1 1 [1!5 !5 !5H ,0         r$   r1   )NF)rb   r,   r   rc   )&
__future__r   r   typingr   r   r   r   numpyr   pandas._libsr   r	   r   pandas.util._decoratorsr
   pandas.core.dtypes.commonr   pandas.core.dtypes.dtypesr   pandas.core.dtypes.missingr   pandas.corer   pandas.core.array_algosr   pandas.core.arrays.maskedr   r   rB   pandas._typingr   r   r   r   r   r|   r1   r(   r$   r#   <module>r      sO   " " " " " "                        / . . . . . 2 2 2 2 2 2 > > > > > > + + + + + +       8 8 8 8 8 8       
  	9NNN          988888 HC; C; C; C; C;? C; C;  C;N %*R R R R Rj On n n n n? n n n n nr$   