
    Eg0                       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rd dlZd dlmZmZmZmZm Z  e G d de                      Z!	 dddZ" G 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                      e Zd ZU dZdZded<   edd            Zedd	            Zedd            Z	e
dd            ZddZedd            Zedd            Z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                    t           j        S N)npbool_selfs    O/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/core/arrays/boolean.pyr   zBooleanDtype.typeD   s	    x    strc                    dS )Nb r   s    r!   kindzBooleanDtype.kindH   s    sr"   np.dtypec                *    t          j        d          S )Nbool)r   dtyper   s    r!   numpy_dtypezBooleanDtype.numpy_dtypeL   s    xr"   type_t[BooleanArray]c                    t           S )zq
        Return the array type associated with this dtype.

        Returns
        -------
        type
        )BooleanArray)clss    r!   construct_array_typez!BooleanDtype.construct_array_typeP   s
     r"   c                    dS )Nr   r&   r   s    r!   __repr__zBooleanDtype.__repr__[   s    ~r"   r*   c                    dS NTr&   r   s    r!   _is_booleanzBooleanDtype._is_boolean^       tr"   c                    dS r5   r&   r   s    r!   _is_numericzBooleanDtype._is_numericb   r7   r"   array$pyarrow.Array | pyarrow.ChunkedArrayr/   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*   emptyr/   buffersfrom_buffersr?   to_numpy
null_countzerosappendr:   _concat_same_type)r    r:   rA   rH   rI   maskdataresultsarrbuflistbool_arrs              r!   __from_arrow__zBooleanDtype.__from_arrow__f   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   r/   )__name__
__module____qualname____doc__r   __annotations__propertyr   r'   r,   classmethodr1   r3   r6   r9   rY   r&   r"   r!   r   r   (   s         , $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	|z   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-float)r   rK   npt.NDArray[np.bool_]z&values.shape and mask.shape must match)rE   r/   
ValueError_data_maskrb   r   ndarrayr+   r   r'   r   rP   rG   r*   astypeallrD   asarrayobjectr   infer_dtyper   floatshaper:   )valuesrS   rb   mask_valuesvalues_boolvalues_objectinferred_dtypeinteger_likes           r!   coerce_to_arrayr|      s)   " &,'' 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!5!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	dBJ'' 		*DJ"(,B,B&k) '99;;D8D---D&k)|tz!!ABBB4<r"   c                       e Zd ZdZd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 )/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falserv   
np.ndarrayrS   rj   r   r   c                r    t                                          ||          }t                      |_        |S r   )super_simple_newr   _dtype)r0   rv   rS   result	__class__s       r!   r   zBooleanArray._simple_new-  s,    $$VT22$r"   rb   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   )
rE   r   rn   r+   r   rD   r   r   r   __init__)r    rv   rS   rb   r   s       r!   r   zBooleanArray.__init__3  sp     62:.. 	6<283K3K2   #nnD11111r"   r   c                    | j         S r   )r   r   s    r!   r+   zBooleanArray.dtype>  s
    {r"   N)r+   rb   true_valuesfalse_valuesstrings	list[str]r+   Dtype | Noner   list[str] | Noner   c               X  	
 | j                             |pg           
| j                            |pg           	d	
fd}t          j        |t
                    }t          |          }t          t          |||                              || <   | 	                    |||          S )Nr   r*   c                @    | v rdS | v rdS t          |  d          )NTFz cannot be cast to bool)rk   )sfalse_values_uniontrue_values_unions    r!   
map_stringz:BooleanArray._from_sequence_of_strings.<locals>.map_stringO  s<    %%%t(((u A!>!>!>???r"   r=   )r+   rb   rZ   )
_TRUE_VALUESunion_FALSE_VALUESr   r:   rr   r   listmap_from_sequence)r0   r   r+   rb   r   r   r   scalarsrS   r   r   s            @@r!   _from_sequence_of_stringsz&BooleanArray._from_sequence_of_stringsB  s      ,22;3D"EE .44\5GRHH	@ 	@ 	@ 	@ 	@ 	@ 	@ (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|   )r0   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        }}nt          |          rEt          j	        |d          }|j
        dk    rt          d          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>   z(can only perform ops with 1-d structuresFr   z+'other' should be pandas.NA or a bool. Got z	 instead.zLengths must match>   r   r   >   r   r   )r[   r   	is_scalarrE   r/   rl   rm   r	   r   rq   ndimNotImplementedErrorr|   r   item
libmissingNAis_boolrD   r   rG   rk   r   	kleene_or
kleene_and
kleene_xor_maybe_mask_result)r    otheropother_is_scalarrS   r   s         r!   _logical_methodzBooleanArray._logical_methodf  s   {MMMMM-..e\** 	!+u{4EE%   	!JuF333EzA~~)*TUUU)%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"   rf   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   kwargsrT   rS   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   rS   rj   r   r   )F)rv   r   rS   r   rb   r*   r   r   )r   r   )r   r   r+   r   rb   r*   r   r   r   r   r   r/   )r+   r   rb   r*   r   rc   )r   r#   rg   r*   r   r   )r[   r\   r]   r^   _internal_fill_value_truthy_value_falsey_valuer   r   ra   r   r   r`   r+   r   r   rn   numbersNumberr*   r   _HANDLED_TYPESr   r   r   __classcell__)r   s   @r!   r/   r/      sx       1 1h ! MM777L;;;M     [ BG	2 	2 	2 	2 	2 	2 	2    X 
 #(,)-C C C C C [C2 j'.$AN5:1 1 1 1 1 [1!5 !5 !5H ,0         r"   r/   )NF)rb   r*   r   rc   )$
__future__r   r   typingr   r   r   numpyr   pandas._libsr   r   r   pandas.core.dtypes.commonr	   pandas.core.dtypes.dtypesr
   pandas.core.dtypes.missingr   pandas.corer   pandas.core.array_algosr   pandas.core.arrays.maskedr   r   rA   pandas._typingr   r   r   r   r   r   r|   r/   r&   r"   r!   <module>r      s   " " " " " "                     
 3 2 2 2 2 2 > > > > > > + + + + + +       8 8 8 8 8 8       
  	NNN              l; l; l; l; l;? l; l; l;` %*T T T T Tnh h h h h? h h h h hr"   