o
    ôT·jí9  ã                   @  s`  d Z ddlmZ ddlmZ ddlmZ ddlZddlmZm	Z	m
Z
 ddlZddlmZ ddlmZmZ ddlm  mZ dd	lmZmZ dd
lmZ ddlmZmZ er]ddlmZm Z  dZ!dZ"dZ#e"e# Z$dZ%G dd„ dƒZ&G dd„ de&ƒZ'ddddœZ(G dd„ dƒZ)dd„ Z*dd„ Z+dZ,ej-ej.ej/ej0ej1ej2e*e+fZ3e4e5e,e3ƒƒZ6d Z7ej8ej9ej8ej9fZ:e4e5e7e:ƒƒZ;d!Z<ej=ej>ej?ej@ejAejBejCfZDe4e5e<eDƒƒZEd"ZFejAejBejCfZGe4e5eFeGƒƒZHi ZIe6e;eEfD ]ZJeI KeJ¡ qêd2d%d&„ZLG d'd(„ d(e)ƒZMd2d)d*„ZNd+ZOejPejQejRejRfZSe4e5eOeSƒƒZTG d,d-„ d-e)ƒZUG d.d/„ d/e)ƒZVG d0d1„ d1ƒZWdS )3z
Operator classes for eval.
é    )Úannotations)Údatetime)ÚpartialN)ÚTYPE_CHECKINGÚCallableÚLiteral)Ú	Timestamp)Úis_list_likeÚ	is_scalar)Úensure_decodedÚresult_type_many)ÚDEFAULT_GLOBALS)Úpprint_thingÚpprint_thing_encoded)ÚIterableÚIterator)ÚsumÚprodÚminÚmax)ÚsinÚcosÚexpÚlogÚexpm1Úlog1pÚsqrtÚsinhÚcoshÚtanhÚarcsinÚarccosÚarctanÚarccoshÚarcsinhÚarctanhÚabsÚlog10ÚfloorÚceil)Úarctan2Ú__pd_eval_local_c                      sà   e Zd ZU d'‡ fdd„	Zded< d'd(dd	„Zed)dd„ƒZd)dd„Zdd„ Z	d*dd„Z
dd„ Zd(dd„Zed+dd„ƒZedd„ ƒZeZed)dd„ƒZed+dd„ƒZedd „ ƒZejd(d!d „ƒZed"d#„ ƒZed,d%d&„ƒZ‡  ZS )-ÚTermNc                   s&   t |tƒstn| }tt|ƒj}||ƒS ©N)Ú
isinstanceÚstrÚConstantÚsuperr,   Ú__new__)ÚclsÚnameÚenvÚsideÚencodingÚklassÚsupr_new©Ú	__class__© ú^/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/pandas/core/computation/ops.pyr2   L   s   zTerm.__new__ÚboolÚis_localÚreturnÚNonec                 C  sB   || _ || _|| _t|ƒ}| t¡p|tv | _|  ¡ | _	|| _
d S r-   )Ú_namer5   r6   r/   Ú
startswithÚ	LOCAL_TAGr   r?   Ú_resolve_nameÚ_valuer7   )Úselfr4   r5   r6   r7   Útnamer<   r<   r=   Ú__init__T   s   

zTerm.__init__r/   c                 C  s   | j  td¡S )NÚ )r4   ÚreplacerD   ©rG   r<   r<   r=   Ú
local_name^   s   zTerm.local_namec                 C  ó
   t | jƒS r-   )r   r4   rL   r<   r<   r=   Ú__repr__b   ó   
zTerm.__repr__c                 O  ó   | j S r-   ©Úvalue©rG   ÚargsÚkwargsr<   r<   r=   Ú__call__e   ó   zTerm.__call__c                 O  s   | S r-   r<   rT   r<   r<   r=   Úevaluateh   s   zTerm.evaluatec                 C  sl   t | jƒ}| j}|| jjv rt| jj| tƒrd}| jj||d�}|  |¡ t	|dƒr4|j
dkr4tdƒ‚|S )NF)r?   Úndimé   z?N-dimensional objects, where N > 2, are not supported with eval)r/   rM   r?   r5   Úscoper.   ÚtypeÚresolveÚupdateÚhasattrrZ   ÚNotImplementedError)rG   rM   r?   Úresr<   r<   r=   rE   k   s   
ÿ
ÿzTerm._resolve_namec                 C  s.   | j }t|tƒr| jj| j||d� || _dS )zâ
        search order for local (i.e., @variable) variables:

        scope, key_variable
        [('locals', 'local_name'),
         ('globals', 'local_name'),
         ('locals', 'key'),
         ('globals', 'key')]
        )Ú	new_valueN)r4   r.   r/   r5   ÚswapkeyrM   rS   )rG   rS   Úkeyr<   r<   r=   r_   |   s   


zTerm.updatec                 C  rN   r-   )r
   rF   rL   r<   r<   r=   r
   Ž   ó   
zTerm.is_scalarc                 C  sL   z| j jjW S  ty%   z| j jW  Y S  ty$   t| j ƒ Y  Y S w w r-   )rF   ÚvaluesÚdtypeÚAttributeErrorr]   rL   r<   r<   r=   r]   ’   s   þüz	Term.typec                 C  s$   t | ƒj› dt| jƒ› d| j › d�S )Nz(name=z, type=ú))r]   Ú__name__Úreprr4   rL   r<   r<   r=   Úraw¡   s   $zTerm.rawc                 C  s6   z| j j }W n ty   | j }Y nw t|ttjfƒS r-   )r]   ri   Ú
issubclassr   ÚnpÚ
datetime64©rG   Útr<   r<   r=   Úis_datetime¥   ó   
ÿzTerm.is_datetimec                 C  rQ   r-   ©rF   rL   r<   r<   r=   rS   ®   ó   z
Term.valuec                 C  s
   || _ d S r-   ru   )rG   rc   r<   r<   r=   rS   ²   rf   c                 C  rQ   r-   ©rB   rL   r<   r<   r=   r4   ¶   rv   z	Term.nameÚintc                 C  s   | j jS r-   )rF   rZ   rL   r<   r<   r=   rZ   º   s   z	Term.ndim)NN©r@   rA   ©r@   r/   )r@   r,   ©r@   r>   )r@   rx   )rk   Ú
__module__Ú__qualname__r2   Ú__annotations__rI   ÚpropertyrM   rO   rW   rY   rE   r_   r
   r]   Úreturn_typerm   rs   rS   Úsetterr4   rZ   Ú__classcell__r<   r<   r:   r=   r,   K   s8   
 






r,   c                   @  s*   e Zd Zdd„ Zedd„ ƒZd
dd„Zd	S )r0   c                 C  rQ   r-   rw   rL   r<   r<   r=   rE   À   rX   zConstant._resolve_namec                 C  rQ   r-   rR   rL   r<   r<   r=   r4   Ã   rv   zConstant.namer@   r/   c                 C  rN   r-   )rl   r4   rL   r<   r<   r=   rO   Ç   s   
zConstant.__repr__Nrz   )rk   r|   r}   rE   r   r4   rO   r<   r<   r<   r=   r0   ¿   s
    
r0   ú~ú&ú|)ÚnotÚandÚorc                   @  s|   e Zd ZU dZded< ddd	d
„Zddd„Zddd„Zedd„ ƒZ	eddd„ƒZ
edd„ ƒZeddd„ƒZeddd„ƒZdS ) ÚOpz.
    Hold an operator of arbitrary arity.
    r/   ÚopNÚoperandsúIterable[Term | Op]r@   rA   c                 C  s   t  ||¡| _|| _|| _d S r-   )Ú_bool_op_mapÚgetrŠ   r‹   r7   )rG   rŠ   r‹   r7   r<   r<   r=   rI   ×   s   
zOp.__init__r   c                 C  rN   r-   )Úiterr‹   rL   r<   r<   r=   Ú__iter__Ü   rP   zOp.__iter__c                 C  s(   dd„ | j D ƒ}td| j› d� |¡ƒS )zW
        Print a generic n-ary operator and its operands using infix notation.
        c                 s  s    � | ]}d t |ƒ› d�V  qdS )ú(rj   N)r   )Ú.0Úoprr<   r<   r=   Ú	<genexpr>ä   s   € zOp.__repr__.<locals>.<genexpr>ú )r‹   r   rŠ   Újoin)rG   Úparenedr<   r<   r=   rO   ß   s   zOp.__repr__c                 C  s,   | j tt v r
tjS tdd„ t | ¡D ƒŽ S )Nc                 s  ó   � | ]}|j V  qd S r-   ©r]   ©r’   Útermr<   r<   r=   r”   ì   ó   € z!Op.return_type.<locals>.<genexpr>)rŠ   ÚCMP_OPS_SYMSÚBOOL_OPS_SYMSro   Úbool_r   ÚcomÚflattenrL   r<   r<   r=   r€   ç   s   zOp.return_typer>   c                 C  s(   | j }tt d¡gƒ}| jtko|| S )NÚobject)Úoperand_typesÚ	frozensetro   rh   r€   r¢   )rG   ÚtypesÚobj_dtype_setr<   r<   r=   Úhas_invalid_return_typeî   s   zOp.has_invalid_return_typec                 C  s   t dd„ t | ¡D ƒƒS )Nc                 s  r˜   r-   r™   rš   r<   r<   r=   r”   ö   rœ   z#Op.operand_types.<locals>.<genexpr>)r¤   r    r¡   rL   r<   r<   r=   r£   ô   s   zOp.operand_typesc                 C  s   t dd„ | jD ƒƒS )Nc                 s  r˜   r-   )r
   )r’   Úoperandr<   r<   r=   r”   ú   rœ   zOp.is_scalar.<locals>.<genexpr>)Úallr‹   rL   r<   r<   r=   r
   ø   s   zOp.is_scalarc                 C  s6   z| j j}W n ty   | j }Y nw t|ttjfƒS r-   )r€   r]   ri   rn   r   ro   rp   rq   r<   r<   r=   rs   ü   rt   zOp.is_datetimer-   )rŠ   r/   r‹   rŒ   r@   rA   )r@   r   rz   r{   )rk   r|   r}   Ú__doc__r~   rI   r�   rO   r   r€   r§   r£   r
   rs   r<   r<   r<   r=   r‰   Ð   s    
 



r‰   c                 C  sT   z|   |¡W S  ty)   t| ƒr#z|  | ¡W  Y S  ty"   Y nw | |v  Y S w )z`
    Compute the vectorized membership of ``x in y`` if possible, otherwise
    use Python.
    ©Úisinri   r	   ©ÚxÚyr<   r<   r=   Ú_in  s   ÿúr°   c                 C  sX   z|   |¡ W S  ty+   t| ƒr%z	|  | ¡ W  Y S  ty$   Y nw | |v Y S w )zd
    Compute the vectorized membership of ``x not in y`` if possible,
    otherwise use Python.
    r«   r­   r<   r<   r=   Ú_not_in  s   ÿúr±   )ú>ú<z>=z<=z==z!=Úinznot in)r„   r…   r‡   rˆ   )ú+ú-Ú*ú/ú**ú//ú%)r¹   rº   r»   r@   r>   c                 C  s
   t | tƒS r-   )r.   r,   )Úobjr<   r<   r=   Úis_termO  rP   r½   c                      sF   e Zd ZdZd‡ fdd„Zdd	„ Zddd„Zddd„Zdd„ Z‡  Z	S )ÚBinOpzˆ
    Hold a binary operator and its operands.

    Parameters
    ----------
    op : str
    lhs : Term or Op
    rhs : Term or Op
    rŠ   r/   r@   rA   c              
     s~   t ƒ  |||f¡ || _|| _|  ¡  |  ¡  zt| | _W d S  ty> } zt	t 
¡ ƒ}tdt|ƒ› d|› �ƒ|‚d }~ww )NzInvalid binary operator ú, valid operators are )r1   rI   ÚlhsÚrhsÚ_disallow_scalar_only_bool_opsÚconvert_valuesÚ_binary_ops_dictÚfuncÚKeyErrorÚlistÚkeysÚ
ValueErrorrl   )rG   rŠ   rÀ   rÁ   ÚerrrÈ   r:   r<   r=   rI   ^  s    ÿþ€ýzBinOp.__init__c                 C  s    |   |¡}|  |¡}|  ||¡S )zã
        Recursively evaluate an expression in Python space.

        Parameters
        ----------
        env : Scope

        Returns
        -------
        object
            The result of an evaluated expression.
        )rÀ   rÁ   rÅ   )rG   r5   ÚleftÚrightr<   r<   r=   rW   p  s   

zBinOp.__call__Úenginec                 C  sŒ   |dkr	| |ƒ}n2| j j|||||d�}| jj|||||d�}| j|v r-|  |j|j¡}nddlm}	 |	| |||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)Ú
local_dictrÍ   rÏ   ©r5   )	rÀ   rY   rÁ   rŠ   rÅ   rS   Úpandas.core.computation.evalrÒ   Úadd_tmp)rG   r5   rÍ   rÏ   rÐ   rÑ   rb   rË   rÌ   rÒ   r4   r<   r<   r=   rY   ƒ  s,   
ûû
	
zBinOp.evaluatec                   sö   ‡ fdd„}ˆ j ˆ j}}t|ƒr?|jr?t|ƒr?|jr?|j}t|ttfƒr)||ƒ}t	t
|ƒƒ}|jdur9| d¡}ˆ j |¡ t|ƒrs|jrut|ƒrw|jry|j}t|ttfƒr[||ƒ}t	t
|ƒƒ}|jdurk| d¡}ˆ j  |¡ dS dS dS dS dS )zK
        Convert datetimes to a comparable value in an expression.
        c                   s,   ˆ j d urttˆ j d�}|| ƒS t}|| ƒS )N)r7   )r7   r   r   r   )rS   ÚencoderrL   r<   r=   Ú	stringify¹  s
   
ÿz'BinOp.convert_values.<locals>.stringifyNÚUTC)rÀ   rÁ   r½   rs   r
   rS   r.   rx   Úfloatr   r   ÚtzÚ
tz_convertr_   )rG   rØ   rÀ   rÁ   Úvr<   rL   r=   rÃ   ´  s&   



ùzBinOp.convert_valuesc                 C  sz   | j }| j}|j}t|d|ƒ}|j}t|d|ƒ}|js|jr9| jtv r7t|tt	j
fƒr3t|tt	j
fƒs;tdƒ‚d S d S d S )Nr]   z$cannot evaluate scalar only bool ops)rÁ   rÀ   r€   Úgetattrr
   rŠ   Ú_bool_ops_dictrn   r>   ro   rŸ   ra   )rG   rÁ   rÀ   Úrhs_rtÚlhs_rtr<   r<   r=   rÂ   Õ  s&   ÿÿ
ýüøþz$BinOp._disallow_scalar_only_bool_ops)rŠ   r/   r@   rA   )rÍ   r/   ry   )
rk   r|   r}   rª   rI   rW   rY   rÃ   rÂ   r‚   r<   r<   r:   r=   r¾   S  s    


1!r¾   c                 C  s   t t | ¡jtjƒS r-   )rn   ro   rh   r]   Únumber)rh   r<   r<   r=   Ú	isnumericë  s   rã   )rµ   r¶   rƒ   r†   c                      sD   e Zd ZdZd‡ fdd„Zdd	d
„Zddd„Zeddd„ƒ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.
    rŠ   úLiteral['+', '-', '~', 'not']r@   rA   c              
     sZ   t ƒ  ||f¡ || _zt| | _W d S  ty, } ztdt|ƒ› dt› �ƒ|‚d }~ww )NzInvalid unary operator r¿   )	r1   rI   r¨   Ú_unary_ops_dictrÅ   rÆ   rÉ   rl   ÚUNARY_OPS_SYMS)rG   rŠ   r¨   rÊ   r:   r<   r=   rI     s   ÿÿý€ÿzUnaryOp.__init__ÚMathCallc                 C  s   |   |¡}|  |¡S r-   )r¨   rÅ   )rG   r5   r¨   r<   r<   r=   rW     s   

zUnaryOp.__call__r/   c                 C  s   t | j› d| j› d�ƒS )Nr‘   rj   )r   rŠ   r¨   rL   r<   r<   r=   rO     s   zUnaryOp.__repr__únp.dtypec                 C  sR   | j }|jt d¡krt d¡S t|tƒr$|jtv s|jtv r$t d¡S t d¡S )Nr>   rx   )	r¨   r€   ro   rh   r.   r‰   rŠ   Ú_cmp_ops_dictrß   )rG   r¨   r<   r<   r=   r€     s   



zUnaryOp.return_type)rŠ   rå   r@   rA   ©r@   rè   rz   )r@   ré   )
rk   r|   r}   rª   rI   rW   rO   r   r€   r‚   r<   r<   r:   r=   rä   ô  s    

rä   c                      s0   e Zd Zd
‡ fdd„Zdd„ Zddd	„Z‡  ZS )rè   r@   rA   c                   s   t ƒ  |j|¡ || _d S r-   )r1   rI   r4   rÅ   )rG   rÅ   rU   r:   r<   r=   rI   &  s   
zMathCall.__init__c                   s    ‡ fdd„| j D ƒ}| jj|Ž S )Nc                   s   g | ]}|ˆ ƒ‘qS r<   r<   )r’   rŠ   rÔ   r<   r=   Ú
<listcomp>,  s    z%MathCall.__call__.<locals>.<listcomp>)r‹   rÅ   )rG   r5   r‹   r<   rÔ   r=   rW   *  s   zMathCall.__call__r/   c                 C  s(   t t| jƒ}t| j› dd |¡› d�ƒS )Nr‘   ú,rj   )Úmapr/   r‹   r   rŠ   r–   )rG   r‹   r<   r<   r=   rO   /  s   zMathCall.__repr__ry   rz   )rk   r|   r}   rI   rW   rO   r‚   r<   r<   r:   r=   rè   %  s    rè   c                   @  s    e Zd Zddd„Zddd	„Zd
S )ÚFuncNoder4   r/   r@   rA   c                 C  s.   |t vrtd|› d�ƒ‚|| _tt|ƒ| _d S )Nú"z" is not a supported function)ÚMATHOPSrÉ   r4   rÞ   ro   rÅ   )rG   r4   r<   r<   r=   rI   5  s   zFuncNode.__init__rè   c                 G  s
   t | |ƒS r-   )rè   )rG   rU   r<   r<   r=   rW   ;  rP   zFuncNode.__call__N)r4   r/   r@   rA   rë   )rk   r|   r}   rI   rW   r<   r<   r<   r=   rï   4  s    
rï   r{   )Xrª   Ú
__future__r   r   Ú	functoolsr   ÚoperatorÚtypingr   r   r   Únumpyro   Úpandas._libs.tslibsr   Úpandas.core.dtypes.commonr	   r
   Úpandas.core.commonÚcoreÚcommonr    Úpandas.core.computation.commonr   r   Úpandas.core.computation.scoper   Úpandas.io.formats.printingr   r   Úcollections.abcr   r   Ú
REDUCTIONSÚ_unary_math_opsÚ_binary_math_opsrñ   rD   r,   r0   r�   r‰   r°   r±   r�   ÚgtÚltÚgeÚleÚeqÚneÚ_cmp_ops_funcsÚdictÚziprê   rž   Úand_Úor_Ú_bool_ops_funcsrß   ÚARITH_OPS_SYMSÚaddÚsubÚmulÚtruedivÚpowÚfloordivÚmodÚ_arith_ops_funcsÚ_arith_ops_dictÚSPECIAL_CASE_ARITH_OPS_SYMSÚ_special_case_arith_ops_funcsÚ_special_case_arith_ops_dictrÄ   Údr_   r½   r¾   rã   rç   ÚposÚnegÚinvertÚ_unary_ops_funcsræ   rä   rè   rï   r<   r<   r<   r=   Ú<module>   sˆ    t6ø
ù	ÿ
 
1