a
    OfO                  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rd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>   int64Zfloat32boolZint32float64>   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   \/var/www/ai-form-bot/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|||rn Y n0 |r|| }}t	rt
|d u |d u rt| |||}|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   		*$