
    Owg0                        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#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                      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y)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                "    t         j                  S N)npbool_selfs    Q/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/core/arrays/boolean.pytypezBooleanDtype.typeD   s    xx    c                     y)Nb r   s    r   kindzBooleanDtype.kindH   s    r!   c                ,    t        j                  d      S )Nbool)r   dtyper   s    r   numpy_dtypezBooleanDtype.numpy_dtypeL   s    xxr!   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                     y)Nr   r$   r   s    r   __repr__zBooleanDtype.__repr__[   s    r!   c                     yNTr$   r   s    r   _is_booleanzBooleanDtype._is_boolean^       r!   c                     yr1   r$   r   s    r   _is_numericzBooleanDtype._is_numericb   r3   r!   c                   ddl }|j                   |j                         k7  r>|j                  j	                  |j                        st        d|j                   d      t        ||j                        r|g}t        |      }n|j                  }|j                         }|j                  j	                  |j                        rBt        j                  |t              }t        j                  |t              }t        ||      S g }|D ]	  }|j!                         }	|j                  j#                  |j                  t        |      d|	d   g|j$                        j'                  d	      }|j(                  dk7  rU|j                  j#                  |j                  t        |      d|	d   g|j$                        j'                  d	      }| }n$t        j*                  t        |      t              }t        ||      }
|j-                  |
        |sRt        t        j.                  g t        j                        t        j.                  g t        j                              S t        j1                  |      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_buffersr9   to_numpy
null_countzerosappendarray_concat_same_type)r   rL   r;   rB   rC   maskdataresultsarrbuflistbool_arrs              r   __from_arrow__zBooleanDtype.__from_arrow__f   s    	::(1F1Fuzz1RB5::,hWXXeW]]+WFZF \\F\\^F==  ,776.D88F$/Dd++ 	%CkkmG''44#c(T71:$6szz 5 heh,  ~~"++88HHc#hwqz(:3:: 9 (%(0  uxxC5#D$/HNN8$	%  288,bhhr.J   11'::r!   N)returnr    )rU   str)rU   znp.dtype)rU   ztype_t[BooleanArray]rU   r'   )rL   z$pyarrow.Array | pyarrow.ChunkedArrayrU   r+   )__name__
__module____qualname____doc__r   __annotations__propertyr    r%   r)   classmethodr-   r/   r2   r5   rT   r$   r!   r   r   r   (   s    , $D-#              /;9/;	/;r!   r   c                V   t        | t              rK|t        d      | j                  | j                  }} |r | j                         } |j                         }| |fS d}t        | t        j                        r2| j                  t        j                  k(  r|r| j                         } nt        | t        j                        r| j                  j                  dv rt        |       }t        j                  t        |       t              }| |    j                  t              || <   t        j                   ||    j                  | j                        | |    k(        st#        d      |} nt        j$                  | t&              }t)        j*                  |d      }d}|d	|z   vrt#        d      t-        d
t        |            }t        j                  t        |       t              } ||    j                  t              | | <   ||v rQt        j                   | |    j                  t.              ||    j                  t.              k(        st#        d      |(|&t        j                  | j0                  t              }ny||}ntt        |t        j                        r8|j                  t        j                  k(  r|||z  }n5|r3|j                         }n"t        j2                  |t              }|||z  }| j0                  |j0                  k7  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iufcbr7   zNeed to pass bool-like valuesTskipna)floatingintegerzmixed-integer-float)r   rE   npt.NDArray[np.bool_]z&values.shape and mask.shape must match)r?   r+   
ValueError_data_maskcopyr   ndarrayr(   r   r%   r   rJ   rA   r'   astypeallr>   asarrayobjectr   infer_dtyper   floatshaperL   )valuesrN   ri   mask_valuesvalues_boolvalues_objectinferred_dtypeinteger_likes           r   coerce_to_arrayrx      s   " &,'FGG||V\\[[]F99;Dt|K&"**%&,,"((*B[[]F	FBJJ	'FLL,=,=,H6lhhs6{$7$*K<$8$?$?$E[L!vv%,,V\\:fk\>RR
 ;<<

68tDE!5!DD;<< 2D4GH#f+T2,k\:AA$G| l*FF|$++E2 +.55e<=
 ;<<|+xxD1	dBJJ'DJJ"((,B&k)99;D88D-D&k)||tzz!ABB4<r!   c                  6    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falsec                F    t         |   ||      }t               |_        |S r   )super_simple_newr   _dtype)r,   rr   rN   result	__class__s       r   r   zBooleanArray._simple_new-  s"    $VT2$r!   c                    t        |t        j                        r|j                  t        j                  k(  st        d      t               | _        t        | %  |||       y )NzIvalues should be boolean numpy array. Use the 'pd.array' function insteadri   )
r?   r   rj   r(   r   r>   r   r   r   __init__)r   rr   rN   ri   r   s       r   r   zBooleanArray.__init__3  sS     62::.6<<2883K2  #nD1r!   c                    | j                   S r   )r   r   s    r   r(   zBooleanArray.dtype>  s    {{r!   N)r(   ri   true_valuesfalse_valuesc               >  	
 | j                   j                  |xs g       
| j                  j                  |xs g       	d	
fd}t        j                  |t
              }t        |      }t        t        |||                || <   | j                  |||      S )Nc                4    | v ry| v ryt        |  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_stringO  s.    %%(( A3&=!>??r!   r7   )r(   ri   rW   )
_TRUE_VALUESunion_FALSE_VALUESr   rL   rn   r   listmap_from_sequence)r,   stringsr(   ri   r   r   r   scalarsrN   r   r   s            @@r   _from_sequence_of_stringsz&BooleanArray._from_sequence_of_stringsB  s      ,,22;3D"E ..44\5GRH	@ ((7&1G}c*gten=>!!'T!BBr!   r   c               .    |r|dk(  sJ t        ||      S )Nr   r   )rx   )r,   valuer(   ri   s       r   _coerce_to_arrayzBooleanArray._coerce_to_array^  s"     I%%%u400r!   c                   |j                   dv sJ t        j                  |      }d }t        |t              r|j
                  |j                  }}nwt        |      rBt        j                  |d      }|j                  dkD  rt        d      t        |d      \  }}n*t        |t        j                        r|j                         }|rI|t        j                   ur7t        j"                  |      s"t%        dt'        |      j                    d	      |s"t)        |       t)        |      k7  rt+        d
      |j                   dv r0t-        j.                  | j
                  || j                  |      \  }}nm|j                   dv r0t-        j0                  | j
                  || j                  |      \  }}n/t-        j2                  | j
                  || j                  |      \  }}| j5                  ||      S )N>   or_xorand_ror_rxorrand_r'   r7   r8   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   )rX   r   	is_scalarr?   r+   rg   rh   r	   r   rm   ndimNotImplementedErrorrx   r   item
libmissingNAis_boolr>   r    rA   rf   r   	kleene_or
kleene_and
kleene_xor_maybe_mask_result)r   otheropother_is_scalarrN   r   s         r   _logical_methodzBooleanArray._logical_methodf  s   {{MMMM--.e\*++u{{4E% JJuF3EzzA~)*TUU)%e<KE4rxx(JJLEuJMM9#++eBTE{++,I7 
 3t9E
#:122;;/)==UDJJMLFD[[-->>$**eTZZNLFD >>$**eTZZNLFD &&vt44r!   ra   c                  | j                   }| j                  }|dv r1t        t        |      } |||fd|i|\  }}| j	                  ||      S ddlm}   ||j                  t              |      j                  |fd|i|S )N)cummincummaxrb   r   )IntegerArray)
rg   rh   getattrr   r   pandas.core.arraysr   rk   int_accumulate)r   r   rb   kwargsrO   rN   r   r   s           r   r   zBooleanArray._accumulate  s     zzzz''-t4BD$@v@@JD$##D$//7C<C 0$7CC#'- r!   )rr   
np.ndarrayrN   re   rU   r   )F)rr   r   rN   r   ri   r'   rU   None)rU   r   )r   z	list[str]r(   zDtype | Noneri   r'   r   list[str] | Noner   r   rU   r+   )r(   r   ri   r'   rU   tuple[np.ndarray, np.ndarray])r   rV   rb   r'   rU   r   )rX   rY   rZ   r[   _internal_fill_value_truthy_value_falsey_valuer   r   r^   r   r   r]   r(   r   r   rj   numbersNumberr'   r   _HANDLED_TYPESr   r   r   __classcell__)r   s   @r   r+   r+      sN   1h ! MM7L;M  BG	2 	2(2	2:>	2		2   
 #(,)-CC 	C
 C &C 'C 
C C2 jj'..$AN5:1&1.21	&1 1!5H ,0$(	r!   r+   )NF)ri   r'   rU   r   )$
__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   r;   pandas._typingr   r   r   r   r   r   rx   r+   r$   r!   r   <module>r      s    "   
 3 > +  8
   l;? l; l;` %*T!T"Tnh? hr!   