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
U
¬ý°d6ã8@s@UdZddlmZddlZddlZddlZddlmZddl    m
Z
ddl m Z ddl mZddlmZerrddlZdad    ed
<gad ed <eadad ed<dad ed<dddddhdddhdœZdZdIdddœdd„ZdJddœdd„Zdd „Zddœd!d"„Zd#d$„Zej d%ej!d%ej"d&ej#d&ej$d'ej%d'ej&d(ej'd(ej(dej)dej*dej+dej,d)ej-d)ej.d*ejd+ej/d,ej0d-ej1d.ej2d/ej3d0ej4d0ej5d1ej6d1ej7d2ej8d2e9dej:diZ;d3d4„Z<d5d6„Z=eed7ƒƒd8d9„Z>d1d0d2d:œZ?ddœd;d<„Z@dKdd=œd>d?„ZAdLdd=œd@dA„ZBdMdddœdBdC„ZCdddDœdEdF„ZDd dœdGdH„ZEdS)NzL
Expressions
-----------
 
Offer fast expression evaluation through numexpr
 
é)Ú annotationsN)Ú
get_option)ÚFuncType)Úfind_stack_level)ÚNUMEXPR_INSTALLED)Ú    roperatorz bool | NoneÚ
_TEST_MODEz
list[bool]Ú _TEST_RESULTzFuncType | NoneÚ    _evaluateÚ_whereÚint64Úint32Úfloat64Úfloat32Úbool)ÚevaluateÚwherei@BTÚNone)ÚvÚreturncCs$tr|atrtntatrtntadS©N)rÚ USE_NUMEXPRÚ_evaluate_numexprÚ_evaluate_standardr
Ú_where_numexprÚ_where_standardr ©r©rúZd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/computation/expressions.pyÚset_use_numexpr*s r)rcCs&tr"tr"|dkrt ¡}t |¡dSr)rrÚneZdetect_number_of_coresZset_num_threads)ÚnrrrÚset_numexpr_threads7sr"cCstr tdƒ|||ƒS)z
    Standard evaluation.
    F)rÚ_store_test_result)ÚopÚop_strÚaÚbrrrr@srcCsZ|dk    rV|jtkrVtƒ}||fD]}t|dƒr ||jjhO}q t|ƒrRt||krVdSdS)z,return a boolean if we WILL be using numexprNÚdtypeTF)ÚsizeÚ _MIN_ELEMENTSÚsetÚhasattrr(ÚnameÚlenÚ_ALLOWED_DTYPES)r$r%r&r'Z dtype_checkZdtypesÚorrrÚ_can_use_numexprIs
 
r1cCsÎd}t||||dƒr¤|j d¡ d¡}|r4||}}|}|}z"tjd|›d||dœdd}Wn6tk
rrYn$tk
r”t|||ƒrŽn‚YnX|r¤||}}t    r´t
|dk    ƒ|dkrÊt ||||ƒ}|S)    NrÚ_Úrza_value z b_value)Úa_valueÚb_valueÚsafe©Z
local_dictZcasting) r1Ú__name__ÚstripÚ
startswithr rÚ    TypeErrorÚNotImplementedErrorÚ_bool_arith_fallbackrr#r)r$r%r&r'ÚresultZ is_reversedr4r5rrrr\s4
 
ý
 
 rú+Ú*ú-ú/z**z==z!=z<=ú<z>=ú>ú&ú|ú^cCst |||¡Sr)Únpr)Úcondr&r'rrrr©srcCsDd}tdd||dƒr,tjd|||dœdd}|dkr@t|||ƒ}|S)Nrz#where(cond_value, a_value, b_value))Z
cond_valuer4r5r6r7)r1r rr)rIr&r'r>rrrr®s
ý rzcompute.use_numexprcCs6z |jtkWStk
r0t|ttjfƒYSXdSr)r(rÚAttributeErrorÚ
isinstancerHZbool_)ÚxrrrÚ_has_bool_dtypeÃs rM)r?r@rAcCsJt|ƒrFt|ƒrF|tkrFtjdt|ƒ›dtt|ƒ›dtƒddSdS)z¨
    Check if we should fallback to the python `_evaluate_standard` in case
    of an unsupported operation by numexpr, which is the case for some
    boolean ops.
    z'evaluating in Python space because the z> operator is not supported by numexpr for the bool dtype, use z     instead.)Ú
stacklevelTF)rMÚ_BOOL_OP_UNSUPPORTEDÚwarningsÚwarnÚreprr)r%r&r'rrrr=Ísür=)Ú use_numexprcCs0t|}|dk    r"|r"t||||ƒSt||||ƒS)zô
    Evaluate and return the expression of the op on a and b.
 
    Parameters
    ----------
    op : the actual operand
    a : left operand
    b : right operand
    use_numexpr : bool, default True
        Whether to try to use numexpr.
    N)Ú_op_str_mappingr
r)r$r&r'rSr%rrrrßs
rcCs(tdk    s t‚|rt|||ƒSt|||ƒS)zý
    Evaluate the where condition cond on a and b.
 
    Parameters
    ----------
    cond : np.ndarray[bool]
    a : return if cond is True
    b : return if cond is False
    use_numexpr : bool, default True
        Whether to try to use numexpr.
    N)r ÚAssertionErrorr)rIr&r'rSrrrrós rcCs |agadS)z¯
    Keeps track of whether numexpr was used.
 
    Stores an additional ``True`` for every successful use of evaluate with
    numexpr since the last ``get_test_result``.
    N)rr    rrrrÚ set_test_modesrV)Ú used_numexprrcCs|rt |¡dSr)r    Úappend)rWrrrr#sr#cCs t}ga|S)z1
    Get test result and reset test_results.
    )r    )ÚresrrrÚget_test_resultsrZ)T)N)T)T)T)FÚ__doc__Ú
__future__rÚoperatorrPÚnumpyrHZpandas._configrZpandas._typingrZpandas.util._exceptionsrZpandas.core.computation.checkrZpandas.core.opsrZnumexprr rÚ__annotations__r    rr
r r/r*rr"rr1rÚaddZraddÚmulZrmulÚsubZrsubÚtruedivZrtruedivÚfloordivZ    rfloordivÚmodZrmodÚpowZrpowÚeqÚleÚltÚgeÚgtÚand_Zrand_Úor_Zror_ÚxorZrxorÚdivmodZrdivmodrTrrrMrOr=rrrVr#rZrrrrÚ<module>sº           þ         *à$