
    OwgO                    &   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rd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d3d4dZd5d6dZd Zd7dZ d Z!i ejD                  dejF                  dejH                  dejJ                  dejL                  dejN                  dejP                  dejR                  dejT                  dejV                  dejX                  dejZ                  dej\                  dej^                  dej`                  dej$                  d ejb                  d!ejd                  d"ejf                  d#ejh                  d$ejj                  d%ejl                  d%ejn                  d&ejp                  d&ejr                  d'ejt                  d'e;dejx                  diZ=d( Z>d) Z? e e
d*             d+ Z@d&d%d'd,ZAd7d-ZBd3d8d.ZCd3d8d/ZDd3d4d0ZEd9d1ZFd:d2ZGy);zL
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 c                ^    t         r| at        rt        nt        at        rt
        ay t        ay N)r   USE_NUMEXPR_evaluate_numexpr_evaluate_standardr   _where_numexpr_where_standardr   vs    Z/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/core/computation/expressions.pyset_use_numexprr    -   s$     
 &1!6HI*^FF    c                v    t         r3t        r,| t        j                         } t        j                  |        y y y r   )r   r   nedetect_number_of_coresset_num_threads)ns    r   set_numexpr_threadsr'   :   s2     [9))+A
1 )r!   c                6    t         rt        d        | ||      S )z
    Standard evaluation.
    F)r
   _store_test_result)opop_strabs       r   r   r   C   s     5!a8Or!   c                    |e|j                   t        kD  rRt               }||fD ])  }t        |d      s||j                  j
                  hz  }+ t        |      rt        |   |k\  ryy)z,return a boolean if we WILL be using numexprdtypeTF)size_MIN_ELEMENTSsethasattrr/   namelen_ALLOWED_DTYPES)r*   r+   r,   r-   dtype_checkdtypesos          r   _can_use_numexprr:   L   sg    66M!"uFV -1g&qww||n,F- v;/+">&"Hr!   c                r   d }t        | |||d      rZ| j                  j                  d      j                  d      }|r||}}|}|}	 t	        j
                  d| d||dd      }|r||}}t        rt        |d u       |t        | |||      }|S # t        $ r Y 6t        $ r t        |||      rn Y Ow xY w)	Nr   _rza_value z b_value)a_valueb_valuesafe
local_dictcasting)r:   __name__strip
startswithr#   r   	TypeErrorNotImplementedError_bool_arith_fallbackr
   r)   r   )r*   r+   r,   r-   resultis_reversedr>   r?   s           r   r   r   _   s    FFAq*5kk'',77<aqA	[[6((+'.7CF aqA6-.~#B15M)  	 " 	#FAq1 	s   B 	B6B65B6+*-/z**z==z!=z<=<z>=>&|^c                0    t        j                  | ||      S r   )npr   )condr,   r-   s      r   r   r      s    88D!Qr!   c                ~    d }t        d d||d      rt        j                  d| ||dd      }|t        | ||      }|S )Nr   z#where(cond_value, a_value, b_value))
cond_valuer>   r?   r@   rA   )r:   r#   r   r   )rW   r,   r-   rJ   s       r   r   r      sO    Fgq!W51&*qQG
 ~ q!,Mr!   zcompute.use_numexprc                    	 | j                   t        k(  S # t        $ r# t        | t        t        j
                  f      cY S w xY wr   )r/   r   AttributeError
isinstancerV   bool_)xs    r   _has_bool_dtyper_      s:    /ww$ /!dBHH-../s    )A A)rL   rM   rN   c           	         t        |      rSt        |      rH| t        v r@t        j                  dt	        |        dt	        t        |           dt                      yy)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)r_   _BOOL_OP_UNSUPPORTEDwarningswarnreprr   )r+   r,   r-   s      r   rI   rI      sb     qoa0))MM9$v, H089:)E ,-	 r!   c                T    t         |    }||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.
    )_op_str_mappingr   r   )r*   r,   r-   use_numexprr+   s        r   r   r      s9     R FRA..b&!Q//r!   c                J    t         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.
    )r   r   )rW   r,   r-   rh   s       r   r   r      s/     !,6$1M/$12MMr!   c                    | a g ay)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   s    r   set_test_moderk     s     JLr!   c                4    | rt         j                  |        y y r   )r   append)used_numexprs    r   r)   r)     s    L) r!   c                     t         } g a | S )z1
    Get test result and reset test_results.
    )r   )ress    r   get_test_resultrq     s    
 CLJr!   )T)r   r   returnNoner   )rr   rs   )rr   r   )rh   r   )rn   r   rr   rs   )rr   r   )H__doc__
__future__r   operatortypingr   rc   numpyrV   pandas._configr   pandas.util._exceptionsr   pandas.corer   pandas.core.computation.checkr   numexprr#   pandas._typingr	   r
   __annotations__r   r   r   r   r6   r1   r    r'   r   r:   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rdivmodrg   r   r   r_   rb   rI   r   r   rk   r)   rq    r!   r   <module>r      sd   #      % 4 ! ;'
K j !	? !  A) 
@&&R!LL#!NNC! LL#! NNC	!
 LL#! NNC! c! ! t! ! LL$!  NND!!" LL$#!$ NND%!& KK'!( KK)!* KK+!, KKKKKKMM3OOSLL#NNCLL#NNC
DtA!H 
$ 
01 2/ !s5 $0(N 	*
r!   