Ë
    *�£jf4  ã                  ó@  — 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    ú<C:\FundamentalWorkbench\vendor\pandas\core\arrays\boolean.pyÚtypezBooleanDtype.type_   s   € ä�x‰xˆó    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   € ä�x‰x˜ÓÐ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õ  € ó 	à�:‰:˜˜Ÿ™›Ò(°·±×1FÑ1FÀuÇzÁzÔ1RÜÐBÀ5Ç:Á:À,ÈhÐWÓXÐXä�e˜WŸ]™]Ô+Ø�WˆFÜ˜“Z‰Fð —\‘\ˆFØ—\‘\“^ˆFà�=‰=× Ñ  §¡Ô,Ü—7‘7˜6¬Ô.ˆDä—8‘8˜F¬$Ô/ˆDÜ  dÓ+Ð+àˆÜˆCØ—k‘k“mˆGØ×'Ñ'×4Ñ4Ø—‘œ#˜c›( T¨7°1©:Ð$6¸s¿z¹zð 5ó ç‰h eˆhÓ,ð ð �~‰~ Ò"Ø×+Ñ+×8Ñ8Ø—H‘Hœc #›h¨¨w°q©zÐ(:À3Ç:Á:ð 9ó ç‘(¨%�(Ó0ð ð �u‘ä—x‘x¤ C£´Ô5�ä# D¨$Ó/ˆHØ�N‰N˜8Ö$ð ñ  ÜÜ—‘˜¤2§8¡8Ô,¬b¯h©h°rÄÇÁÔ.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                  «       } �n¸t        | t        j                  «      r«| j                  j                  dv r“t        | «      }t        j                  t        | «      t        ¬«      }| |    j                  t        «      || <   t        j                   ||    j                  | j                  «      | |    k(  «      st#        d«      ‚|} nót        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Ø—9‘9“;ˆDØ�tˆ|Ðà€KÜ�&œ"Ÿ*™*Ô%¨&¯,©,¼"¿(¹(Ò*BÚØ—[‘[“]ŠFÜ	�FœBŸJ™JÔ	'¨F¯L©L×,=Ñ,=ÀÑ,HÜ˜6“lˆä—h‘hœs 6›{´$Ô7ˆØ$*¨K¨<Ñ$8×$?Ñ$?ÄÓ$Eˆ�[�LÑ!ä�v‰vØ˜˜Ñ%×,Ñ,¨V¯\©\Ó:¸fÀkÀ\Ñ>RÑRô
ô Ð;Ó<Ð<à‰äŸ
™
 6´Ô8ˆäŸ™¨¸tÔDˆØEˆØ )¨WÐ!D°|Ñ!DÑDÜÐ;Ó<Ð<ô Ð2´D¸Ó4GÓHˆÜ—‘œ#˜f›+¬TÔ2ˆØ,¨k¨\Ñ:×AÑAÄ$ÓGˆ�ˆ|Ñð ˜lÑ*Ü�F‰FØ˜�|Ñ$×+Ñ+¬EÓ2Ø  + Ñ.×5Ñ5´eÓ<ñ=ôô
 Ð;Ó<Ð<à€|˜Ð+Ü�x‰x˜Ÿ™¬DÔ1‰Ø	ˆØ‰Ü	�Dœ"Ÿ*™*Ô	%¨$¯*©*¼¿¹Ò*@ØÐ"Ø˜+Ñ%‰DÙØ—9‘9“;‰Dä�x‰x˜¤DÔ)ˆØÐ"Ø˜+Ñ%ˆDà‡|�|�t—z‘zÒ!ÜÐ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"   ø€ ä‘Ñ$ V¨TÓ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   ø€ ô ˜6¤2§:¡:Ô.°6·<±<Ä2Ç8Á8Ò3KÜð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Ñ!Øä  A 3Ð&=Ð!>Ó?Ð?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°\Ò5GÀRÓHÐàÐØˆK÷	@ô —(‘(˜7¬&Ô1ˆÜ�G‹}ˆÜœc *¨g°t°e©nÓ=Ó>ˆ��‰Ø×!Ñ! '°¸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Ò%Ð%Ð%Ü˜u¨4Ô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§{¡{�4‰EÜ˜%Ô Ü—J‘J˜u¨FÔ3ˆEØ�z‰z˜AŠ~Ü%Ð%Ü)¨%°eÔ<‰KˆE‘4Ü˜œrŸx™xÔ(Ø—J‘J“LˆEá˜u¬J¯M©MÑ9Ä#Ç+Á+ÈeÔBTÜðÜ˜E“{×+Ñ+Ð,¨Ið7óð ñ
 ¤3 t£9´°E³
Ò#:ÜÐ1Ó2Ð2à�;‰;˜/Ñ)ÜŸ=™=¨¯©°U¸D¿J¹JÈÓM‰LˆF‘DØ�[‰[Ð-Ñ-ÜŸ>™>¨$¯*©*°e¸T¿Z¹ZÈÓN‰LˆF‘Dô Ÿ>™>¨$¯*©*°e¸T¿Z¹ZÈÓN‰LˆF�Dð ×&Ñ& v¨tÓ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”   € ð �z‰zˆØ�z‰zˆØÐ'Ñ'ÜÔ-¨tÓ4ˆBÙ˜D $Ñ@¨vÐ@¸Ñ@‰JˆD�$Ø×#Ñ# 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 8€LÚ;€Màôó ðð BGð	2Ø ð	2Ø(2ð	2Ø:>ð	2à	õ	2ð òó ðð ð Ø(,Ø)-Ø(,ñCàðCð ð	Cð
 ðCð &ðCð 'ðCð &ðCð 
òCó ðCð> —j‘j '§.¡.°$¸¿¹ÐA€Nàà5:ñ1Ø&ð1Ø.2ð1à	&ò1ó ð1ò!5ðH ,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#   