zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
U
¬ý°dð/ã@sòddlmZddlZddlmZmZddlZddlm    Z    m
Z ddl m Z mZmZddlmZmZddlmZddlmZdd    lmZdd
lmZdd lmZmZer¸ddlZdd l mZeGd d„deƒƒZ ddddœdd„Z!Gdd„deƒZ"dS)é)Ú annotationsN)Ú TYPE_CHECKINGÚcast)ÚlibÚmissing)ÚDtypeÚDtypeObjÚtype_t)Ú is_list_likeÚis_numeric_dtype)Úregister_extension_dtype)Úisna)Úops)Úmasked_accumulations)ÚBaseMaskedArrayÚBaseMaskedDtype)Únptc@sžeZdZdZdZeddœdd„ƒZeddœdd    „ƒZed
dœd d „ƒZe    d dœdd„ƒZ
ddœdd„Z eddœdd„ƒZ eddœdd„ƒZ dddœdd„ZdS)Ú 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
    ÚbooleanÚtype©ÚreturncCstjS©N)ÚnpÚbool_©Úself©rúQd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/arrays/boolean.pyrEszBooleanDtype.typeÚstrcCsdS)NÚbrrrrrÚkindIszBooleanDtype.kindznp.dtypecCs
t d¡S)NÚbool)rÚdtyperrrrÚ numpy_dtypeMszBooleanDtype.numpy_dtypeztype_t[BooleanArray]cCstS)zq
        Return the array type associated with this dtype.
 
        Returns
        -------
        type
        )Ú BooleanArray)ÚclsrrrÚconstruct_array_typeQs    z!BooleanDtype.construct_array_typecCsdS)NrrrrrrÚ__repr__\szBooleanDtype.__repr__r"cCsdS©NTrrrrrÚ _is_boolean_szBooleanDtype._is_booleancCsdSr)rrrrrÚ _is_numericcszBooleanDtype._is_numericz$pyarrow.Array | pyarrow.ChunkedArrayr%)Úarrayrc
Csddl}|j| ¡kr(td|j›dƒ‚t||jƒr<|g}n|j}g}|D]œ}| ¡}|jj    |jt
|ƒd|dg|j dj dd}|j dkrÀ|jj    |jt
|ƒd|dg|j dj dd}|}ntjt
|ƒtd    }t||ƒ}    | |    ¡qJ|sttjgtjd    tjgtjd    ƒSt |¡SdS)
zI
        Construct BooleanArray from pyarrow Array/ChunkedArray.
        rNz$Expected array of boolean type, got z insteadé)ÚoffsetF)Zzero_copy_only©r#)ÚpyarrowrrÚ    TypeErrorÚ
isinstanceÚArrayÚchunksÚbuffersr%Z from_buffersÚlenr.Zto_numpyZ
null_countrÚzerosr"Úappendr,Z_concat_same_type)
rr,r0r4ÚresultsZarrZbuflistÚdataÚmaskZbool_arrrrrÚ__from_arrow__gsH 
ÿþ
 
ÿþ
 ÿzBooleanDtype.__from_arrow__N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__ÚnameÚpropertyrr!r$Ú classmethodr'r(r*r+r<rrrrr)s 
rFr"útuple[np.ndarray, np.ndarray])ÚcopyrcCs@t|tƒrD|dk    rtdƒ‚|j|j}}|r<| ¡}| ¡}||fSd}t|tjƒrp|jtj    krp|rl| ¡}nt|tjƒræt
|jƒræt |ƒ}tj t |ƒtd}|| t¡||<t || |j¡||k¡sàtdƒ‚|}n¦tj|td}tj|dd}d}|d|krtdƒ‚td    t |ƒƒ}tj t |ƒtd}|| t¡||<||krŒt || t¡|| t¡k¡sŒtdƒ‚|dkr²|dkr²tj |jtd}np|dkrÂ|}n`t|tjƒr|jtj    kr|dk    rò||B}n|r"| ¡}n tj|td}|dk    r"||B}|j|jkr8td
ƒ‚||fS) 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 inputr/zNeed to pass bool-like valuesT©Úskipna)ZfloatingÚintegerzmixed-integer-float)rÚemptyznpt.NDArray[np.bool_]z&values.shape and mask.shape must match)r2r%Ú
ValueErrorÚ_dataÚ_maskrErÚndarrayr#rr r r7r6r"ÚastypeÚallr1ÚasarrayÚobjectrZ infer_dtyperÚfloatÚshaper,)Úvaluesr;rEZ mask_valuesZ values_boolZ values_objectZinferred_dtypeZ integer_likerrrÚcoerce_to_array‘sh
 ÿ
ÿÿÿ
 
 
 
 
rUc    sÞeZdZdZdZdZdZdddddhZd    d
d d d hZd.dddddœ‡fdd„ Z    e
ddœdd„ƒZ e dddddœdddddddœdd„ƒZ ejejeejfZe dd œd!dd"d#œd$d%„ƒZd&d'„Zdd(œd)dd*d+œd,d-„Z‡ZS)/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ÚTrueÚTRUEÚtrueÚ1z1.0ÚFalseÚFALSEÚfalseÚ0z0.0z
np.ndarrayr"ÚNone)rTr;rErcs>t|tjƒr|jtjks tdƒ‚tƒ|_tƒj    |||ddS)NzIvalues should be boolean numpy array. Use the 'pd.array' function instead©rE)
r2rrMr#rr1rÚ_dtypeÚsuperÚ__init__)rrTr;rE©Ú    __class__rrrb&s ÿzBooleanArray.__init__rrcCs|jSr)r`rrrrr#1szBooleanArray.dtypeN)r#rEÚ true_valuesÚ false_valuesz    list[str]z Dtype | Nonezlist[str] | None)Ústringsr#rErerfrc    st|j |p g¡‰|j |pg¡‰ddœ‡‡fdd„ }tj|td}t|ƒ}tt|||ƒƒ||<|j    |||dS)Nr"rcs*|ˆkr dS|ˆkrdSt|›dƒ‚dS)NTFz cannot be cast to bool)rJ)Ús©Zfalse_values_unionZtrue_values_unionrrÚ
map_stringBs
z:BooleanArray._from_sequence_of_strings.<locals>.map_stringr/)r#rE)
Ú _TRUE_VALUESÚunionÚ _FALSE_VALUESrr,rQr ÚlistÚmapZ_from_sequence)    r&rgr#rErerfrjZscalarsr;rrirÚ_from_sequence_of_strings5s
z&BooleanArray._from_sequence_of_stringsr_rrD)r#rErcCs|r|dkst‚t||dS)Nrr_)ÚAssertionErrorrU)r&Úvaluer#rErrrÚ_coerce_to_arrayQs zBooleanArray._coerce_to_arraycCs<|jdkst‚t |¡}d}t|tƒr6|j|j}}nNt|ƒrpt    j
|dd}|j dkr^t dƒ‚t |dd\}}nt|t    jƒr„| ¡}|r²|tjk    r²t |¡s²tdt|ƒj›d    ƒ‚|sÎt|ƒt|ƒkrÎtd
ƒ‚|jd kròt |j||j|¡\}}n>|jd krt |j||j|¡\}}nt |j||j|¡\}}| ||¡S) N>ÚxorÚrxorÚrand_Úor_Úand_Úror_r"r/r-z(can only perform ops with 1-d structuresFr_z+'other' should be pandas.NA or a bool. Got z     instead.zLengths must match>ryrw>rvrx)r=rqrZ    is_scalarr2r%rKrLr
rrPÚndimÚNotImplementedErrorrUrÚitemÚ
libmissingZNAZis_boolr1rr6rJrZ    kleene_orZ
kleene_andZ
kleene_xorZ_maybe_mask_result)rÚotherÚopZother_is_scalarr;ÚresultrrrÚ_logical_methodYs0
 
 
 ÿ
 zBooleanArray._logical_methodrFrr)rArGrcKs||j}|j}|dkrJtt|ƒ}|||fd|i|—Ž\}}t|ƒ||ddSddlm}|| t¡|ƒj    |fd|i|—ŽSdS)N)ZcumminZcummaxrGFr_r)Ú IntegerArray)
rKrLÚgetattrrrZpandas.core.arraysr‚rNÚintÚ _accumulate)rrArGÚkwargsr:r;rr‚rrrr…|s
 ÿÿÿzBooleanArray._accumulate)F)r=r>r?r@Z_internal_fill_valueZ _truthy_valueZ _falsey_valuerkrmrbrBr#rCrprrMÚnumbersÚNumberr"rZ_HANDLED_TYPESrsrr…Ú __classcell__rrrcrr%ès.4ÿ ùÿ$ÿr%)NF)#Ú
__future__rr‡ÚtypingrrÚnumpyrZ pandas._libsrrr}Zpandas._typingrrr    Zpandas.core.dtypes.commonr
r Zpandas.core.dtypes.dtypesr Zpandas.core.dtypes.missingr Z pandas.corerZpandas.core.array_algosrZpandas.core.arrays.maskedrrr0rrrUr%rrrrÚ<module>s(      hÿW