
    Pi                     &   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    w/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/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left_opright_ops       r!   r   r   D   s,      "5!!!2gx   r#   c                    |g|j         t          k    rWt                      }||fD ]"}t          |d          r||j        j        hz  }#t          |          rt          |         |k    rdS dS )z2return left_op 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<   M   s~    <-''"uuFx( - -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left_value z right_value)
left_valueright_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FGXzBB 2k'',,77<< 	2 ('XG
	[2f222*4[QQ  FF
  	 	 	 D" 	 	 	#FGX>>  	  	2 ('XG /6-...~#BBB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'8,,,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_valuea_valueb_valuerB   rC   )r<   r%   r   r   )rY   r.   r/   rL   s       r!   r   r      se    Fgw'BB 
1&*w8TT
 
 
 ~ w99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_dtyperc      sK    /w$ / / /!dBH-...../s    +A A )rN   rO   rP   c                    t          |          rNt          |          r?| t          v r6t          j        d| d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)rc   _BOOL_OP_UNSUPPORTEDwarningswarnr   )r-   r.   r/   s      r!   rK   rK      s     w OH$=$= )))MA& A A+F3A A A ,--	    45r#   use_numexprc                l    t           |          }||rt          | |||          S t          | |||          S )a  
    Evaluate and return the expression of the op on left_op and right_op.

    Parameters
    ----------
    op : the actual operand
    left_op : left operand
    right_op : right operand
    use_numexpr : bool, default True
        Whether to try to use numexpr.
    )_op_str_mappingr   r   )r,   r.   r/   ri   r-   s        r!   r   r      sD     R F 	<R(;;;b&'8<<<r#   c                \    t           J |rt          | ||          S t          | ||          S )a  
    Evaluate the where condition cond on left_op and right_op.

    Parameters
    ----------
    cond : np.ndarray[bool]
    left_op : return if cond is True
    right_op : return if cond is False
    use_numexpr : bool, default True
        Whether to try to use numexpr.
    )r   r   )rY   r.   r/   ri   s       r!   r   r      s<      8dGX...tWh777r#   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_modern   
  s     JLLLr#   used_numexprc                B    | rt                               |            d S d S r   )r   append)ro   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_resultrt     s    
 CLJr#   )T)r   r   r   r   r   )r   r   )r   r   )ri   r   )ro   r   r   r   )r   r   )H__doc__
__future__r   operatortypingr   rg   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rdivmodrk   r   r   rc   rf   rK   r   r   rn   r+   rt    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    $= = = = =(8 8 8 8 8&	 	 	 	 	* * * *
     r#   