
    `Vg1+                        d dl mZ d dlZd dlmZmZ d dlZd dlm	Z	m
Z d dlmZmZm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mZ er
d dlZd dlmZ e G d de             Z	 d	 	 	 ddZ G d de      Z y)    )annotationsN)TYPE_CHECKINGcast)libmissing)DtypeDtypeObjtype_t)is_list_likeis_numeric_dtype)register_extension_dtype)isna)ops)BaseMaskedArrayBaseMaskedDtype)nptc                      e Zd ZdZdZ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)BooleanDtypeaf  
    Extension dtype for boolean data.

    .. versionadded:: 1.0.0

    .. warning::

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

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

    Methods
    -------
    None

    Examples
    --------
    >>> pd.BooleanDtype()
    BooleanDtype
    booleanc                "    t         j                  S N)npbool_selfs    [/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pandas/core/arrays/boolean.pytypezBooleanDtype.typeF   s    xx    c                     y)Nb r   s    r   kindzBooleanDtype.kindJ   s    r   c                ,    t        j                  d      S )Nbool)r   dtyper   s    r   numpy_dtypezBooleanDtype.numpy_dtypeN   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_typeR   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r.   r!   r   s    r   _is_numericzBooleanDtype._is_numericd   r0   r   c                   ddl }|j                   |j                         k7  rt        d|j                   d      t	        ||j
                        r|g}n|j                  }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        j'                  |      S )
zI
        Construct BooleanArray from pyarrow Array/ChunkedArray.
        r   Nz$Expected array of boolean type, got z instead   )offsetF)zero_copy_onlyr%   )pyarrowr   r   	TypeError
isinstanceArraychunksbuffersr(   from_bufferslenr5   to_numpy
null_countr   zerosr$   appendarray_concat_same_type)
r   rD   r8   r<   resultsarrbuflistdatamaskbool_arrs
             r   __from_arrow__zBooleanDtype.__from_arrow__h   s    	::(B5::,hWXXeW]]+WF \\F 	%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   )rM   str)rM   znp.dtype)rM   ztype_t[BooleanArray])rM   r$   )rD   z$pyarrow.Array | pyarrow.ChunkedArrayrM   r(   )__name__
__module____qualname____doc__namepropertyr   r"   r&   classmethodr*   r,   r/   r2   rL   r!   r   r   r   r   (   s    0 D              ';9';	';r   r   c                P   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                        rt        | j                        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 inputr7   zNeed to pass bool-like valuesT)skipna)floatingintegerzmixed-integer-float)r   emptyznpt.NDArray[np.bool_]z&values.shape and mask.shape must match)r:   r(   
ValueError_data_maskcopyr   ndarrayr%   r   r   r   rB   r?   r$   astypeallr9   asarrayobjectr   infer_dtyper   floatshaperD   )valuesrJ   r^   mask_valuesvalues_boolvalues_objectinferred_dtypeinteger_likes           r   coerce_to_arrayrm      s   " &,'FGG||V\\[[]F99;Dt|K&"**%&,,"((*B[[]F	FBJJ	',<V\\,J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                      e Zd ZdZdZdZdZh dZh 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 xZS )r(   aZ  
    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).

    .. versionadded:: 1.0.0

    .. 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                    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r^   )
r:   r   r_   r%   r   r9   r   _dtypesuper__init__)r   rg   rJ   r^   	__class__s       r   r}   zBooleanArray.__init__'  sS     62::.6<<2883K2  #nD1r   c                    | j                   S r   )r{   r   s    r   r%   zBooleanArray.dtype2  s    {{r   N)r%   r^   true_valuesfalse_valuesc                  	
 | j                   j                  |xs g       
| j                  j                  |xs g       		
fd}|D cg c]
  } ||       }}| j                  |||      S c c}w )Nc                N    t        |       r| S | v ry| v ryt        |  d      )NTFz cannot be cast to bool)r   r[   )sfalse_values_uniontrue_values_unions    r   
map_stringz:BooleanArray._from_sequence_of_strings.<locals>.map_stringC  s:    Aw''(( A3&=!>??r   )r%   r^   )_TRUE_VALUESunion_FALSE_VALUES_from_sequence)r)   stringsr%   r^   r   r   r   xscalarsr   r   s            @@r   _from_sequence_of_stringsz&BooleanArray._from_sequence_of_strings6  sy      ,,22;3D"E ..44\5GRH	@ +22Q:a=22!!'T!BB 3s   A0rz   c               .    |r|dk(  sJ t        ||      S )Nr   rz   )rm   )r)   valuer%   r^   s       r   _coerce_to_arrayzBooleanArray._coerce_to_arrayR  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   r4   z(can only perform ops with 1-d structuresFrz   z+'other' should be pandas.NA or a bool. Got z	 instead.zLengths must match>   r   r   >   r   r   )rO   r   	is_scalarr:   r(   r\   r]   r   r   rb   ndimNotImplementedErrorrm   r   item
libmissingNAis_boolr9   r   r?   r[   r   	kleene_or
kleene_and
kleene_xor_maybe_mask_result)r   otheropother_is_scalarrJ   results         r   _logical_methodzBooleanArray._logical_methodZ  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   )F)rg   
np.ndarrayrJ   r   r^   r$   rM   None)rM   r   )r   z	list[str]r%   zDtype | Noner^   r$   r   list[str] | Noner   r   rM   r(   )r%   r	   r^   r$   rM   tuple[np.ndarray, np.ndarray])rO   rP   rQ   rR   _internal_fill_value_truthy_value_falsey_valuer   r   r}   rT   r%   rU   r   r   r_   numbersNumberr$   r   _HANDLED_TYPESr   r   __classcell__)r~   s   @r   r(   r(      s   3l !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"5r   r(   )NF)r^   r$   rM   r   )!
__future__r   r   typingr   r   numpyr   pandas._libsr   r   r   pandas._typingr   r	   r
   pandas.core.dtypes.commonr   r   pandas.core.dtypes.dtypesr   pandas.core.dtypes.missingr   pandas.corer   pandas.core.arrays.maskedr   r   r8   r   r   rm   r(   r!   r   r   <module>r      s    " 
   ? + 
 " f;? f; f;T %*T!T"TnS5? S5r   