
    EgO                    &   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d:d;dZd<d=dZd Zd>dZ 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j0        d$ej        d%ej1        d&ej2        d'ej3        d(ej4        d)ej5        d*ej6        d*ej7        d+ej8        d+ej9        d,ej:        d,e;dej<        diZ=d- Z>d. Z? e e
d/                     d0 Z@d+d*d,d1ZAd>d2ZBd:d?d4ZCd:d?d5ZDd:d;d6ZEd@d8ZFdAd9ZGdS )BzL
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                l    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   s    X/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/core/computation/expressions.pyset_use_numexprr"   -   s6      
 &1H!!6HI*?^^FFF    c                |    t           r2t          r-| t          j                    } t          j        |            d S d S d S r   )r   r   nedetect_number_of_coresset_num_threads)ns    r!   set_numexpr_threadsr)   :   sQ      [ 9)++A
1   r#   c                F    t           rt          d            | ||          S )z
    Standard evaluation.
    F)r
   _store_test_result)opop_strabs       r!   r   r   C   s)      "5!!!2a88Or#   c                    |g|j         t          k    rWt                      }||fD ]"}t          |d          r||j        j        hz  }#t          |          rt          |         |k    rdS dS )z,return a boolean if we WILL be using numexprNdtypeTF)size_MIN_ELEMENTSsethasattrr1   namelen_ALLOWED_DTYPES)r,   r-   r.   r/   dtype_checkdtypesos          r!   _can_use_numexprr<   L   s}    6M!!"uuFV - -1g&& -qw|n,F v;; /+">&"H"Ht5r#   c                   d }t          | |||d          r| j                            d                              d          }|r||}}|}|}	 t	          j        d| d||dd          }n.# t          $ r Y n"t          $ r t          |||          rn Y nw xY w|r||}}t          rt          |d u           |t          | |||          }|S )	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@   rA   s           r!   r   r   _   s8   FFAq*55 k'',,77<< 	aqA	[+6+++'.7CC  FF
  	 	 	 D" 	 	 	#FAq11  	  	aqA /6-...~#B155Ms   A- -
B9BB+*-/z**z==z!=z<=<z>=>&|^c                .    t          j        | ||          S r   )npr   )condr.   r/   s      r!   r   r      s    8D!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@   rA   rB   rC   )r<   r%   r   r   )rY   r.   r/   rL   s       r!   r   r      se    Fgq!W55 
1&*qQG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   )r1   r   AttributeError
isinstancerX   bool_)xs    r!   _has_bool_dtypera      sK    /w$ / / /!dBH-...../s    +A A )rN   rO   rP   c           	         t          |          rht          |          rY| t          v rPt          j        dt	          |            dt	          t          |                     dt                                 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)ra   _BOOL_OP_UNSUPPORTEDwarningswarnreprr   )r-   r.   r/   s      r!   rK   rK      s     q oa00 )))ME$v,, E E0899E E E ,--	    45r#   use_numexprc                l    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/   rh   r-   s        r!   r   r      sD     R F 	/RA...b&!Q///r#   c                \    t           J |rt          | ||          n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   )rY   r.   r/   rh   s       r!   r   r      s8     !,M6$1/$12M2MMr#   c                    | 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    s    r!   set_test_moderm     s     JLLLr#   used_numexprc                B    | rt                               |            d S d S r   )r   append)rn   s    r!   r+   r+     s.     *L)))))* *r#   c                     t           } g a | S )z1
    Get test result and reset test_results.
    )r   )ress    r!   get_test_resultrs     s    
 CLJr#   )T)r   r   r   r   r   )r   r   )r   r   )rh   r   )rn   r   r   r   )r   r   )H__doc__
__future__r   operatortypingr   re   numpyrX   pandas._configr   pandas.util._exceptionsr   pandas.corer   pandas.core.computation.checkr   numexprr%   pandas._typingr	   r
   __annotations__r   r   r   r   r8   r3   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rdivmodrj   r   r   ra   rd   rK   r   r   rm   r+   rs    r#   r!   <module>r      s     # " " " " "                   % % % % % % 4 4 4 4 4 4 ! ! ! ! ! ! ; ; ; ; ; ;  (''''''
        !	 ! ! ! !     A@@)))  
@ 
@ 
@ 
@ 
@         && & &R!L#!NC! L#! NC	!
 L#! NC! c! ! t! ! L$!  ND!!" L$#!$ ND%!& K'!( K)!* K+!, KKKM3OSL#NCL#NC
DtA! !H     
  $ 

011 2 2 2/ / / !s55    $0 0 0 0 0(N N N N N 	 	 	 	 	* * * *
     r#   