
    Whv2                        d dl Z d dl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mZmZ d dlmZ  eej                            dd           ed          d	          Z eej                            d
d           ed          d	          Z eed                                         ed                             d          ed                             d          ed                             d          d          Z eed                                         ed                             d          ed                             d          ed                             d          d          Z eej                            dd
d           ed          d	          Z eej                            dd
d           ed          d	          Zed         j                                        Zed         j                                        Z ed         j                                        Z!ed         j                                        Z"ej#        $                    ej%         d           G d d                      Z&dS )    N)option_context)	DataFrameIndexSeries)expressions'     ABCDfloat64)columnsdtyped   ABfloat32Cint64Dint32)r   r   r   r      )r   r	   size)e   r	   znot using numexpr)reasonc                   ,   e Zd Zd Zd Zededefd            Ze	j
                            deeeej                            dd ej        e          	          z  eeeeg          e	j
                            dd
dg          e	j
                            dg d          d                                     Ze	j
                            deeeej                            dd ej        e          	          z  eeeeg          e	j
                            dd
dg          d                         Zd Ze	j
                            dg d          e	j
                            deefeefg          d                         Ze	j
                            dg d          e	j
                            deefeefg          d                         Ze	j
                            dd
dg          e	j
                            deeeeg          d                         Ze	j
                            dg d          d             Z e	j
                            dg d          d             Z!e	j
                            d e"g dg dgg d !           e"ddgddggd"d#g!          f e"g d$g d%g d&gg d !           e"ddgddgddggd"d#g!          fg          d'             Z#e	j
                            dd          e	j
                            d(d)          d*                         Z$e	j
                            d+g d,          e	j
                            d-e"e%e&g          e	j
                            d.d/d0g          d1                                     Z'd2S )3TestExpressionsc                 (    t           j        | _        d S N)expr_MIN_ELEMENTSselfs    c/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/pandas/tests/test_expressions.pysetup_methodzTestExpressions.setup_method2   s    !/    c                 (    | j         t          _         d S r   )r    r   r!   s    r#   teardown_methodzTestExpressions.teardown_method5   s    !/r%   flexopnamec                     |rfd}|_         nt          t                    }t          dd          5   || |          }d d d            n# 1 swxY w Y   t	          j                      || |          }||fS )Nc                 6     t          |           |          S r   )getattr)xyr)   s     r#   <lambda>z)TestExpressions.call_op.<locals>.<lambda>;   s    0ga0033 r%   compute.use_numexprF)__name__r,   operatorr   r   get_test_result)dfotherr(   r)   opexpectedresults      `   r#   call_opzTestExpressions.call_op8   s     	+3333B BKK6**B1599 	% 	%r"e}}H	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	Bxs   AAAr4   r      r   TFarith)addsubmulmodtruedivfloordivc                    dt           _        |                     ||||          \  }}|dk    r%t          d |j        j        D                       sJ t          j        ||           t          t          |j
                            D ]h}|                     |j        d d |f         |j        d d |f         ||          \  }}|dk    r|j        j        dk    sJ t          j        ||           id S )Nr   r@   c              3   ,   K   | ]}|j         d k    V  dS )fN)kind).0r-   s     r#   	<genexpr>z6TestExpressions.test_run_arithmetic.<locals>.<genexpr>^   s(      EEqv}EEEEEEr%   rD   )r   r    r9   alldtypesvaluestmassert_equalrangelenr   ilocr   rE   )r"   r4   r(   r;   r8   r7   is          r#   test_run_arithmeticz#TestExpressions.test_run_arithmeticH   s   $ <<Be<<IEEho.DEEEEEEEE
&)))s2:'' 	. 	.A#||BGAAAqDM27111a4=$PUVVFH	!!~*c1111OHf----		. 	.r%   c                 p   |j         }t          dd          5  |                                dz   }ddd           n# 1 swxY w Y   dt          _        t          j        d           |                     ||||          \  }}t          j                    }|s
J d            t          j	        ||           dS )z
        tests solely that the result is the same whether or not numexpr is
        enabled.  Need to test whether the function does the correct thing
        elsewhere.
        r0   Fr   Nr   Tz Did not use numexpr as expected.)
r1   r   copyr   r    set_test_moder9   r3   rK   rL   )	r"   r4   r(   comparison_opr;   r5   r8   r7   used_numexprs	            r#   test_run_binaryzTestExpressions.test_run_binaryg   s    ( &1599 	" 	"GGIIME	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 4   <<E4??+--?????|
&)))))s   <A A c                 f   t           j                            d          }t           j                            d          }t          j        t
          j        d ||d          }|rJ t          j        t
          j        d||d          }|rJ t          j        t
          j        d||d          }|sJ d S )NiAB r   evaluate+)nprandomrandnr   _can_use_numexprr2   r<   )r"   arrayarray2r8   s       r#   test_invalidzTestExpressions.test_invalid   s    		**%% &x|T5%TTz &x|S&&*UUz &x|S%TTvr%   zopname,op_str))r<   rZ   )r=   -)r>   *)r@   /)pow**z
left,rightc                     fd}t          dd          5   |             d d d            n# 1 swxY w Y   t          j        d            |             t          j                      |             d S )Nc                     dk    rd S t          t                    } t          j                    5  d}t          j        d|t
                     t          j        | d          }t          j        | d          }d d d            n# 1 swxY w Y   t          j	        ||           t          j
        | d          }|rJ d S )Nre   z(invalid value encountered in true_divideignoreTuse_numexprFrY   )r,   r2   warningscatch_warningsfilterwarningsRuntimeWarningr   rY   rK   assert_numpy_array_equalr^   )r6   msgr8   r7   leftop_strr)   rights       r#   testitz/TestExpressions.test_binary_ops.<locals>.testit   s   6**B(** L L@'#~FFFr44HHH=T4UKKKL L L L L L L L L L L L L L L '999*2vueZPPF:s   ABBBr0   Fr   r   r   set_numexpr_threadsr"   r)   rs   rr   rt   ru   s    ```` r#   test_binary_opszTestExpressions.test_binary_ops   s    	 	 	 	 	 	 	 	& 1599 	 	FHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ### """   488))gt>)lt<)gez>=)lez<=)eqz==)nez!=c                     fd}t          dd          5   |             d d d            n# 1 swxY w Y   t          j        d            |             t          j                      |             d S )Nc                     dz   } dz   }t          t                    }t          j        || d          }t          j        || d          }t	          j        ||           t          j        ||d          }|rJ d S )Nr   Trj   FrY   )r,   r2   r   rY   rK   rp   r^   )	f12f22r6   r8   r7   rr   rs   r)   rt   s	        r#   ru   z3TestExpressions.test_comparison_ops.<locals>.testit   s    (C!)C6**B]2tSdCCCF}RsFFFH'999*2vuc:NNF:r%   r0   Fr   rv   rx   s    ```` r#   test_comparison_opsz#TestExpressions.test_comparison_ops   s    	 	 	 	 	 	 	 	 1599 	 	FHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ### """rz   condc                     fd}t          dd          5   |             d d d            n# 1 swxY w Y   t          j        d            |             t          j                      |             d S )Nc                  2   t          j        j        t           j                  } |                                t          j        | j        j        dz             }t          j        | j        j        dz             }t          j	        ||           d S )N)r   r   )
r[   emptyshapebool_fillr   whererJ   rK   rp   )cr8   r7   r   r4   s      r#   ru   z*TestExpressions.test_where.<locals>.testit   sy    222AFF4LLLZ29bi!m<<Fx29bi!m<<H'99999r%   r0   Fr   rv   )r"   r   r4   ru   s    `` r#   
test_wherezTestExpressions.test_where   s    	: 	: 	: 	: 	: 	: 1599 	 	FHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ### """s   044zop_str,opname))rd   r@   )z//rA   )rf   re   c                 *   t          t          j                            d          dk    t          j                            d          dk    d          }d| d}t	          t
          |          }t          j        |          }t          j	        t          |          5   |||           d d d            n# 1 swxY w Y   t          j	        t          |          5   ||j        |j                   d d d            n# 1 swxY w Y   t          j	        t          |          5   ||j        d           d d d            n# 1 swxY w Y   t          j	        t          |          5   |d|j                   d d d            n# 1 swxY w Y   t          j	        t          |          5   |d|           d d d            n# 1 swxY w Y   t          j	        t          |          5   ||d           d d d            d S # 1 swxY w Y   d S )	N
         ?abz
operator 'z!' not implemented for bool dtypes)matchTF)r   r[   r\   randr,   r2   reescapepytestraisesNotImplementedErrorr   r   )r"   rs   r)   r4   rq   rD   err_msgs          r#   !test_bool_ops_raise_on_arithmeticz1TestExpressions.test_bool_ops_raise_on_arithmetic   si    RY^^B//#5BINN2<N<NQT<TUUVVD6DDDHf%%)C..].g>>> 	 	Ab"III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ].g>>> 	 	AbdBDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ].g>>> 	 	AbdDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ].g>>> 	 	AeRTNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ].g>>> 	 	AeRLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ].g>>> 	 	Ab$KKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sl   B88B<?B<DDD'EE	E	+F		FF/GGG.HHH))rZ   r<   )rc   r>   )rb   r=   c                    d}t          t          j                            |          dk    t          j                            |          dk    d          }dddd}dd	d
d}t	          t
          |          }t	          t
          |||                            }|dk    rd S t          j        dd          5  t          j                    5   |||          }	 |||          }
t          j	        |	|
           d d d            n# 1 swxY w Y   t          j                    5   ||j
        |j                  }	 ||j
        |j                  }
t          j        |	|
           d d d            n# 1 swxY w Y   t          j                    5   ||j
        d          }	 ||j
        d          }
t          j        |	|
           d d d            n# 1 swxY w Y   t          j                    5   |d|j
                  }	 |d|j
                  }
t          j        |	|
           d d d            n# 1 swxY w Y   t          j                    5   |d|          }	 |d|          }
t          j	        |	|
           d d d            n# 1 swxY w Y   t          j                    5   ||d          }	 ||d          }
t          j	        |	|
           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   r   r   |&^)rZ   rc   rb   or_and_xor)r   r   r   rb   T   )min_elementsF)r   r[   r\   r   r,   r2   rK   rk   assert_produces_warningassert_frame_equalr   r   assert_series_equal)r"   rs   r)   nr4   subs	sub_funcsrD   feres              r#    test_bool_ops_warn_on_arithmeticz0TestExpressions.test_bool_ops_warn_on_arithmetic  s    RY^^A..429>>!;L;Ls;RSSTTs--f599	Hf%%Xyf677S==F^Dq111 	, 	,+-- , ,Ab"IIBr2JJ%a+++, , , , , , , , , , , , , , ,
 +-- - -AbdBDMMBrtRTNN&q!,,,- - - - - - - - - - - - - - -
 +-- - -AbdDMMBrtTNN&q!,,,- - - - - - - - - - - - - - -
 +-- - -AeRTNNBubdOO&q!,,,- - - - - - - - - - - - - - -
 +-- , ,AeRLLBubMM%a+++, , , , , , , , , , , , , , ,
 +-- , ,Ab$KKBr4LL%a+++, , , , , , , , , , , , , , ,5	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   7K=.D9K=D			K=D		K=#AE1%K=1E5	5K=8E5	9K=8GK=G	K=G	K=18H5)K=5H9	9K=<H9	=K=.JK=J	K=J	K=+.K%K=%K)	)K=,K)	-K==LLztest_input,expected)r   r   r:   aa)r   r   r   r   )r   r   r   )r      r:   r   )r   r	   r:   r   )r   r   r   bbc                     |j         d d ddgf                             |j         d d ddgf                   }t          j        ||           d S )Nr   r   )locr   rK   r   )r"   
test_inputr7   r8   s       r#   test_bool_ops_column_name_dtypez/TestExpressions.test_bool_ops_column_name_dtypeC  sX    . C> 1255jnQQQgEV6WXX
fh/////r%   axis)r   r   c                 L   t           }|dk    r|j        dd d f         }n|j        d d df         }dt          _        t	          ||          }t          dd          5   |||          }d d d            n# 1 swxY w Y    |||          }t          j        ||           d S )Nr   r   r0   F)r   )_framerO   r   r    r,   r   rK   r   )r"   r   r;   r4   r5   op_funcr7   r8   s           r#   test_frame_series_axisz&TestExpressions.test_frame_series_axis]  s     199GAqqqDMEEGAAAqDME"e$$1599 	1 	1wu4000H	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 T***
h/////s   A77A;>A;r6   )__mod____rmod____floordiv____rfloordiv__boxscalarr   c                    dt           _        t          j        dd          } ||          }t	          ||          } ||          }t          dd          5   ||          }d d d            n# 1 swxY w Y   t          j        ||           t          |          D ]g\  }	}
|t          k    r|j
        |	df         }n||	         }	  t	          t          |
          |          |          }||k    sJ X# t          $ r Y dw xY wd S )Nr   i2   r0   F)r   r    r[   aranger,   r   rK   rL   	enumerater   rO   intZeroDivisionError)r"   r6   r   r   dataobjmethodr8   r7   rP   elemscalar_results               r#   ,test_python_semantics_with_numexpr_installedz<TestExpressions.test_python_semantics_with_numexpr_installedt  sv    yb!!c$iib!! 1599 	& 	&vf~~H	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	))) ! 
	1 
	1GAti &AqD 1 &q	1173t99b11&99 %00000 %   
	1 
	1s$   A00A47A4&C77
DDN)(r1   
__module____qualname__r$   r'   staticmethodboolstrr9   r   markparametrize_integer	_integer2r[   r\   randintr   r   _frame2_mixed_mixed2rQ   rW   ra   _array_array2_array_mixed_array_mixed2ry   r   r   r   r   r   r   r   r   r   r    r%   r#   r   r   0   sa       0 0 00 0 0    s       \  [ry((AHBHX4F4F(GGG		
  [VdE]33[DDD . .  43 ". [ry((AHBHX4F4F(GGG		
  [VdE]33* * 43 *2    [SSS  [(<*GH   	 8 [	
 	
 	

 
 [(<*GH   
 
, [VdE]33[TFGVW#EFF  GF 43  [NNN   2 [CCC +, +, +,Z [ 	$__ooo6@X@X@X   	E5>E5>:S'NSSS	 	$__oooG444   	U^eU^eU^D 'N  		
 *0 0+ *0
 [D  [VV,,0 0 -, 0& [	
 	
 	
  [UY$>??[XAw//1 1 0/ @? 1 1 1r%   r   )'r2   r   rl   numpyr[   r   pandasr   pandas._testing_testingrK   pandas.core.apir   r   r   pandas.core.computationr   r   r\   r]   listr   r   rS   astyper   r   r   r   r   rJ   r   r   r   r   r   skipifUSE_NUMEXPRr   r   r%   r#   <module>r      s    				       ! ! ! ! ! !               
 8 7 7 7 7 7	29??5!,,dd6ll)	T	T	T
)BIOOC++TT&\\
S
S
S	C[C[	**C[((C[((	 
 
 )S\  S\  ++S\  ))S\  ))	   9Ia:..VG   IIa8,,dd6ll'  	 
		 	 	"	"
#,

"
"
$
$c{!&&((#((** ((1DEEg1 g1 g1 g1 g1 g1 g1 FEg1 g1 g1r%   