o
    ôT·jO  ã                   @  sD  U d Z ddlmZ ddlZddlmZ ddlZddlZddl	m
Z
 ddlmZ ddlmZ ddlmZ er9ddlZerAdd	lmZ dad
ed< g aded< eadaded< daded< h d£h d£dœZdZdHdIdd„ZdJdKdd„Zdd„ ZdLd d!„Z d"d#„ Z!i ej"d$“ej#d$“ej$d%“ej%d%“ej&d&“ej'd&“ej(d'“ej)d'“ej*d“ej+d“ej,d“ej-d“ej.d(“ej/d(“ej0d)“ejd*“ej1d+“ej2d,ej3d-ej4d.ej5d/ej6d/ej7d0ej8d0ej9d1ej:d1e;dej<di¥Z=d2d3„ Z>d4d5„ Z?ee
d6ƒƒ d7d8„ Z@d0d/d1d9œZAdLd:d;„ZBdHdMd=d>„ZCdHdMd?d@„ZDdHdIdAdB„ZEdNdDdE„ZFdOdFdG„ZGdS )PzL
Expressions
-----------

Offer fast expression evaluation through numexpr

é    )ÚannotationsN)ÚTYPE_CHECKING)Ú
get_option)Úfind_stack_level)Ú	roperator)ÚNUMEXPR_INSTALLED)ÚFuncTypezbool | NoneÚ
_TEST_MODEú
list[bool]Ú_TEST_RESULTzFuncType | NoneÚ	_evaluateÚ_where>   ÚboolÚint32Úint64Úfloat32Úfloat64>   r   r   r   )ÚevaluateÚwherei@B TÚvr   ÚreturnÚNonec                 C  s(   t r| atrtntatrtad S tad S ©N)r   ÚUSE_NUMEXPRÚ_evaluate_numexprÚ_evaluate_standardr   Ú_where_numexprÚ_where_standardr   ©r   © r   úf/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/pandas/core/computation/expressions.pyÚset_use_numexpr-   s   r!   c                 C  s.   t rtr| d u rt ¡ } t | ¡ d S d S d S r   )r   r   ÚneÚdetect_number_of_coresÚset_num_threads)Únr   r   r    Úset_numexpr_threads:   s
   ýr&   c                 C  s   t rtdƒ | ||ƒS )z
    Standard evaluation.
    F)r	   Ú_store_test_result)ÚopÚop_strÚaÚbr   r   r    r   C   s   
r   c                 C  sZ   |dur+|j tkr+tƒ }||fD ]}t|dƒr||jjhO }qt|ƒr)t| |kr+dS dS )z,return a boolean if we WILL be using numexprNÚdtypeTF)ÚsizeÚ_MIN_ELEMENTSÚsetÚhasattrr,   ÚnameÚlenÚ_ALLOWED_DTYPES)r(   r)   r*   r+   Údtype_checkÚdtypesÚor   r   r    Ú_can_use_numexprL   s   

€r7   c                 C  sÊ   d }t | |||dƒrP| j d¡ d¡}|r||}}|}|}ztjd|› d�||dœdd�}W n ty8   Y n tyH   t|||ƒrEn‚ Y nw |rP||}}t	rXt
|d uƒ |d u rct| |||ƒ}|S )	Nr   Ú_Úrza_value z b_value)Úa_valueÚb_valueÚsafe©Ú
local_dictÚcasting)r7   Ú__name__ÚstripÚ
startswithr"   r   Ú	TypeErrorÚNotImplementedErrorÚ_bool_arith_fallbackr	   r'   r   )r(   r)   r*   r+   ÚresultÚis_reversedr:   r;   r   r   r    r   _   s8   


ýþþ
r   ú+Ú*ú-ú/z**z==z!=z<=ú<z>=ú>ú&ú|ú^c                 C  s   t  | ||¡S r   )Únpr   )Úcondr*   r+   r   r   r    r   ¬   s   r   c                 C  sD   d }t d d||dƒrtjd| ||dœdd�}|d u r t| ||ƒ}|S )Nr   z#where(cond_value, a_value, b_value))Ú
cond_valuer:   r;   r<   r=   )r7   r"   r   r   )rR   r*   r+   rF   r   r   r    r   ±   s   
ýr   zcompute.use_numexprc                 C  s0   z| j tkW S  ty   t| ttjfƒ Y S w r   )r,   r   ÚAttributeErrorÚ
isinstancerQ   Úbool_)Úxr   r   r    Ú_has_bool_dtypeÆ   s
   ÿrX   )rH   rI   rJ   c                 C  sJ   t |ƒr#t |ƒr#| tv r#tjdt| ƒ› dtt|  ƒ› d�tƒ d� dS dS )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)rX   Ú_BOOL_OP_UNSUPPORTEDÚwarningsÚwarnÚreprr   )r)   r*   r+   r   r   r    rE   Ð   s   
þürE   Úuse_numexprc                 C  s0   t |  }|dur|rt| |||ƒS t| |||ƒ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+   r^   r)   r   r   r    r   â   s
   r   c                 C  s(   t dusJ ‚|rt | ||ƒS t| ||ƒ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   r   )rR   r*   r+   r^   r   r   r    r   ö   s   r   c                 C  s   | a g adS )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)r	   r   r   r   r   r    Úset_test_mode  s   r`   Úused_numexprc                 C  s   | r	t  | ¡ d S d S r   )r   Úappend)ra   r   r   r    r'     s   ÿr'   c                  C  s   t } g a | S )z1
    Get test result and reset test_results.
    )r   )Úresr   r   r    Úget_test_result  s   rd   )T)r   r   r   r   r   )r   r   )r   r   )r^   r   )ra   r   r   r   )r   r
   )HÚ__doc__Ú
__future__r   ÚoperatorÚtypingr   r[   ÚnumpyrQ   Úpandas._configr   Úpandas.util._exceptionsr   Úpandas.corer   Úpandas.core.computation.checkr   Únumexprr"   Úpandas._typingr   r	   Ú__annotations__r   r   r   r   r3   r.   r!   r&   r   r7   r   ÚaddÚraddÚmulÚrmulÚsubÚrsubÚtruedivÚrtruedivÚfloordivÚ	rfloordivÚmodÚrmodÚpowÚrpowÚeqÚleÚltÚgeÚgtÚand_Úrand_Úor_Úror_ÚxorÚrxorÚdivmodÚrdivmodr_   r   r   rX   rZ   rE   r   r   r`   r'   rd   r   r   r   r    Ú<module>   s¬    þ	
	)ÿþýüûúùø
öõñðïîíìëà$

