
    if4                    @   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%y)    )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y)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]nameFc                "    t         j                  S N)npbool_selfs    W/app/cer_product_mecsu/.venv/lib/python3.12/site-packages/pandas/core/arrays/boolean.pytypezBooleanDtype.type_   s    xx    c                     y)Nb r   s    r!   kindzBooleanDtype.kindc   s    r#   c                ,    t        j                  d      S )Nbool)r   dtyper   s    r!   numpy_dtypezBooleanDtype.numpy_dtypeg   s    xxr#   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                     y)Nr   r&   r   s    r!   __repr__zBooleanDtype.__repr__u   s    r#   c                     yNTr&   r   s    r!   _is_booleanzBooleanDtype._is_booleanx       r#   c                     yr2   r&   r   s    r!   _is_numericzBooleanDtype._is_numeric|   r4   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_buffersr:   to_numpy
null_countzerosappendarray_concat_same_type)r    rM   r<   rC   rD   maskdataresultsarrbuflistbool_arrs              r!   __from_arrow__zBooleanDtype.__from_arrow__   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"   )rV   str)rV   znp.dtype)rV   ztype_t[BooleanArray])rV   r)   )rM   z$pyarrow.Array | pyarrow.ChunkedArrayrV   r-   )__name__
__module____qualname____doc__r   __annotations___internal_fill_valuepropertyr"   r'   r+   r.   r0   r3   r6   rU   r&   r#   r!   r   r   *   s    )V $D-# !            /;9/;	/;r#   r   c                Z   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	d
g|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iufcbr8   zNeed to pass bool-like valuesTskipna)floatingintegerzmixed-integer-floatr   rF   npt.NDArray[np.bool_]z&values.shape and mask.shape must match)r@   r-   
ValueError_data_maskcopyr   ndarrayr*   r   r'   r   rK   rB   r)   astypeallr?   asarrayobjectr   infer_dtyper   floatshaperM   )valuesrO   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)W!D|!DD;<< 2D4GH#f+T2,k\:AA$G| l*FF|$++E2 +.55e<=
 ;<<|+xxD1		D"**	%$***@"+%D99;DxxD)"+%D||tzz!A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 )r-   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falsec                F    t         |   ||      }t               |_        |S r   )super_simple_newr   _dtype)clsrr   rO   result	__class__s       r!   r   zBooleanArray._simple_newF  s"    $VT2$r#   Fc                    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   rO   ri   r   s       r!   r   zBooleanArray.__init__L  sS     62::.6<<2883K2  #nD1r#   c                    | j                   S r   )r   r   s    r!   r*   zBooleanArray.dtypeW  s    {{r#   N)ri   true_valuesfalse_valuesnone_valuesc               J  
 | j                   j                  |xs g       | j                  j                  |xs g       
g d
fd}t        j                  |t
              }t        |      }	t        t        |||	                ||	 <   | j                  |||      S )Nc                >    | v ry| v ry| v ry t        |  d      )NTFz cannot be cast to bool)rf   )sfalse_values_unionr   true_values_unions    r!   
map_stringz:BooleanArray._from_sequence_of_strings.<locals>.map_stringl  s9    %%((k! A3&=!>??r#   r8   )r*   ri   )rV   zbool | None)
_TRUE_VALUESunion_FALSE_VALUESr   rM   rn   r   listmap_from_sequence)r   stringsr*   ri   r   r   r   r   scalarsrO   r   r   s         `   @@r!   _from_sequence_of_stringsz&BooleanArray._from_sequence_of_strings[  s      ,,22;3D"E ..44\5GRHK	@ ((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                  }}nrt        |      r=t        j                  |d      }|j                  dkD  rt        S 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)   r8   r9   Fr   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NotImplementedrx   r   item
libmissingNAis_boolr?   r"   rB   rf   r   	kleene_or
kleene_and
kleene_xor_maybe_mask_result)r    otheropother_is_scalarrO   r   s         r!   _logical_methodzBooleanArray._logical_method  s   {{MMMM--.e\*++u{{4E% JJuF3EzzA~%%)%e<KE4rxx(JJLEuJMM9#++eBTE{++,I7 
 3t9E
#:122;;/)==UDJJMLFD[[-->>$**eTZZNLFD >>$**eTZZNLFD &&vt44r#   Tra   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   kwargsrP   rO   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.ndarrayrO   re   rV   r   )F)rr   r   rO   r   ri   r)   rV   None)rV   r   )r   z	list[str]r*   r   ri   r)   r   list[str] | Noner   r   r   r   rV   r-   )r*   r   ri   r)   rV   tuple[np.ndarray, np.ndarray])r   rW   rb   r)   rV   r   )rX   rY   rZ   r[   r   r   classmethodr   r   r^   r*   r   r   rj   numbersNumberr)   r   _HANDLED_TYPESr   r   r   __classcell__)r   s   @r!   r-   r-     sG   8t 8L;M  BG	2 	2(2	2:>	2		2    (,)-(,CC 	C
 C &C 'C &C 
C C> jj'..$AN5:1&1.21	&1 1!5H ,0$(	r#   r-   )NF)ri   r)   rV   r   )&
__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   r<   pandas._typingr   r   r   r   r   rx   r-   r&   r#   r!   <module>r      s    "    / 2 > +  8
   9 HC;? C;  C;N %*R!R"Rj On? n nr#   