o
    5c                     @  s.  U d Z ddlmZ ddl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 ddlmZ er9ddl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dGdHddZdIdHddZdd Zd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j.d&ejd'ej/d(ej0d)ej1d*ej2d+ej3d,ej4d,ej5d-ej6d-ej7d.ej8d.e9dej:diZ;d/d0 Z<d1d2 Z=eed3 d4d5 Z>d-d,d.d6Z?d7d8 Z@dGdJd;d<ZAdGd=d>ZBdGdKd@dAZCdLdCdDZDdMdEdFZEdS )NzL
Expressions
-----------

Offer fast expression evaluation through numexpr

    )annotationsN)
get_option)FuncType)find_stack_level)NUMEXPR_INSTALLED)	roperatorzbool | None
_TEST_MODE
list[bool]_TEST_RESULTzFuncType | None	_evaluate_where>   boolint32int64float32float64>   r   r   r   )evaluatewherei@B T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   v r   Y/var/www/html/gps/gps/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_threads7   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   @   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_numexprI   s   

r6   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)r6   __name__strip
startswithr!   r   	TypeErrorNotImplementedError_bool_arith_fallbackr   r&   r   )r'   r(   r)   r*   resultis_reversedr9   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_valuer9   r:   r;   r<   )r6   r!   r   r   )rQ   r)   r*   rE   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
isinstancerP   bool_)xr   r   r   _has_bool_dtype   s
   rW   )rG   rH   rI   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)rW   _BOOL_OP_UNSUPPORTEDwarningswarnreprr   )r(   r)   r*   r   r   r   rD      s   
rD   use_numexprr   c                 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   )rQ   r)   r*   r]   r   r   r   r      s   r   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)r`   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   rc   )T)r   r   r   )r]   r   )r   r   r   r   )r`   r   r   r   )r   r	   )F__doc__
__future__r   operatorrZ   numpyrP   pandas._configr   pandas._typingr   pandas.util._exceptionsr   pandas.core.computation.checkr   pandas.core.opsr   numexprr!   r   __annotations__r
   r   r   r   r2   r-   r    r%   r   r6   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   rW   rY   rD   r   r   r_   r&   rc   r   r   r   r   <module>   s    		)
$

