zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
U
¬ý°dêAã@sxdZddlmZddlmZddlmZddlZddlmZm    Z    m
Z
m Z ddl Z ddlmZddlmZmZddlmmZdd    lmZmZdd
lmZdd lmZmZd Zd Z dZ!e e!Z"dZ#Gdd„dƒZ$Gdd„de$ƒZ%ddddœZ&Gdd„dƒZ'dd„Z(dd„Z)dZ*ej+ej,ej-ej.ej/ej0e(e)fZ1e2e3e*e1ƒƒZ4dZ5ej6ej7ej6ej7fZ8e2e3e5e8ƒƒZ9d Z:ej;ej<ej=ej>ej?ej@ejAfZBe2e3e:eBƒƒZCd!ZDej?ej@ejAfZEe2e3eDeEƒƒZFiZGe4e9eCfD]ZHeG IeH¡qÄd"d#œd$d%„ZJd&d#œd'd(„ZKGd)d*„d*e'ƒZLd&d#œd+d,„ZMGd-d.„d.eLƒZNd/ZOejPejQejRejRfZSe2e3eOeSƒƒZTGd0d1„d1e'ƒZUGd2d3„d3e'ƒZVGd4d5„d5ƒZWdS)6z
Operator classes for eval.
é)Ú annotations)Údatetime)ÚpartialN)ÚCallableÚIterableÚIteratorÚLiteral)Ú    Timestamp)Ú is_list_likeÚ    is_scalar)Úensure_decodedÚresult_type_many)ÚDEFAULT_GLOBALS)Ú pprint_thingÚpprint_thing_encoded)ÚsumÚprodÚminÚmax)ÚsinÚcosÚexpÚlogÚexpm1Úlog1pÚsqrtÚsinhÚcoshÚtanhZarcsinZarccosZarctanZarccoshZarcsinhZarctanhÚabsÚlog10ÚfloorÚceil)Zarctan2Z__pd_eval_local_cseZdZUd'‡fdd„    Zded<d(ddœdd    „Zed
dœd d „ƒZd
dœd d„Zdd„Z    ddœdd„Z
dd„Z ddœdd„Z eddœdd„ƒZ edd„ƒZeZed
dœdd„ƒZeddœdd„ƒZedd „ƒZejddœd!d „ƒZed"d#„ƒZed$dœd%d&„ƒZ‡ZS))ÚTermNcs&t|tƒstn|}tt|ƒj}||ƒS©N)Ú
isinstanceÚstrÚConstantÚsuperr#Ú__new__)ÚclsÚnameÚenvÚsideÚencodingÚklassZsupr_new©Ú    __class__©úRd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/computation/ops.pyr)Gs z Term.__new__ÚboolÚis_localÚNone©ÚreturncCsB||_||_||_t|ƒ}| t¡p*|tk|_| ¡|_    ||_
dSr$) Ú_namer,r-r&Ú
startswithÚ    LOCAL_TAGrr5Ú _resolve_nameÚ_valuer.)Úselfr+r,r-r.Ztnamer2r2r3Ú__init__Os
z Term.__init__r&cCs|j td¡S)NÚ)r+Úreplacer;©r>r2r2r3Ú
local_nameYszTerm.local_namecCs
t|jƒSr$)rr+rBr2r2r3Ú__repr__]sz Term.__repr__cOs|jSr$©Úvalue©r>ÚargsÚkwargsr2r2r3Ú__call__`sz Term.__call__cOs|Sr$r2rGr2r2r3Úevaluatecsz Term.evaluatecCslt|jƒ}|j}||jjkr2t|jj|tƒr2d}|jj||d}| |¡t    |dƒrh|j
dkrht dƒ‚|S)NF)r5Úndiméz?N-dimensional objects, where N > 2, are not supported with eval) r&rCr5r,Zscoper%ÚtypeÚresolveÚupdateÚhasattrrLÚNotImplementedError)r>rCr5Úresr2r2r3r<fs
 
ÿ
ÿzTerm._resolve_namecCs.|j}t|tƒr$|jj|j||d||_dS)zâ
        search order for local (i.e., @variable) variables:
 
        scope, key_variable
        [('locals', 'local_name'),
         ('globals', 'local_name'),
         ('locals', 'key'),
         ('globals', 'key')]
        )Ú    new_valueN)r+r%r&r,ZswapkeyrCrF)r>rFÚkeyr2r2r3rPws
 
z Term.updatecCs
t|jƒSr$)r r=rBr2r2r3r ‰szTerm.is_scalarc CsXz |jjjWStk
rRz|jjWYStk
rLt|jƒYYSXYnXdSr$)r=ÚvaluesÚdtypeÚAttributeErrorrNrBr2r2r3rNs z    Term.typecCs$t|ƒj›dt|jƒ›d|j›dS)Nz(name=z, type=ú))rNÚ__name__Úreprr+rBr2r2r3ÚrawœszTerm.rawcCs8z |jj}Wntk
r&|j}YnXt|ttjfƒSr$)rNrXÚ
issubclassrÚnpÚ
datetime64©r>Útr2r2r3Ú is_datetime s
  zTerm.is_datetimecCs|jSr$©r=rBr2r2r3rF©sz
Term.valuecCs
||_dSr$rc)r>rTr2r2r3rF­scCs|jSr$©r9rBr2r2r3r+±sz    Term.nameÚintcCs|jjSr$)r=rLrBr2r2r3rLµsz    Term.ndim)NN)NN)rZÚ
__module__Ú __qualname__r)Ú__annotations__r?ÚpropertyrCrDrJrKr<rPr rNÚ return_typer\rbrFÚsetterr+rLÚ __classcell__r2r2r0r3r#Fs6
 
 
 
 
r#csFeZdZd ddœ‡fdd„ Zdd„Zedd    „ƒZd
dœd d „Z‡ZS)r'Nr6r7cstƒj||||ddS)N)r-r.)r(r?)r>rFr,r-r.r0r2r3r?»szConstant.__init__cCs|jSr$rdrBr2r2r3r<¾szConstant._resolve_namecCs|jSr$rErBr2r2r3r+Ász Constant.namer&cCs
t|jƒSr$)r[r+rBr2r2r3rDÅszConstant.__repr__)NN)    rZrfrgr?r<rir+rDrlr2r2r0r3r'ºs
 
r'ú~ú&ú|)ÚnotÚandÚorc@s˜eZdZUdZded<dddddœdd    „Zd
d œd d „Zdd œdd„Zedd„ƒZ    edd œdd„ƒZ
edd„ƒZ edd œdd„ƒZ edd œdd„ƒZ dS)ÚOpz.
    Hold an operator of arbitrary arity.
    r&ÚopNzIterable[Term | Op]r6)rtÚoperandsr8cCst ||¡|_||_||_dSr$)Ú _bool_op_mapÚgetrtrur.)r>rtrur.r2r2r3r?Õsz Op.__init__rr7cCs
t|jƒSr$)ÚiterrurBr2r2r3Ú__iter__Úsz Op.__iter__cCs(dd„|jDƒ}td|j›d |¡ƒS)zW
        Print a generic n-ary operator and its operands using infix notation.
        css|]}dt|ƒ›dVqdS)ú(rYN)r)Ú.0Zoprr2r2r3Ú    <genexpr>âszOp.__repr__.<locals>.<genexpr>ú )rurrtÚjoin)r>Zparenedr2r2r3rDÝsz Op.__repr__cCs,|jttkrtjStdd„t |¡DƒŽS)Ncss|] }|jVqdSr$©rN©r{Útermr2r2r3r|êsz!Op.return_type.<locals>.<genexpr>)rtÚ CMP_OPS_SYMSÚ BOOL_OPS_SYMSr^Úbool_r ÚcomÚflattenrBr2r2r3rjåszOp.return_typer4cCs(|j}tt d¡gƒ}|jtko&||S)NÚobject)Ú operand_typesÚ    frozensetr^rWrjr‡)r>ÚtypesZ obj_dtype_setr2r2r3Úhas_invalid_return_typeìszOp.has_invalid_return_typecCstdd„t |¡DƒƒS)Ncss|] }|jVqdSr$rr€r2r2r3r|ôsz#Op.operand_types.<locals>.<genexpr>)r‰r…r†rBr2r2r3rˆòszOp.operand_typescCstdd„|jDƒƒS)Ncss|] }|jVqdSr$)r )r{Úoperandr2r2r3r|øszOp.is_scalar.<locals>.<genexpr>)ÚallrurBr2r2r3r ösz Op.is_scalarcCs8z |jj}Wntk
r&|j}YnXt|ttjfƒSr$)rjrNrXr]rr^r_r`r2r2r3rbús
  zOp.is_datetime)N)rZrfrgÚ__doc__rhr?ryrDrirjr‹rˆr rbr2r2r2r3rsÎs
 
 
rsc Cs\z | |¡WStk
rVt|ƒrJz| |¡WYStk
rHYnX||kYSXdS)z`
    Compute the vectorized membership of ``x in y`` if possible, otherwise
    use Python.
    N©ÚisinrXr
©ÚxÚyr2r2r3Ú_ins r”c Cs`z| |¡WStk
rZt|ƒrNz| |¡WYStk
rLYnX||kYSXdS)zd
    Compute the vectorized membership of ``x not in y`` if possible,
    otherwise use Python.
    Nrr‘r2r2r3Ú_not_insr•)ú>ú<z>=z<=z==z!=Úinznot in)rnrorqrr)ú+ú-Ú*ú/ú**ú//ú%)rržrŸr6r7c    Cs`t |¡}|D]L}|j|krqz|j |¡}Wn tk
rN| |j¡}YnX| |¡qdS)a$
    Cast an expression inplace.
 
    Parameters
    ----------
    terms : Op
        The expression that should cast.
    acceptable_dtypes : list of acceptable numpy.dtype
        Will not cast if term's dtype in this list.
    dtype : str or numpy.dtype
        The dtype to cast to.
    N)r^rWrNrFZastyperXrP)ZtermsÚacceptable_dtypesrWÚdtrrTr2r2r3Ú _cast_inplaceMs
 
r¢r4cCs
t|tƒSr$)r%r#)Úobjr2r2r3Úis_termfsr¤csTeZdZdZdddœ‡fdd„ Zdd„Zdd    œd
d „Zdd œd d„Zdd„Z‡Z    S)ÚBinOpzˆ
    Hold a binary operator and its operands.
 
    Parameters
    ----------
    op : str
    lhs : Term or Op
    rhs : Term or Op
    r&r6©rtr8c
sŠtƒ |||f¡||_||_| ¡| ¡zt||_WnHtk
r„}z*t    t 
¡ƒ}t dt |ƒ›d|›ƒ|‚W5d}~XYnXdS)NzInvalid binary operator ú, valid operators are ) r(r?ÚlhsÚrhsÚ_disallow_scalar_only_bool_opsÚconvert_valuesÚ_binary_ops_dictÚfuncÚKeyErrorÚlistÚkeysÚ
ValueErrorr[)r>rtr¨r©Úerrr°r0r2r3r?us ÿþzBinOp.__init__cCs | |¡}| |¡}| ||¡S)zã
        Recursively evaluate an expression in Python space.
 
        Parameters
        ----------
        env : Scope
 
        Returns
        -------
        object
            The result of an evaluated expression.
        )r¨r©r­)r>r,ÚleftÚrightr2r2r3rJ‡s
 
zBinOp.__call__)Úenginec CsŒ|dkr||ƒ}nd|jj|||||d}|jj|||||d}|j|krZ| |j|j¡}nddlm}    |    ||||d}| |¡}
||
|dS)al
        Evaluate a binary operation *before* being passed to the engine.
 
        Parameters
        ----------
        env : Scope
        engine : str
        parser : str
        term_type : type
        eval_in_python : list
 
        Returns
        -------
        term_type
            The "pre-evaluated" expression as an instance of ``term_type``
        Úpython)rµÚparserÚ    term_typeÚeval_in_pythonr)Úeval)Z
local_dictrµr·©r,)    r¨rKr©rtr­rFZpandas.core.computation.evalrºZadd_tmp) r>r,rµr·r¸r¹rSr³r´rºr+r2r2r3rKšs,
ûû    
 
zBinOp.evaluater7csæ‡fdd„}ˆjˆj}}t|ƒr~|jr~t|ƒr~|jr~|j}t|ttfƒrR||ƒ}t    t
|ƒƒ}|j dk    rr|  d¡}ˆj  |¡t|ƒrâ|jrât|ƒrâ|jrâ|j}t|ttfƒr¶||ƒ}t    t
|ƒƒ}|j dk    rÖ|  d¡}ˆj  |¡dS)zK
        Convert datetimes to a comparable value in an expression.
        cs&ˆjdk    rttˆjd}nt}||ƒS)N)r.)r.rrr)rFÚencoderrBr2r3Ú    stringifyÐs
z'BinOp.convert_values.<locals>.stringifyNÚUTC)r¨r©r¤rbr rFr%reÚfloatr    r ÚtzZ
tz_convertrP)r>r½r¨r©Úvr2rBr3r«Ës$  
 
 
 
zBinOp.convert_valuescCsr|j}|j}|j}t|d|ƒ}|j}t|d|ƒ}|js<|jrn|jtkrnt|tt    j
fƒrft|tt    j
fƒsnt dƒ‚dS)NrNz$cannot evaluate scalar only bool ops) r©r¨rjÚgetattrr rtÚ_bool_ops_dictr]r4r^r„rR)r>r©r¨Zrhs_rtZlhs_rtr2r2r3rªìs"  ÿÿþûú
z$BinOp._disallow_scalar_only_bool_ops)
rZrfrgrŽr?rJrKr«rªrlr2r2r0r3r¥js 
1!r¥cCstt |¡jtjƒSr$)r]r^rWrNÚnumber)rWr2r2r3Ú    isnumericsrÅcs&eZdZdZddœ‡fdd„ Z‡ZS)ÚDivzš
    Div operator to special case casting.
 
    Parameters
    ----------
    lhs, rhs : Term or Op
        The Terms or Ops in the ``/`` expression.
    r6r7csjtƒ d||¡t|jƒr$t|jƒsFtd|j›d|j›d|j›dƒ‚tjtjg}t    t
  |¡|tjƒdS)Nrœz unsupported operand type(s) for z: 'z' and 'ú') r(r?rÅrjÚ    TypeErrorrtr^Úfloat32Zfloat_r¢r…r†)r>r¨r©r r0r2r3r?sÿ z Div.__init__)rZrfrgrŽr?rlr2r2r0r3rÆs    rÆ)r™ršrmrpcsVeZdZdZdddœ‡fdd„ Zddœd    d
„Zd dœd d „Zeddœdd„ƒZ‡Z    S)ÚUnaryOpaK
    Hold a unary operator and its operands.
 
    Parameters
    ----------
    op : str
        The token used to represent the operator.
    operand : Term or Op
        The Term or Op operand to the operator.
 
    Raises
    ------
    ValueError
        * If no function associated with the passed operator token is found.
    zLiteral[('+', '-', '~', 'not')]r6r¦c
sftƒ ||f¡||_zt||_Wn<tk
r`}ztdt|ƒ›dt›ƒ|‚W5d}~XYnXdS)NzInvalid unary operator r§)    r(r?rŒÚ_unary_ops_dictr­r®r±r[ÚUNARY_OPS_SYMS)r>rtrŒr²r0r2r3r?4sÿýzUnaryOp.__init__ÚMathCallr7cCs| |¡}| |¡Sr$)rŒr­)r>r,rŒr2r2r3rJ@s
zUnaryOp.__call__r&cCst|j›d|j›dƒS)NrzrY)rrtrŒrBr2r2r3rDEszUnaryOp.__repr__znp.dtypecCsR|j}|jt d¡kr t d¡St|tƒrH|jtks>|jtkrHt d¡St d¡S)Nr4re)    rŒrjr^rWr%rsrtÚ _cmp_ops_dictrÃ)r>rŒr2r2r3rjHs
 
ÿÿ
zUnaryOp.return_type)
rZrfrgrŽr?rJrDrirjrlr2r2r0r3rÊ#s  rÊcs8eZdZddœ‡fdd„ Zdd„Zddœdd    „Z‡ZS)
rÍr6r7cstƒ |j|¡||_dSr$)r(r?r+r­)r>r­rHr0r2r3r?UszMathCall.__init__c
sD‡fdd„|jDƒ}tjdd|jj|ŽW5QR£SQRXdS)Ncsg|] }|ˆƒ‘qSr2r2)r{rtr»r2r3Ú
<listcomp>[sz%MathCall.__call__.<locals>.<listcomp>Úignore)r)rur^Zerrstater­)r>r,rur2r»r3rJYszMathCall.__call__r&cCs(tt|jƒ}t|j›dd |¡›dƒS)Nrzú,rY)Úmapr&rurrtr~)r>rur2r2r3rD_s zMathCall.__repr__)rZrfrgr?rJrDrlr2r2r0r3rÍTsrÍc@s$eZdZdddœdd„Zdd„ZdS)    ÚFuncNoder&r6)r+r8cCs.|tkrtd|›dƒ‚||_tt|ƒ|_dS)Nú"z" is not a supported function)ÚMATHOPSr±r+rÂr^r­)r>r+r2r2r3r?eszFuncNode.__init__cGs
t||ƒSr$)rÍ)r>rHr2r2r3rJkszFuncNode.__call__N)rZrfrgr?rJr2r2r2r3rÓdsrÓ)XrŽÚ
__future__rrÚ    functoolsrÚoperatorÚtypingrrrrÚnumpyr^Zpandas._libs.tslibsr    Zpandas.core.dtypes.commonr
r Zpandas.core.commonÚcoreÚcommonr…Zpandas.core.computation.commonr r Zpandas.core.computation.scoperZpandas.io.formats.printingrrZ
REDUCTIONSZ_unary_math_opsZ_binary_math_opsrÕr;r#r'rvrsr”r•r‚ÚgtÚltÚgeÚleÚeqÚneZ_cmp_ops_funcsÚdictÚziprÎrƒÚand_Úor_Z_bool_ops_funcsrÃZARITH_OPS_SYMSÚaddÚsubÚmulÚtruedivÚpowÚfloordivÚmodZ_arith_ops_funcsZ_arith_ops_dictZSPECIAL_CASE_ARITH_OPS_SYMSZ_special_case_arith_ops_funcsZ_special_case_arith_ops_dictr¬ÚdrPr¢r¤r¥rÅrÆrÌÚposÚnegÚinvertZ_unary_ops_funcsrËrÊrÍrÓr2r2r2r3Ú<module>s†     t 6ø
ù    ÿ1