o
    ŀgO                     @  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   W/var/www/html/myenv/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    	
	)
$

