a
    DBìjO  ã                8   @  sH  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rrddlZer‚d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dHdddœdd„ZdIddœdd„Zdd„ Zddœd d!„Z d"d#„ Z!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œZAddœd:d;„ZBdJdd<œd=d>„ZCdKdd<œd?d@„ZDdLdddœdAdB„ZEdddCœdDdE„ZFddœdFdG„ZGdS )MzL
Expressions
-----------

Offer fast expression evaluation through numexpr

é    )ÚannotationsN)ÚTYPE_CHECKING)Ú
get_option)Úfind_stack_level)Ú	roperator)ÚNUMEXPR_INSTALLED)ÚFuncTypezbool | NoneÚ
_TEST_MODEz
list[bool]Ú_TEST_RESULTzFuncType | NoneÚ	_evaluateÚ_where>   Úfloat64Zfloat32Úint64Zint32Úbool>   r   r   r   )ÚevaluateÚwherei@B Tr   ÚNone)ÚvÚreturnc                 C  s$   t r| atrtntatrtntad S ©N)r   ÚUSE_NUMEXPRÚ_evaluate_numexprÚ_evaluate_standardr   Ú_where_numexprÚ_where_standardr   ©r   © r   úb/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pandas/core/computation/expressions.pyÚset_use_numexpr-   s    r   )r   c                 C  s&   t r"tr"| d u rt ¡ } t | ¡ d S r   )r   r   ÚneZdetect_number_of_coresZ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rV|j tkrVtƒ }||fD ]}t|dƒr ||jjhO }q t|ƒrRt| |krVd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&   Zdtype_checkZdtypesÚor   r   r   Ú_can_use_numexprL   s    

r0   c                 C  sÊ   d }t | |||dƒr | j d¡ d¡}|r4|| }}|}|}z"tjd|› d�||dœdd�}W n2 typ   Y n" ty�   t|||ƒrŠn‚ Y n0 |r || }}t	r°t
|d uƒ |d u rÆt| |||ƒ}|S )	Nr   Ú_Úrza_value z b_value)Úa_valueÚb_valueÚsafe©Z
local_dictZcasting)r0   Ú__name__ÚstripÚ
startswithr   r   Ú	TypeErrorÚNotImplementedErrorÚ_bool_arith_fallbackr	   r"   r   )r#   r$   r%   r&   ÚresultZis_reversedr3   r4   r   r   r   r   _   s4    

ý

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))Z
cond_valuer3   r4   r5   r6   )r0   r   r   r   )rH   r%   r&   r=   r   r   r   r   ±   s    
ýr   zcompute.use_numexprc                 C  s4   z| j tkW S  ty.   t| ttjfƒ Y S 0 d S r   )r'   r   ÚAttributeErrorÚ
isinstancerG   Zbool_)Úxr   r   r   Ú_has_bool_dtypeÆ   s    rL   )r>   r?   r@   c                 C  sJ   t |ƒrFt |ƒrF| tv rFt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)rL   Ú_BOOL_OP_UNSUPPORTEDÚwarningsÚwarnÚreprr   )r$   r%   r&   r   r   r   r<   Ð   s    
þür<   )Ú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&   rR   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   )rH   r%   r&   rR   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    rT   )Úused_numexprr   c                 C  s   | rt  | ¡ d S r   )r
   Úappend)rU   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    rX   )T)N)T)T)T)HÚ__doc__Ú
__future__r   ÚoperatorÚtypingr   rO   ÚnumpyrG   Zpandas._configr   Zpandas.util._exceptionsr   Zpandas.corer   Zpandas.core.computation.checkr   Znumexprr   Zpandas._typingr   r	   Ú__annotations__r
   r   r   r   r.   r)   r   r!   r   r0   r   ÚaddZraddÚmulZrmulÚsubZrsubÚtruedivZrtruedivÚfloordivZ	rfloordivÚmodZrmodÚpowZrpowÚeqÚleÚltÚgeÚgtÚand_Zrand_Úor_Zror_ÚxorZrxorÚdivmodZrdivmodrS   r   r   rL   rN   r<   r   r   rT   r"   rX   r   r   r   r   Ú<module>   s†   þ		*à$