
    Owgz              	       Z   d dl Z d dlZd dlZd dlmZmZ d dlmc m	Z
 d dlZd dlmZmZmZmZmZ d dlmZ d dlmZ  ej.                  ddgd       d	        Z ej.                  d ej2                  d
 e
j4                  d
            gd       d        Zd Z G d d      Z G d d      Z G d d      Z e
j4                  d
       G d d             Z  e
j4                  d
       G d de              Z! G d de       Z" G d de!      Z# G d d      Z$ G d d       Z% G d! d"      Z&y)#    N)NumExprClobberingErrorUndefinedVariableError)	DataFrameIndex
MultiIndexSeries
date_range)NUMEXPR_INSTALLEDpythonpandasc                     | S N xs    Y/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/tests/frame/test_query_eval.py<lambda>r      s    1     )paramsidsc                     | j                   S r   paramrequests    r   parserr      s    ==r   numexpr)marksc                     | S r   r   r   s    r   r   r      s    ! r   c                     | j                   S r   r   r   s    r   enginer!      s    
 ==r   c                 @    | dk7  rt        j                  d|         y y )Nr   zcannot evaluate with parser=)pytestskip)r   s    r   skip_if_no_pandas_parserr%   %   s#    26(;< r   c                       e Zd Zej                  d        Zej                  d        Zej                  d        Zd Zd Z	d Z
d Zy)	
TestCompatc                      t        dg di      S )NA         r   selfs    r   dfzTestCompat.df+   s    #y)**r   c                 &    ||j                   dkD     S )Nr   r)   r0   r1   s     r   	expected1zTestCompat.expected1/   s    "$$(|r   c                      |j                   dz   S Nr+   r3   r4   s     r   	expected2zTestCompat.expected23   s    ttaxr   c                     |j                  d      }t        j                  ||       |j                  d      }t        j                  ||d       y )NA>0A+1Fcheck_namesquerytmassert_frame_equalevalassert_series_equalr0   r1   r5   r8   results        r   test_query_defaultzTestCompat.test_query_default7   s@     %
fi0
vyeDr   c                     |j                  dd       }t        j                  ||       |j                  dd       }t        j                  ||d       y )Nr:   r!   r;   Fr<   r>   rD   s        r   test_query_NonezTestCompat.test_query_None?   sH    %-
fi0t,
vyeDr   c                     |j                  dd      }t        j                  ||       |j                  dd      }t        j                  ||d       y )Nr:   r   rH   r;   Fr<   r>   rD   s        r   test_query_pythonzTestCompat.test_query_pythonE   sH    %1
fi0x0
vyeDr   c                    t         rU|j                  dd      }t        j                  ||       |j	                  dd      }t        j
                  ||d       y d}t        j                  t        |      5  |j                  dd       d d d        t        j                  t        |      5  |j	                  dd       d d d        y # 1 sw Y   AxY w# 1 sw Y   y xY w)	Nr:   r   rH   r;   Fr<   z~'numexpr' is not installed or an unsupported version. Cannot use engine='numexpr' for query/eval if 'numexpr' is not installedmatch)	r
   r?   r@   rA   rB   rC   r#   raisesImportError)r0   r1   r5   r8   rE   msgs         r   test_query_numexprzTestCompat.test_query_numexprK   s    XXeIX6F!!&)4WWU9W5F""69%H! 
 {#6 2y12{#6 1i01 12 21 1s   9C0CCC"N)__name__
__module____qualname__r#   fixturer1   r5   r8   rF   rI   rK   rR   r   r   r   r'   r'   *   s_    ^^+ + ^^  ^^ EEE1r   r'   c                       e Zd Zej                  j                  dddg      ej                  j                  dg d      d               Zd Zd Zd	 Z	d
 Z
d Zd Zy)TestDataFrameEvaln   i  zop_str,op,rop))+__add____radd__)-__sub____rsub__)*__mul____rmul__)/__truediv____rtruediv__c                 &   t        dt        |      t        d            }d|j                  d<   |j	                         }t        t        j                  |j                  |      j                  |d      t        d            }t        d| d	      }t        d
| d	      }	t        j                  |	|       |dv r) t        ||      |      }	t        j                  |	|       y |dv r) t        ||      |      }	t        j                  |	|       y y )Nr+   abcdindexcolumnsr,   r   rk   zbase z dfzm )r[   ra   )r^   rd   )r   rangelistilocmeannptilevaluesreshaperB   r@   rA   getattr)
r0   op_stroproprY   r1   mbaseexpectedrE   s
             r   test_opszTestDataFrameEval.test_ops_   s     qa$v,?
GGIGGAHHa ((B/f
 %xs+, 6(#&'
fh/ $WR_Q'F!!&(3 :%WR%a(F!!&(3 r   c                 p   t        dt        j                  j                  d      j	                  d      i      }t        j
                  |j                  dd dt        j                  |j                  dd       z
  }dt        j                  |      z
  j                  dd }t        j                  ||       y )Nr)   r,   ia  r      r+      )
r   rr   randomdefault_rngstandard_normalnanrp   isnanr@   rA   )r0   r1   r|   rE   s       r   test_dataframe_sub_numexpr_pathz1TestDataFrameEval.test_dataframe_sub_numexpr_path   s     RYY2215EEeLMNvv!rxx"..bhhrl"((2.
fh/r   c                 2   t        g dg dd      }d}t        j                  t        |      5  |j	                  d        d d d        t        j                  t        |      5  |j	                  d       d d d        y # 1 sw Y   ?xY w# 1 sw Y   y xY w)Nr*   )abr   r)   Bz%expr must be a string to be evaluatedrM   c                      | j                   dk(  S )Nr   )r   r   s    r   r   z6TestDataFrameEval.test_query_non_str.<locals>.<lambda>   s    qsscz r   o   r   r#   rO   
ValueErrorr?   r0   r1   rQ   s      r   test_query_non_strz$TestDataFrameEval.test_query_non_str   s{    Y_=>5]]:S1 	+HH)*	+ ]]:S1 	HHSM	 		+ 	+	 	s   B&BB
Bc                     t        dg di      }d}t        j                  t        |      5  |j	                  d       d d d        y # 1 sw Y   y xY w)Nr)   r*   zexpr cannot be an empty stringrM    r   r   s      r   test_query_empty_stringz)TestDataFrameEval.test_query_empty_string   sD    Y'(.]]:S1 	HHRL	 	 	s   AAc                 ,   t        t        j                  j                  d      j	                  d      t        d            }ddi}ddi}|j                  d||g	      |d   |d   z   k(  sJ t        j                  d||g	      |d   |d   z   k(  sJ y )
Nr,   
   r,   abrm   r   r+   r   a + b	resolvers)r   rr   r   r   r   ro   rB   pd)r0   r1   dict1dict2s       r   test_eval_resolvers_as_listz-TestDataFrameEval.test_eval_resolvers_as_list   s    II!!!$44W=tDz
 aawww5%.w9U3Z%PS*=TTTTwww5%.9U3Z%PS*=TTTTr   c                    t        t        j                  j                  d      j	                  d      t        d            }ddi}|j                  d|g      }|d   |d	   |d   z  z   }t        j                  ||       y )
Nr,   r   r   rm   cz	a + b * cr   r   r   )	r   rr   r   r   r   ro   rB   r@   rC   )r0   r1   r   rE   r|   s        r   test_eval_resolvers_combinedz.TestDataFrameEval.test_eval_resolvers_combined   s{    II!!!$44W=tDz
 a 8c7RWuSz11
vx0r   c                     t        dddgi      }|j                  d      }t        ddgddgd      }t        j                  ||       y )Na1YNzc = ((a1 == 'Y') & True)TF)r   r   )r   rB   r@   rA   )r0   r1   resr|   s       r   test_eval_object_dtype_binopz.TestDataFrameEval.test_eval_object_dtype_binop   sK    sCj)*gg01S#JdE]CD
c8,r   N)rS   rT   rU   r#   markparametrizer}   r   r   r   r   r   r   r   r   r   rX   rX   ]   sg    [[S1d),[[	
4 -480	U1-r   rX   c                   $    e Zd Zd Zd Zd Zd Zy) TestDataFrameQueryWithMultiIndexc                    t        |       t        j                  j                  d      j	                  ddgd      }t        j                  j                  d      j	                  ddgd      }t        j                  ||gdd	g
      }t        t        j                  j                  d      j                  d      |      }t        |j                  j                  d      j                  |d      }|j                  d||      }|j                  d||      }	||dk(     }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||dk7     }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||j!                  dg         }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||j!                  dg          }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||j!                  dg         }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||j!                  dg          }
t        j                  ||
       t        j                  |	|
       y )Nr,   redgreenr   sizeeggshamcolorfoodnamesr   rj   rj   namezcolor == "red"r   r!   z"red" == colorzcolor != "red"z"red" != colorzcolor == ["red"]z["red"] == colorzcolor != ["red"]z["red"] != colorz["red"] in colorz"red" in colorz["red"] not in colorz"red" not in colorr%   rr   r   r   choicer   from_arraysr   r   r   rj   get_level_valuesrt   r?   r@   rA   isinr0   r   r!   r   r   rj   r1   indres1res2exps              r    test_query_with_named_multiindexzATestDataFrameQueryWithMultiIndex.test_query_with_named_multiindex   s    (II!!!$++UG,<2+FII!!!$++VUO"+E&&1vgv5FGryy,,Q/??HPUVHH%%g.55U

 xx(xGxx(xG
dC(
dC( xx(xGxx(xG
dC(
dC( xx*6&xIxx*6&xI5'"#
dC(
dC(xx*6&xIxx*6&xI#((E7##$
dC(
dC( xx*6&xIxx(xG5'"#
dC(
dC(xx.vfxMxx,VFxK#((E7##$
dC(
dC(r   c                    t        |       t        j                  j                  d      j	                  ddgd      }t        j                  j                  d      j	                  ddgd      }t        j                  ||g      }t        t        j                  j                  d      j                  d      |	      }t        |j                  j                  d
      j                  |	      }|j                  d||      }|j                  d||      }	||dk(     }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||dk7     }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||j!                  dg         }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||j!                  dg          }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||j!                  dg         }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||j!                  dg          }
t        j                  ||
       t        j                  |	|
       t        |j                  j                  d      j                  |	      }|j                  d||      }|j                  d||      }	||dk(     }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||dk7     }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d||      }	||j!                  dg         }
t        j                  ||
       t        j                  |	|
       |j                  d||      }|j                  d ||      }	||j!                  dg          }
t        j                  ||
       t        j                  |	|
       |j                  d!||      }|j                  d"||      }	||j!                  dg         }
t        j                  ||
       t        j                  |	|
       |j                  d#||      }|j                  d$||      }	||j!                  dg          }
t        j                  ||
       t        j                  |	|
       y )%Nr,   r   r   r   r   r   r   r   r   r   ilevel_0 == "red"r   z"red" == ilevel_0ilevel_0 != "red"z"red" != ilevel_0zilevel_0 == ["red"]z["red"] == ilevel_0zilevel_0 != ["red"]z["red"] != ilevel_0z["red"] in ilevel_0z"red" in ilevel_0z["red"] not in ilevel_0z"red" not in ilevel_0r+   zilevel_1 == "eggs"z"eggs" == ilevel_1zilevel_1 != "eggs"z"eggs" != ilevel_1zilevel_1 == ["eggs"]z["eggs"] == ilevel_1zilevel_1 != ["eggs"]z["eggs"] != ilevel_1z["eggs"] in ilevel_1z"eggs" in ilevel_1z["eggs"] not in ilevel_1z"eggs" not in ilevel_1r   r   s              r   "test_query_with_unnamed_multiindexzCTestDataFrameQueryWithMultiIndex.test_query_with_unnamed_multiindex   sJ    (II!!!$++UG,<2+FII!!!$++VUO"+E&&1v.ryy,,Q/??HPUVRXX..q188Fxx+F6xJxx+F6xJ
dC(
dC( xx+F6xJxx+F6xJ
dC(
dC( xx-fVxLxx-fVxL5'"#
dC(
dC(xx-fVxLxx-fVxL#((E7##$
dC(
dC( xx-fVxLxx+F6xJ5'"#
dC(
dC(xx1&xPxx/vxN#((E7##$
dC(
dC( RXX..q188Fxx,VFxKxx,VFxK
dC(
dC( xx,VFxKxx,VFxK
dC(
dC( xx.vfxMxx.vfxM6(#$
dC(
dC(xx.vfxMxx.vfxM#((F8$$%
dC(
dC( xx.vfxMxx,VFxK6(#$
dC(
dC(xx26&xQxx0xO#((F8$$%
dC(
dC(r   c                 n   t        |       t        j                  j                  d      j	                  ddgd      }t        j
                  d      }t        j                  ||g      }d dg|_        t        t        j                  j                  d      j                  d      |      }|j                  d	||
      }t        |j                  j                  d      j                  |d      }||dk(     }	t!        j"                  ||	       |j                  d||
      }t        |j                  j                  d      j                  |d      }||dk7     }	t!        j"                  ||	       |j                  d||
      }t        |j                  j                  d      j                  |      }||dk(     }	t!        j"                  ||	       |j                  d||
      }t        |j                  j                  d      j                  |      }||dk7     }	t!        j"                  ||	       y )Nr,   r   r   r   r   ratingr   r   zrating == 1r   r   r+   zrating != 1r   r   r   )r%   rr   r   r   r   aranger   r   r   r   r   r?   r   rj   r   rt   r@   rA   )
r0   r   r!   r   r   rj   r1   r   r   r   s
             r   *test_query_with_partially_named_multiindexzKTestDataFrameQueryWithMultiIndex.test_query_with_partially_named_multiindexK  s    (II!!!$++UG,<2+FIIbM&&1v.X&ryy,,Q/??HPUVhh}VFhCHH%%h/66e(
 l
c3'hh}VFhCHH%%h/66e(
 l
c3'hh*6&hIRXX..q188F
c3'hh*6&hIRXX..q188F
c3'r   c                 d   t        t        j                  d      t        j                  t        d      D cg c]  }t        d       c}ddg            }|j                         }d }|j                  j                         }|j                  | ||j                  d       ||j                  d      |d	}|j                         D ]`  \  }}t        |t              r|j                  ||         r+J t        |t              rt        j                   |||          Wt#        d
       y c c}w )Nr   r-   r,   r   spamr   r   r   c                 V    | j                  |      }|j                         }| |_        |S r   )r   	to_seriesrj   )milevellevel_valuesss       r   r   z]TestDataFrameQueryWithMultiIndex.test_query_multiindex_get_index_resolvers.<locals>.to_seriess  s,    ..u5L&&(AAGHr   )rj   rk   r   r   clevel_0z object must be a Series or Index)r   rr   onesr   r   rn   _get_index_resolversrk   r   rj   items
isinstancer   is_r   r@   rC   AssertionError)	r0   _r1   r   r   
col_seriesr|   kvs	            r   )test_query_multiindex_get_index_resolverszJTestDataFrameQueryWithMultiIndex.test_query_multiindex_get_index_resolversj  s	   GGG(($)!H-qr-ff5E
 ++-		 ZZ))+
XX!bhh/bhh/"
 OO% 	IDAq!U#uuXa[)))Av&&&q(1+6$%GHH	I' .s   D-N)rS   rT   rU   r   r   r   r   r   r   r   r   r      s    0)dV)p(>Ir   r   c                   \   e Zd Zej                  d        Zej                  d        Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej:                  j=                  ddej@                  gdejB                  gg      d        Z"d Z#d Z$y) TestDataFrameQueryNumExprPandasc                      yNr   r   r/   s    r   r!   z&TestDataFrameQueryNumExprPandas.engine      r   c                      yNr   r   r/   s    r   r   z&TestDataFrameQueryNumExprPandas.parser      r   c                    t        |       t        t        j                  j	                  d      j                  d            }t        dd      |d<   t        dd      |d<   t        d	d      |d
<   |j                  d||      }||j                  dk  d|j                  k  z     }t        j                  ||       y )Nr,   r   r-   1/1/2012r   periodsdates11/1/2013dates21/1/2014dates3z"@df.dates1 < 20130101 < @df.dates3r!   r   20130101)r%   r   rr   r   r   r   r	   r?   r   r   r@   rA   r0   r!   r   r1   r   expecs         r   %test_date_query_with_attribute_accesszETestDataFrameQueryNumExprPandas.test_date_query_with_attribute_access  s     (ryy,,Q/??GH!*a88!*a88!*a88hh0  
 BII
*zBII/EFG
c5)r   c                 j   t        t        j                  j                  d      j	                  d            }t        dd      |d<   t        dd      |d<   t        d	d      |d
<   |j                  d||      }||j                  dk  d|j                  k  z     }t        j                  ||       y )Nr,   r   r   r   r   r   r   r   r   r   dates1 < 20130101 < dates3r   r   r   rr   r   r   r   r	   r?   r   r   r@   rA   r   s         r   #test_date_query_no_attribute_accesszCTestDataFrameQueryNumExprPandas.test_date_query_no_attribute_access  s    ryy,,Q/??GH!*a88!*a88!*a88hh3F6hRBII
*zBII/EFG
c5)r   c                    d}t        t        j                  j                  d      j	                  |df            }t        d|      |d<   t        d|      |d<   t        d	|      |d
<   t        j                  |j                  t        j                  j                  d      j                  |      dkD  df<   t        j                  |j                  t        j                  j                  d      j                  |      dkD  d
f<   |j                  d||      }||j                  dk  d|j                  k  z     }t        j                  ||       y )Nr   r,   r-   r   r   r   r   r   r   r         ?r   r   r   r   rr   r   r   r   r	   r   NaTlocr?   r   r   r@   rA   r0   r!   r   rY   r1   r   r   s          r   test_date_query_with_NaTz8TestDataFrameQueryNumExprPandas.test_date_query_with_NaT  s   ryy,,Q/??AGH!*a88!*a88!*a88EGVVryy$$Q'..q1C7ABEGVVryy$$Q'..q1C7ABhh3F6hRBII
*zBII/EFG
c5)r   c                    d}t        t        j                  j                  d      j	                  |df            }t        d|      |d<   t        d|      |d<   |j                  dd	d	
      }|J |j                  d||      }||j                  dk  d|j                  k  z     }t        j                  ||       y )Nr   r,   r-   r   r   r   r   r   Tinplacedropindex < 20130101 < dates3r   r   r   rr   r   r   r   r	   	set_indexr?   rj   r   r@   rA   r0   r!   r   rY   r1   return_valuer   r   s           r   test_date_index_queryz5TestDataFrameQueryNumExprPandas.test_date_index_query  s    ryy,,Q/??AGH!*a88!*a88||Hd|F###hh26&hQBHHz)j299.DEF
c5)r   c                    d}t        t        j                  j                  d      j	                  |df            j                  dt        i      }t        d|      |d<   t        d|      |d	<   t        j                  |j                  d
<   |j                  ddd      }|J |j                  d||      }||j                  dk  d|j                  k  z     }t        j                   ||       y )Nr   r,   r-   r   r   r   r   r   r   r   r   Tr  r
  r   r   r   rr   r   r   r   astypeobjectr	   r   r  rp   r  r?   rj   r   r@   rA   r  s           r   test_date_index_query_with_NaTz>TestDataFrameQueryNumExprPandas.test_date_index_query_with_NaT  s    ryy,,Q/??AGHOOK
 "*a88!*a88||Hd|F###hh26&hQBHHz)j299.DEF
c5)r   c                    d}i }t        d|      |d<   t        d|      |d<   t        |      }t        j                  |j                  t
        j                  j                  d      j                  |      dkD  df<   |j                  dd	d	
      }|J |j                  d||      }||j                  j                         dk  d|j                  k  z     }t        j                  ||       y )Nr   r   r   r   r   r   r,   r   Tr  r   r   r   )r	   r   r   r  r  rr   r   r   r  r?   rj   r   r   r@   rA   )	r0   r!   r   rY   dr1   r  r   r   s	            r   )test_date_index_query_with_NaT_duplicateszITestDataFrameQueryNumExprPandas.test_date_index_query_with_NaT_duplicates  s     Q7( Q7(q\EGVVryy$$Q'..q1C7AB||Hd|F###hh3F6hRBHH&&(:5*ryy:PQR
c5)r   c                    d}t        t        d|      t        j                  |      d      }|j	                  d||      }t        |      dk(  sJ |j	                  d||      }t        j                  ||       d	}d
D ]>  }t        j                  t        |      5  |j	                  d| d||       d d d        @ y # 1 sw Y   KxY w)Nr   r   r   )datesnondatezdates == nondater   r   zdates != nondatez=Invalid comparison between dtype=datetime64\[ns\] and ndarray)<><=>=rM   zdates z nondate)r   r	   rr   r   r?   lenr@   rA   r#   rO   	TypeError)r0   r!   r   rY   r1   rE   rQ   rx   s           r   test_date_query_with_non_datez=TestDataFrameQueryNumExprPandas.test_date_query_with_non_date  s     Q7BIIaLQ
 ,VFK6{a,VFK
fb)N( 	NBy4 N6"X.vfMN N	NN Ns   CC	c                     t        t        d      t        dd      t        dd      d      }d}t        j                  t        |      5  |j                  d	||
       d d d        y # 1 sw Y   y xY w)Nr   r-      rZ      )ir[   rzinvalid syntaxrM   zi - +r   )r   rn   r#   rO   SyntaxErrorr?   )r0   r!   r   r1   rQ   s        r   test_query_syntax_errorz7TestDataFrameQueryNumExprPandas.test_query_syntax_error  s]    U2YU1b\aMN]];c2 	<HHWVFH;	< 	< 	<s   
A((A1c                    t        |       t        t        j                  j	                  d      j                  d      t        d            }d\  }}|j                  d||      }||j                  |j                  kD     }t        j                  ||       |j                  d||      }|||j                  kD     }t        j                  ||       t        j                  t        d	
      5  |j                  d||       d d d        t        j                  t        d
      5  |j                  d||       d d d        y # 1 sw Y   BxY w# 1 sw Y   y xY w)Nr,   )   r,   r   rm   )r+   r,   za > br   z@a > b!local variable 'c' is not definedrM   z@a > b > @czname 'c' is not definedz
@a > b > c)r%   r   rr   r   r   r   ro   r?   r   r   r@   rA   r#   rO   r   )r0   r!   r   r1   r   r   r   r|   s           r   test_query_scopez0TestDataFrameQueryNumExprPandas.test_query_scope  s4    (II!!!$44W=tDz
 1hhwvfh=bddRTTk?
c8,hhxvh>a"$$h<
c8, ]]"*M
 	B HH]6&HA	B ]]19RS 	AHH\&H@	A 	A	B 	B	A 	As   0E(EEEc                     dx}}t        t        j                  j                  d      j	                  ||df      t        d            }t        j                  t        d      5  |j                  d	||
       d d d        y # 1 sw Y   y xY w)Nr   r,   r-   r   abcrm   zname 'sin' is not definedrM   sin > 5r   )
r   rr   r   r   integersro   r#   rO   r   r?   )r0   r!   r   rY   rz   r1   s         r   test_query_doesnt_pickup_localz>TestDataFrameQueryNumExprPandas.test_query_doesnt_pickup_local  sz    
AII!!!$--aq!f-=tE{

 ]]19TU 	>HHYvfH=	> 	> 	>s   &BBc                 F   dx}}t        t        j                  j                  d      j	                  ||df      t        d            }d|j                  _        d}t        j                  t        |	      5  |j                  d
||       d d d        y # 1 sw Y   y xY w)Nr   r,   r-   r   r/  rm   sinzVariables in expression.+rM   r0  r   )r   rr   r   r   r1  ro   rj   r   r#   rO   r   r?   )r0   r!   r   rY   rz   r1   rQ   s          r   test_query_builtinz2TestDataFrameQueryNumExprPandas.test_query_builtin  s    
AII!!!$--aq!f-=tE{
 )]]1= 	>HHYvfH=	> 	> 	>s   9BB c                    t        t        j                  j                  d      j	                  d      g d      }t        j                  |j                  d||      ||j                  |j                  k            t        j                  |j                  d||      ||j                  |j                  z   |j                  |j                  z  kD            y )Nr,   r   r   r   r   rm   a < br   za + b > b * c)r   rr   r   r   r   r@   rA   r?   r   r   r   r0   r!   r   r1   s       r   
test_queryz*TestDataFrameQueryNumExprPandas.test_query"  s    II!!!$44W=
 	HHWVFH;Rrtt_	
 	HH_VFHCrttbdd{RTTBDD[()	
r   c                    t        t        j                  j                  d      j	                  dd      t        t        d      d      g d      }|j                  d	||
      }||j                  dk  |j                  |j                  k  z     }t        j                  ||       |j                  d||
      }||j                  |j                  k     }t        j                  ||       y )Nr,   r   r   r   blobr   r7  ri   z(blob < 5) & (a < b)r   r   zblob < b)r   rr   r   r   r1  r   rn   r?   rj   r   r   r@   rA   r   s         r   test_query_index_with_namez:TestDataFrameQueryNumExprPandas.test_query_index_with_name/  s    II!!!$--bw-?b	/#

 hh-fVhLBHHqLRTTBDD[12
c5)hhz&h@288bdd?#
c5)r   c                    t        t        j                  j                  d      j	                  dd      t        d      g d      }|j                  d||      }||j                  |j                  k     }t        j                  ||       |j                  d	||      }||j                  d
k     }t        j                  ||       y )Nr,   r   r   r   r7  ri   z	index < br   z	index < 5r   )r   rr   r   r   r1  rn   r?   rj   r   r@   rA   r   s         r   test_query_index_without_namez=TestDataFrameQueryNumExprPandas.test_query_index_without_name>  s    II!!!$--bw-?)#
 hh{6&hA288bdd?#
c5) hh{6&hA288a< 
c5)r   c                    t        |       t        t        j                  j	                  d      j                  d            }t        t        j                  j	                  d      j                  d            }||dkD  |dkD  z     }|j                  d||      }t        j                  ||       t        j                  d||      }t        j                  ||       t        j                  d||      }||dkD  |dkD  z  ||dkD     dkD  z     }t        j                  ||       t        j                  d||      }|j                  d	||      }t        j                  ||       y )
Nr,   r   r   z(@df > 0) & (@df2 > 0)r   zdf[df > 0 and df2 > 0]z)df[df > 0 and df2 > 0 and df[df > 0] > 0]zdf[(df>0) & (df2>0)](@df>0) & (@df2>0))r%   r   rr   r   r   r   r?   r@   rA   r   rB   )r0   r!   r   r1   df2r|   rE   s          r   test_nested_scopez1TestDataFrameQueryNumExprPandas.test_nested_scopeO  s8    (ryy,,Q/??GH		--a0@@HIrAv#'*+26&Q
fh/1&P
fh/7v
 rAv#'*baj1n=>
fh//vN8808O
fh/r   c                     t        t        j                  j                  d      j	                  d            }t        j                  t        d      5  |j                  d||       d d d        y # 1 sw Y   y xY w)Nr,   r   name 'df' is not definedrM   zdf > 0r   )	r   rr   r   r   r   r#   rO   r   r?   r9  s       r   *test_nested_raises_on_local_self_referencezJTestDataFrameQueryNumExprPandas.test_nested_raises_on_local_self_referencef  s_    ryy,,Q/??GH ]]19ST 	=HHXfVH<	= 	= 	=s   A11A:c                    t        |       t        t        j                  j	                  d      j                  d      t        d            }d}||j                  |k     }|j                  d||      }t        j                  ||       ||j                  |j                  k     }|j                  d||      }t        j                  ||       y )	Nr,   )d   r   
abcdefghijrm   r+   za < @br   r8  )r%   r   rr   r   r   r   ro   r   r?   r@   rA   r   )r0   r!   r   r1   r   expectrE   s          r   test_local_syntaxz1TestDataFrameQueryNumExprPandas.test_local_syntaxm  s     (II!!!$44Y?&
 BDD1H(6&A
ff-BDD244K'&@
ff-r   c                    t        |       t        d      }t        t        j                  j                  d      j                  dt        |      f      |      }|j                  d||      }|j                  |j                  k  |j                  |j                  k  z  |j                  j                  |j                         z  |j                  j                  |j                         z  }||   }t        j                  ||       y )Nr/  r,   rI  rm   z!a < b < c and a not in b not in cr   )r%   ro   r   rr   r   r   r   r   r?   r   r   r   r   r@   rA   )r0   r!   r   colsr1   r   r   r   s           r   test_chained_cmp_and_inz7TestDataFrameQueryNumExprPandas.test_chained_cmp_and_in}  s     (E{II!!!$44c3t95EFPT
 hh/v  
 ttbdd{rttbdd{+rttyy.>>"$$))BDD/AQQ3
c5)r   c                    t        |       t        t        j                  j	                  d      j                  dd      d      }t        t        j                  j	                  d      j                  dd      d      }t        ||d	      }|j                  |j                  d
z
  j                  |         }|j                  d||      }t        j                  ||       t        t        j                  j	                  d      j                  dd      d      }|j                  |d
z
  j                  |         }|j                  d||      }t        j                  ||       y )Nr,   r-      r   r   r=  r   r   r   r   r+   z
b - 1 in ar   z@b - 1 in a)r%   r   rr   r   r   r1  r   r  r   r   r?   r@   rA   )r0   r!   r   r   r   r1   r|   rE   s           r   test_local_variable_with_inz;TestDataFrameQueryNumExprPandas.test_local_variable_with_in  s    (299((+44QR4@sK299((+44Rb4ALQQ'(66244!8//!,-,vfE
h/299((+44Rb4AL661q5,,q/*-vF
h/r   c                     t        |       d}t        dg di      }|j                  d||      }||j                  dk(     }t	        j
                  ||       y )Nr+   r   )r   r   r   r   @crU  z	a == "@c"r   rU  r%   r   r?   r   r@   rA   )r0   r!   r   r   r1   rE   r|   s          r   test_at_inside_stringz5TestDataFrameQueryNumExprPandas.test_at_inside_string  sU     (=>?+fVDbdddl#
fh/r   c                 V   | j                   | j                  }}t        |       t        t        j
                  j                  d      j                  d      t        d            }t        j                  t        d      5  |j                  d||       d d d        y # 1 sw Y   y xY w)	Nr,   r   r   rm   r,  rM   za == @cr   )r!   r   r%   r   rr   r   r   ro   r#   rO   r   r?   r9  s       r   test_query_undefined_localz:TestDataFrameQueryNumExprPandas.test_query_undefined_local  s    dkk (ryy,,Q/66w?dT]]"*M
 	> HHYvfH=	> 	> 	>s   BB(c                 >   d}t         j                  ddd   }t        |t         j                  j	                  d      j                  |j                        d      }d|j                  _        |j                  d||      }||d   d	kD     }t        j                  ||       t        |t         j                  j	                  d      j                  |j                        d      }|j                  d
||      }|j                  |j                  |j                  d	kD        }t        j                  ||       t        |t         j                  j	                  d      j                  |j                        d      }d|j                  _        |j                  d||      }||j                  d	kD     }t        j                  ||       |j                  d||      }|j                  |j                  |j                  d	kD        }t        j                  ||       y )Nr+   r+  e   r,   )rj   r   rj   z	index > 5r   r   zilevel_0 > 5rR  r   za > 5)rr   r_r   r   r   r   r   rj   r   r?   r@   rA   r  r   )r0   r!   r   rY   r   r1   rE   r|   s           r   :test_index_resolvers_come_after_columns_with_the_same_namezZTestDataFrameQueryNumExprPandas.test_index_resolvers_come_after_columns_with_the_same_name  s    EE"S)bii33A6FFqvvNO
  +fVDbkAo&
fh/bii33A6FFqvvNO
 .G66"((288a<01
fh/QRYY%:%:1%=%M%Maff%UVW'&@bddQh<
fh/+fVD66"((288a<01
fh/r   zop, f==!=c                    d}t        t        j                  j                  d      j                  |      t        j                  j                  d      j                  |      d      }t        j                  |j
                  d d ddf<   d| d}| ||j                  t        j                           }|j                  |||      }	t        j                  |	|       y )Nr   r,   rR  r   a z infr   )
r   rr   r   r   infr  r   r?   r@   rA   )
r0   rx   fr!   r   rY   r1   qr|   rE   s
             r   test_infz(TestDataFrameQueryNumExprPandas.test_inf  s    YY**1-44Q7YY**1-44Q7
 ssAvDMabffo&!F6:
fh/r   c                 &   |}t        ddd|d      }t        |      }t        |      }|j                  d      }t        j                  ||       t        |      }|j                         j                  d      }t        j                  ||       y )Nz
2019-01-011dr   time)startfreqr   tzr   r   z"2018-01-03 00:00:00+00" < time)r	   r   r?   r@   rA   reset_index)r0   tz_aware_fixturerk  df_indexr|   r1   rE   s          r   test_check_tz_aware_index_queryz?TestDataFrameQueryNumExprPandas.test_check_tz_aware_index_query  s    T2"6
 8,X&;<
fh/X&!''(IJ
fh/r   c           	      R   d}t        dt        j                  j                  d      j                  |      z  t        j                  j                  d      j                  |      d      }||d   j	                  d      dk(     }|j                  d||      }t        j                  ||       t        t        j                  t        j                  j                  d      j                  |      d	k  t        j                  t        j                  j                  d      j                  |            t        j                  j                  d      j                  |      d      }||d   j                            }|j                  d
||      }t        j                  ||       y )Nr   r,   rR  r   intr   za.astype('int') == 0r   r   za.notnull())r   rr   r   r   r  r?   r@   rA   wherer   r   notnull)r0   r!   r   rY   r1   r|   rE   s          r   test_method_calls_in_queryz:TestDataFrameQueryNumExprPandas.test_method_calls_in_query  sS   ..q188;;YY**1-44Q7
 bgnnU+q010O
fh/XXII))!,33A6<FFII))!,<<Q?
 YY**1-==a@	
 bgoo'(-vF
fh/r   N)%rS   rT   rU   r#   rV   r!   r   r   r   r  r  r  r  r"  r)  r-  r2  r5  r:  r>  r@  rD  rG  rL  rO  rS  rW  rY  r]  r   r   operatoreqnere  ro  rt  r   r   r   r   r     s    ^^  ^^ 
**
*	***N"<A4>	>
**"0.=. *00>0> [[Whkk':T8;;<O&PQ0 R000r   r   c                   ~    e Zd Zej                  d        Zej                  d        Zd Zd Zd Z	d Z
d Zd Zd	 Zy
)TestDataFrameQueryNumExprPythonc                      yr   r   r/   s    r   r!   z&TestDataFrameQueryNumExprPython.engine  r   r   c                      yNr   r   r/   s    r   r   z&TestDataFrameQueryNumExprPython.parser
  r   r   c                 j   t        t        j                  j                  d      j	                  d            }t        dd      |d<   t        dd      |d<   t        d	d      |d
<   |j                  d||      }||j                  dk  d|j                  k  z     }t        j                  ||       y )Nr,   r   r   r   r   r   r   r   r   r   )(dates1 < 20130101) & (20130101 < dates3)r   r   r   r   s         r   r   zCTestDataFrameQueryNumExprPython.test_date_query_no_attribute_access  s    ryy,,Q/??GH!*a88!*a88!*a88hh7v  
 BII
*zBII/EFG
c5)r   c                    d}t        t        j                  j                  d      j	                  |df            }t        d|      |d<   t        d|      |d<   t        d	|      |d
<   t        j                  |j                  t        j                  j                  d      j                  |      dkD  df<   t        j                  |j                  t        j                  j                  d      j                  |      dkD  d
f<   |j                  d||      }||j                  dk  d|j                  k  z     }t        j                  ||       y )Nr   r,   r-   r   r   r   r   r   r   r   r   r~  r   r   r  r  s          r   r  z8TestDataFrameQueryNumExprPython.test_date_query_with_NaT  s   ryy,,Q/??AGH!*a88!*a88!*a88EGVVryy$$Q'..q1C7ABEGVVryy$$Q'..q1C7ABhh7v  
 BII
*zBII/EFG
c5)r   c                    d}t        t        j                  j                  d      j	                  |df            }t        d|      |d<   t        d|      |d<   |j                  dd	d	
      }|J |j                  d||      }||j                  dk  d|j                  k  z     }t        j                  ||       y )Nr   r,   r-   r   r   r   r   r   Tr  ((index < 20130101) & (20130101 < dates3)r   r   r  r  s           r   r  z5TestDataFrameQueryNumExprPython.test_date_index_query'  s    ryy,,Q/??AGH!*a88!*a88||Hd|F###hh6vf  
 BHHz)j299.DEF
c5)r   c                    d}t        t        j                  j                  d      j	                  |df            j                  dt        i      }t        d|      |d<   t        d|      |d	<   t        j                  |j                  d
<   |j                  ddd      }|J |j                  d||      }||j                  dk  d|j                  k  z     }t        j                   ||       y )Nr   r,   r-   r   r   r   r   r   r   r  Tr  r  r   r   r  r  s           r   r  z>TestDataFrameQueryNumExprPython.test_date_index_query_with_NaT4  s    ryy,,Q/??AGHOOK
 "*a88!*a88||Hd|F###hh6vf  
 BHHz)j299.DEF
c5)r   c                    d}t        t        j                  j                  d      j	                  |df            }t        d|      |d<   t        d|      |d<   t        j                  |j                  t        j                  j                  d      j                  |      d	kD  df<   |j                  dd
d
      }|J d}t        j                  t        |      5  |j                  d||       d d d        y # 1 sw Y   y xY w)Nr   r,   r-   r   r   r   r   r   r   Tr  "'BoolOp' nodes are not implementedrM   r
  r   )r   rr   r   r   r   r	   r   r  r  r  r#   rO   NotImplementedErrorr?   )r0   r!   r   rY   r1   r  rQ   s          r   r  zITestDataFrameQueryNumExprPython.test_date_index_query_with_NaT_duplicatesE  s    ryy,,Q/??AGH!*a88!*a88EGVVryy$$Q'..q1C7AB||Hd|F###3]].c: 	PHH0HO	P 	P 	Ps   C==Dc                 >   d}t        j                  d||      }|dk(  sJ t        t        j                  j                  d      j                  d            }t        t        j                  j                  d      j                  d            }d}t        j                  t        |      5  |j                  d||       d d d        t        j                  t        d	      5  |j                  d
||       d d d        ||dkD  |dkD  z     }t        j                  d||      }t        j                  ||       ||dkD  |dkD  z  ||dkD     dkD  z     }t        j                  d||      }t        j                  ||       y # 1 sw Y   xY w# 1 sw Y   xY w)Nr+   zx + 1r   r,   r   z5The '@' prefix is only supported by the pandas parserrM   rB  rF  z(df>0) & (df2>0)r   zdf[(df > 0) & (df2 > 0)]z+df[(df > 0) & (df2 > 0) & (df[df > 0] > 0)])r   rB   r   rr   r   r   r   r#   rO   r(  r?   r   r@   rA   )	r0   r!   r   r   rE   r1   rC  rQ   r|   s	            r   rD  z1TestDataFrameQueryNumExprPython.test_nested_scopeQ  sy   ?{{ryy,,Q/??GH		--a0@@HI G]];c2 	IHH)&HH	I ]]19ST 	GHH'vHF	G rAv#'*+3F6R
h/rAv#'*baj1n=>9&QW
 	h/	I 	I	G 	Gs   -F%FFFc                 4   t        g dg dd      }d}t        j                  t        |      5  |j	                  d       d d d        d}t        j                  t        |      5  |j	                  d       d d d        y # 1 sw Y   AxY w# 1 sw Y   y xY w)	Nr*   rZ   r      )minmaxzMVariables in expression \"\(min\) == \(1\)\" overlap with builtins: \('min'\)rM   zmin == 1zMVariables in expression \"\(max\) == \(1\)\" overlap with builtins: \('max'\)zmax == 1)r   r#   rO   r   r?   )r0   r1   regex_to_matchs      r   +test_query_numexpr_with_min_and_max_columnszKTestDataFrameQueryNumExprPython.test_query_numexpr_with_min_and_max_columnsl  s    y;<0 	 ]]1H 	!HHZ 	!0 	 ]]1H 	!HHZ 	! 	!	! 	!	! 	!s   B'BBBN)rS   rT   rU   r#   rV   r!   r   r   r  r  r  r  rD  r  r   r   r   ry  ry    sT    ^^  ^^ 	****"
P06!r   ry  c                   Z    e Zd Zej                  d        Zej                  d        Zd Zy)TestDataFrameQueryPythonPandasc                      yr|  r   r/   s    r   r!   z%TestDataFrameQueryPythonPandas.engine~  r   r   c                      yr   r   r/   s    r   r   z%TestDataFrameQueryPythonPandas.parser  r   r   c                 2   dx}}t        t        j                  j                  d      j	                  ||df      t        d            }d|j                  _        ||j                  dkD     }|j                  d	||
      }t        j                  ||       y Nr   r,   r-   r   r/  rm   r4  r   r0  r   r   rr   r   r   r1  ro   rj   r   r?   r@   rA   r0   r!   r   rY   rz   r1   r|   rE   s           r   r5  z1TestDataFrameQueryPythonPandas.test_query_builtin      
AII!!!$--aq!f-=tE{
 bhhl#)F6B
h/r   NrS   rT   rU   r#   rV   r!   r   r5  r   r   r   r  r  }  5    ^^  ^^ 	0r   r  c                   Z    e Zd Zej                  d        Zej                  d        Zd Zy)TestDataFrameQueryPythonPythonc                      yr|  r   r/   s    r   r!   z%TestDataFrameQueryPythonPython.engine  r   r   c                      yr|  r   r/   s    r   r   z%TestDataFrameQueryPythonPython.parser  r   r   c                 2   dx}}t        t        j                  j                  d      j	                  ||df      t        d            }d|j                  _        ||j                  dkD     }|j                  d	||
      }t        j                  ||       y r  r  r  s           r   r5  z1TestDataFrameQueryPythonPython.test_query_builtin  r  r   Nr  r   r   r   r  r    r  r   r  c            
       P   e Zd Zd Zd Zd Zd Zd Zd Ze	j                  j                  ddej                  gd	ej                  gd
ej                  gdej                   gg      d        Zd Zd Ze	j                  j                  dg dg dg dg dg dg dg      d        Zy)TestDataFrameQueryStringsc           	      P   t        t        j                  j                  d      j	                  d      dg      }t        t        d            |d<   ||j                  dk(     }|dk7  rd}d	}|gdz  |gdz  z   }|d d d
   }d\  }	}
d|	g|
gz   z  }d}t        |||      D ]U  \  }}}| d| d| }t        j                  t        |      5  |j                  |||d|j                  i       d d d        W y |j                  d||      }t        j                  ||       |j                  d||      }t        j                  ||       t        j                  |||j                  j                  dg                ||j                  dk7     }|j                  d||      }t        j                  ||       |j                  d||      }t        j                  ||       t        j                  |||j                  j                  dg                 y # 1 sw Y   xY w)Nr,   r   r+   r   rm   
aabbccddeestringsr   r   z"a"rl   r^  r_  $'(Not)?In' nodes are not implemented rM   )r!   r   
local_dictz"a" == stringsr   zstrings == "a"zstrings != "a"z"a" != strings)r   rr   r   r   r   r   ro   r  zipr#   rO   r  r?   r@   rA   r   r0   r   r!   r1   rK  collstlhsrhsrv  rw  opsrQ   rx   exr   s                   r   test_str_query_methodz/TestDataFrameQueryStrings.test_str_query_method  s   ryy,,Q/??HSVRWXtL129BJJ#%&XCC%!)seai'Cdd)CFBtrd{#C9C #Cc 2 RuAbT3%(]]#6cB HH%%$-rzz#:	    ((+F6(JC!!#v.((+F6(JC!!#v.!!#r"**//3%*@'AB

c)*F((+F6(JC!!#v.((+F6(JC!!#v.!!#r2::??C5+A*A'BC+ s   "HH%	c                    t        t        j                  j                  d      j	                  d      dg      }t        t        d            |d<   ||j                  j                  ddg         }|dk7  rd}d	}|gdz  |gdz  z   }|d d d
   }d\  }	}
d|	g|
gz   z  }d}t        |||      D ]H  \  }}}| d| d| }t        j                  t        |      5  |j                  |||       d d d        J y |j                  d||      }t        j                  ||       |j                  d||      }t        j                  ||       ||j                  j                  ddg          }|j                  d||      }t        j                  ||       |j                  d||      }t        j                  ||       y # 1 sw Y    xY w)Nr,   r  r   rm   r  r  r   r   z
["a", "b"]rl   r  r  r  rM   r   zstrings == ["a", "b"]z["a", "b"] == stringszstrings != ["a", "b"]z["a", "b"] != strings)r   rr   r   r   r   r   ro   r  r   r  r#   rO   r  r?   r@   rA   r  s                   r   test_str_list_query_methodz4TestDataFrameQueryStrings.test_str_list_query_method  s   ryy,,Q/??HSVRWXtL129BJJOOS#J/0XCC%!)seai'Cdd)CFBtrd{#C9C #Cc 2 ?RuAbT3%(]]#6cB ?HHRvH>? ??
 ((26&(QC!!#v.((26&(QC!!#v.#s445F((26&(QC!!#v.((26&(QC!!#v.? ?s   GG	c           	         t        t        d      t        d      t        j                  j	                  d      j                  dd      t        j                  j	                  d      j                  dd      d      }|d	k(  r|j                  d
||      }||j                  j                  |j                           }t        j                  ||       |j                  d||      }||j                  j                  |j                        |j                  |j                  k  z     }t        j                  ||       y d}t        j                  t         |      5  |j                  d
||       d d d        d}t        j                  t         |      5  |j                  d||       d d d        y # 1 sw Y   DxY w# 1 sw Y   y xY w)Naaaabbbbccccaabbccddeeffr,   r      r   	   r   r   r   r  r   za in br   za in b and c < dr  rM   r  )r   ro   rr   r   r   r1  r?   r   r   r   r@   rA   r   r  r#   rO   r  )r0   r   r!   r1   r   r   rQ   s          r   test_query_with_string_columnsz8TestDataFrameQueryStrings.test_query_with_string_columns  s   .).)YY**1-66qr6BYY**1-66qr6B	
 X((8F6(BCrttyy'E!!#u-((-fV(LCrttyy"$$+67E!!#u-9C2#> A&@A 8C2#> K+F6JK K	A AK Ks    F8G8GGc           	         t        t        d      t        d      t        j                  j	                  d      j                  dd      t        j                  j	                  d      j                  dd      d      }|r|d	k(  rt        nd }t        j                  |      5  |j                  d
||      }d d d        ||j                  |j                  k(     }t        j                  |       t        j                  |      5  |j                  d||      }d d d        ||j                  |j                  k7     }t        j                  ||       y # 1 sw Y   xY w# 1 sw Y   HxY w)Nr  r  r,   r   r  r   r  r  r   za == br   za != b)r   ro   rr   r   r   r1  RuntimeWarningr@   assert_produces_warningr?   r   r   rA   )r0   r   r!   using_infer_stringr1   warningr   r   s           r   test_object_array_eq_nez1TestDataFrameQueryStrings.test_object_array_eq_ne  s:   .).)YY**1-66qr6BYY**1-66qr6B	
 %76Y;N.TX''0 	C((8F6(BC	C
c3'''0 	C((8F6(BC	C
c3'	C 	C
	C 	Cs   #EE#E #E,c           	         t        |       t        dd      D cg c]  }dD ]
  }d| d|   c}}dz  }t        ddd	
      }t        ddd	
      }t        t	        j
                  dd      j                  d      ||j                  |      d      }||j                  dk(     }	|j                  d||      }
t        j                  |	|
       y c c}}w )Nr+   rZ   )loadexitzpage r  r,   z2014-01-01 0:00:0130sr  )rj  r   z2014-02-01 1:00:01   )idevent	timestampz"page 1 load"z'"page 1 load"' in eventr   )r%   rn   r	   r   rr   r   repeatappendr  r?   r@   rA   )r0   r   r!   rY   acteventsstamps1stamps2r1   r|   r   s              r   test_query_with_nested_stringsz8TestDataFrameQueryStrings.test_query_with_nested_strings"  s     (',Q{
"#>N
7:eA3au

 1qI1qIii1o,,Q/$^^G4
 bhh/12hh5fVhT
h,
s   Cc                     t        |       t        g dg dd      }|j                  d||      }||j                  dk(     }t	        j
                  ||       y )N)r   r   test & testr*   rR  za == "test & test"r   r  rV  )r0   r   r!   r1   r   r   s         r   (test_query_with_nested_special_characterzBTestDataFrameQueryStrings.test_query_with_nested_special_character5  sR     (6YGHhh+F6hJ244=()
c5)r   zop, funcr  r  r  r  c                    t        t        j                  j                  d      j	                  t        d      d            }t        t        j                  |j                              }t        ||d      }|r|dk(  rt        nd }	t        j                  |	      5  |j                  d| d||      }
d d d        | ||j                  d	         }t        j                  
|       y # 1 sw Y   6xY w)
Nr,   abcder+  )Xr   r   zX z "d"r   r  )r   rr   r   r   r   ro   r   r   r   r  r@   r  r?   r  rA   )r0   r   r!   rx   funcr  r   r   r1   r  r   r|   s               r   test_query_lex_compare_stringsz8TestDataFrameQueryStrings.test_query_lex_compare_strings<  s     299((+224="EF299QVV$%QQ'($66Y;N.TX''0 	H((Rt4=(GC	Hd244o&
c8,	H 	Hs   C**C3c                 J   d}t         j                  j                  d      j                  ddt	        |      f      j                  t              }t        ||      }|j                  d||      }||j                  |j                  z     }t        j                  ||       y )N)bidbidsizeaskasksizer,   r+   r   rm   z	bid & askr   )rr   r   r   r1  r   r  boolr   r?   r  r  r@   rA   )r0   r   r!   rk   datar1   r   r|   s           r   "test_query_single_element_booleansz<TestDataFrameQueryStrings.test_query_single_element_booleansR  s    4yy$$Q'00!S\9J0KRRSWXtW-hh{6&hAbffrvvo&
c8,r   c                     t        |       t        g dg dd      }||j                  dk(     }d}|j                  d||      }t	        j
                  ||       y )N)BUD USr  IBM USr  )gl[@gGzn[@gf@g33333f@)SymbolPricer  zSymbol == @symbr   )r%   r   r  r?   r@   rA   )r0   r   r!   r1   esymbr'  s          r   !test_query_string_scalar_variablez;TestDataFrameQueryStrings.test_query_string_scalar_variableZ  s^     (B9
 ryyH$%HH&vfHE
a#r   in_list)Nasdfghjk)r  Nr  )r  r  N)NNr  )r  NN)NNNc                    d}d}t        |      D ci c]  \  }}|dk(  s|| }}}t        d|id      }|j                  j                  d      |_        t        d|id      }|j	                  d||	      }	||d   dk(     }
|j	                  d
||	      }t        j                  |	|       t        j                  |	|
       t        j                  |	|       t        j                  |
|       y c c}}w )Nr   r   r  r   stringdtypeint64za == 'asdf'r   za <= 'asdf')	enumerater   rj   r  r?   r@   rA   )r0   r  r   r!   r&  valuer|   df_expectedr1   r   r   res3s               r   test_query_string_null_elementsz9TestDataFrameQueryStrings.test_query_string_null_elementsg  s     -6w-?SE5F?AuHSShx@'--44W=W~X6xxfVxD"S'V#$xxfVxD
dK0
dD)
dD)
dD) Ts
   C3C3N)rS   rT   rU   r  r  r  r  r  r  r#   r   r   ru  ltgtleger  r  r  r  r   r   r   r  r    s    'DR!/FK4((-&* [[(++(++8;;8;;		
---$ [["""  	

*
*r   r  c                       e Zd Zej                  d        Zd Zd Zej                  j                  dg d      d        Z
y)TestDataFrameEvalWithFramec                     t        t        j                  j                  d      j	                  d      t        d            S )Nr,   r   r/  rm   )r   rr   r   r   r   ro   r/   s    r   framez TestDataFrameEvalWithFrame.frame  s2    II!!!$44W=tE{
 	
r   c                     |j                  d||      }|j                  |j                  z   }t        j                  ||       y )Nr   r   rB   r   r   r@   rC   r0   r  r   r!   r   rK  s         r   test_simple_exprz+TestDataFrameEvalWithFrame.test_simple_expr  s8    jjj?577"
sF+r   c                     |j                  d||      }|j                  |j                  dk     |j                  z   }t        j                  ||       y )Nza[a < 1] + br   r+   r  r  s         r   test_bool_arith_exprz/TestDataFrameEvalWithFrame.test_bool_arith_expr  sE    jjvjF1%/
sF+r   rx   )r[   r^   ra   rd   c                     t        ddgddgd      }d}t        j                  t        |      5  |j	                  d| d	||
       d d d        y # 1 sw Y   y xY w)Nr+   r,   r   r  rR  z:unsupported operand type\(s\) for .+: '.+' and '.+'|CannotrM   ra  z br   )r   r#   rO   r!  rB   )r0   r   r!   rx   r1   rQ   s         r   %test_invalid_type_for_operator_raisesz@TestDataFrameEvalWithFrame.test_invalid_type_for_operator_raises  s[    aV3*56K]]9C0 	?GGbBKvG>	? 	? 	?s   AAN)rS   rT   rU   r#   rV   r  r  r  r   r   r  r   r   r   r  r    sH    ^^
 

,
,
 [[T#78? 9?r   r  c                      e Zd Zej                  d        Zd Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej>                  jA                  dg d      d        Z!ej>                  jA                  ddd g      ej>                  jA                  dg d      d!               Z"d" Z#y#)$!TestDataFrameQueryBacktickQuotingc           	   #      K   t        i dg ddg ddg ddg dd	g d
dg ddg ddg ddg ddg ddg ddg ddg ddg ddg ddg d d!g d"g d#g d$g d%g d&g d'd(       y)w)*z
        Yields a dataframe with strings that may or may not need escaping
        by backticks. The last two columns cannot be escaped by backticks
        and should raise a ValueError.
        r)   r*   B B)r-   r,   r+   C Cr  C  C)r  rZ   r-   C_C)   r  r   D_D D)   r+   r[  E.E)r  r-   r   F-F)r  r+   r   1e1)r,   rZ   r  def)r   r  r,   A (x))rZ   r+   r-   zB(x))r+   r+   r   zB (x))r,   r  rZ        &^ :!€$?(} >    <++*''  )r,   r   r  r   )r   r  r+    A)rZ   r  r    r+   r,   r+   )r  r-   r+   )r  r+   r  )r  r  r  )r,   rZ   r   )r   r  r  )zit'szthat'su   ☺zfoo#barr+   Nr.   r/   s    r   r1   z$TestDataFrameQueryBacktickQuoting.df  s      Yy y 		
 z  y z y {  	  /	 K  i!" i#$ "# $-
 	
s   A6A8c                 h    |j                  d      }|d|d   k     }t        j                  ||       y )Nz	1 < `B B`r+   r  r?   r@   rA   r0   r1   r   rK  s       r   #test_single_backtick_variable_queryzETestDataFrameQueryBacktickQuoting.test_single_backtick_variable_query  s2    hh{#A5	M"
c6*r   c                 z    |j                  d      }|d|d   k  d|d   k  z     }t        j                  ||       y )Nz1 < `B B` and 4 < `C C`r+   r  rZ   r  r  r  s       r   !test_two_backtick_variables_queryzCTestDataFrameQueryBacktickQuoting.test_two_backtick_variables_query  s@    hh01QE]q2e9}56
c6*r   c                 h    |j                  d      }|d   |d   z   }t        j                  ||       y )Nz	A + `B B`r)   r  rB   r@   rC   r  s       r   "test_single_backtick_variable_exprzDTestDataFrameQueryBacktickQuoting.test_single_backtick_variable_expr  2    ggk"C2e9$
sF+r   c                 h    |j                  d      }|d   |d   z   }t        j                  ||       y )Nz`B B` + `C C`r  r  r  r  s       r    test_two_backtick_variables_exprzBTestDataFrameQueryBacktickQuoting.test_two_backtick_variables_expr  s2    ggo&ERY&
sF+r   c                 h    |j                  d      }|d   |d   z   }t        j                  ||       y )Nz	`C_C` + Ar
  r)   r  r  s       r    test_already_underscore_variablezBTestDataFrameQueryBacktickQuoting.test_already_underscore_variable  s2    ggk"ERW$
sF+r   c                 h    |j                  d      }|d   |d   z   }t        j                  ||       y )NzC_C + `C C`r
  r  r  r  s       r   test_same_name_but_underscoresz@TestDataFrameQueryBacktickQuoting.test_same_name_but_underscores  s2    ggm$ERY&
sF+r   c                 h    |j                  d      }|d   |d   z   }t        j                  ||       y )NzA + `D_D D`r)   r  r  r  s       r   !test_mixed_underscores_and_spaceszCTestDataFrameQueryBacktickQuoting.test_mixed_underscores_and_spaces  s2    ggm$C2g;&
sF+r   c                 h    |j                  d      }|d   |d   z   }t        j                  ||       y )Nz	A + `C_C`r)   r
  r  r  s       r   'test_backtick_quote_name_with_no_spaceszITestDataFrameQueryBacktickQuoting.test_backtick_quote_name_with_no_spaces  r   r   c                 t    |j                  d      }|d   |d   z   |d   z
  }t        j                  ||       y )Nz`E.E` + `F-F` - Ar  r  r)   r  r  s       r   test_special_charactersz9TestDataFrameQueryBacktickQuoting.test_special_characters  s<    gg)*ERY&C0
sF+r   c                 h    |j                  d      }|d   |d   z   }t        j                  ||       y )Nz	A + `1e1`r)   r  r  r  s       r   test_start_with_digitz7TestDataFrameQueryBacktickQuoting.test_start_with_digit  r   r   c                 h    |j                  d      }|d   |d   z   }t        j                  ||       y )Nz	A + `def`r)   r  r  r  s       r   test_keywordz.TestDataFrameQueryBacktickQuoting.test_keyword  r   r   c                 h    |j                  d      }||d   dkD     }t        j                  ||       y )Nz`A` > 2r)   r,   r  r  s       r   test_unneeded_quotingz7TestDataFrameQueryBacktickQuoting.test_unneeded_quoting  s1    hhy!BsGaK
c6*r   c                 h    |j                  d      }||d   dkD     }t        j                  ||       y )Nz`A (x)` > 2r  r,   r  r  s       r   test_parenthesisz2TestDataFrameQueryBacktickQuoting.test_parenthesis  s2    hh}%BwK!O$
c6*r   c                 h    |j                  d      }||d   dkD     }t        j                  ||       y )Nz`` > 5r   r   r  r  s       r   test_empty_stringz3TestDataFrameQueryBacktickQuoting.test_empty_string  s1    hhx BrFQJ
c6*r   c                 h    |j                  d      }||d   dkD     }t        j                  ||       y )Nz
`C  C` > 5r	  r   r  r  s       r   test_multiple_spacesz6TestDataFrameQueryBacktickQuoting.test_multiple_spaces  s2    hh|$BvJN#
c6*r   c                 h    |j                  d      }|d   |d   z   }t        j                  ||       y )Nz` A` + `  `r  r  r  r  s       r   test_start_with_spacesz8TestDataFrameQueryBacktickQuoting.test_start_with_spaces  s2    ggm$DBtH$
sF+r   c                 h    |j                  d      }||d   dkD     }t        j                  ||       y )Nu"   `  &^ :!€$?(} >    <++*''  ` > 4r  rZ   r  r  s       r   test_lots_of_operators_stringz?TestDataFrameQueryBacktickQuoting.test_lots_of_operators_string  s6    hh;<B56:;
c6*r   c                     d}t        j                  t        |      5  |j                  d       d d d        y # 1 sw Y   y xY w)Nz(module 'pandas' has no attribute 'thing'rM   z	@pd.thing)r#   rO   AttributeErrorrB   )r0   r1   messages      r   test_missing_attributez8TestDataFrameQueryBacktickQuoting.test_missing_attribute  s6    <]]>9 	!GGK 	! 	! 	!	   9Ac                     d}t        j                  t        |      5  |j                  d       d d d        y # 1 sw Y   y xY w)N6(Could not convert ).*( to a valid Python identifier.)rM   z`it's` > `that's`r#   rO   r(  r?   r   s      r   test_failing_quotez4TestDataFrameQueryBacktickQuoting.test_failing_quote  s7    G]];c2 	*HH()	* 	* 	*rA  c                     d}t        j                  t        |      5  |j                  d       d d d        y # 1 sw Y   y xY w)NrC  rM   u	   `☺` > 4rD  r   s      r   $test_failing_character_outside_rangezFTestDataFrameQueryBacktickQuoting.test_failing_character_outside_range   s6    G]];c2 	"HH[!	" 	" 	"rA  c                     d}t        j                  t        |      5  |j                  d       d d d        y # 1 sw Y   y xY w)NzFailed to parse backticksrM   z`foo#bar` > 4rD  r   s      r   test_failing_hashtagz6TestDataFrameQueryBacktickQuoting.test_failing_hashtag%  s6    )]];c2 	&HH_%	& 	& 	&rA  c                 6   d }|g}|j                  d       t        j                  t        d      5  |j                  d       ddd       t        j                  t        d      5  |j                  d       ddd       y# 1 sw Y   ?xY w# 1 sw Y   yxY w)z
        Only attributes and variables ('named functions') can be called.
        .__call__() is not an allowed attribute because that would allow
        calling anything.
        https://github.com/pandas-dev/pandas/pull/32460
        c                       yr7   r   )r   s    r   r  zNTestDataFrameQueryBacktickQuoting.test_call_non_named_expression.<locals>.func2  s    r   z@func()z"Only named functions are supportedrM   z@funcs[0]()Nz@funcs[0].__call__())rB   r#   rO   r!  )r0   r1   r  funcss       r   test_call_non_named_expressionz@TestDataFrameQueryBacktickQuoting.test_call_non_named_expression*  s    	 
	]]9,PQ 	#GGM"	# ]]9,PQ 	,GG*+	, 	,	# 	#	, 	,s   B(BBBc                    t        ddgddggddg|      }t        rt        nd }t        j                  |      5  |j                  d      }d d d        t        g d	g d
gg d|      }t        j                  |       y # 1 sw Y   6xY w)Nr+   r,   r-   rZ   r   r   rk   r  z	c = b - ar  )r-   rZ   r+   r7  r   r
   r  r@   r  rB   rA   )r0   any_numeric_ea_and_arrow_dtyper1   r  rE   r|   s         r   test_ea_dtypesz0TestDataFrameQueryBacktickQuoting.test_ea_dtypes?  s    VaVsCj8V
 %6.4''0 	*WW[)F	*	"#0

 	fh/	* 	*   BB
c                    t        ddgddggddgd      }t        rt        nd }t        j                  |      5  |j                  d	      }d d d        t        g d
g dgg dd      }t        j                  |       y # 1 sw Y   6xY w)Nr+   r,   r-   rZ   r   r   Float64rO  z	c = b - 1r  )r-   rZ   r-   r7  rP  )r0   r1   r  rE   r|   s        r   test_ea_dtypes_and_scalarz;TestDataFrameQueryBacktickQuoting.test_ea_dtypes_and_scalarN  s    AA'#s9M$5.4''0 	*WW[)F	*	"O9
 	fh/	* 	*rS  c           	         t        ddgddggddg|      }|j                  d      }t        t        ddg|	      t        ddg|	      t        ddg|d
   j                  	      d      }t	        j
                  ||       y )Nr+   r,   r-   rZ   r   r   rO  z	c = 2 - 1r  r   r7  )r   rB   r   r  r@   rA   )r0   rQ  r1   rE   r|   s        r   #test_ea_dtypes_and_scalar_operationzETestDataFrameQueryBacktickQuoting.test_ea_dtypes_and_scalar_operationY  s    VaVsCj8V
 %QF*HIQF*HIQF&+*;*;<
 	fh/r   r  )r  Int64int64[pyarrow]c                 p   |dk(  rt        j                  d       t        dt        ddg|      i      }dh}|dk(  rt        rt
        nd }t        j                  |      5  |j                  d      }d d d        t        dt        dg|dg	      i      }t        j                  |       y # 1 sw Y   ;xY w)
NrZ  pyarrowr   r+   r,   r  rY  z	a in @refr  rj   )
r#   importorskipr   r   r
   r  r@   r  r?   rA   )r0   r  r1   refr  rE   r|   s          r   test_query_ea_dtypesz6TestDataFrameQueryBacktickQuoting.test_query_ea_dtypesh  s    $$	*VQF%89:c$)W$49J.PT''0 	+XXk*F	+c61#U1##FGH
fh/	+ 	+s    B,,B5r!   r   r   c           	         |dk(  rt         nd }|dk(  rt        st        j                  d       |dk(  rt        j                  d       t        t        g dd      t        g d|      d	      }t        j                  |      5  |j                  d
|      }d d d        t        t        ddgdddg      t        ddg|ddg      d	      }t        j                  |       y # 1 sw Y   NxY w)Nr   znumexpr not installedrZ  r\  )r+   r+   r,   rY  r  )r+   r,   r,   r   zA == BrH   r+   r,   r   r]  )r  r
   r#   r$   r^  r   r   r@   r  r?   rA   )r0   r  r!   r  r1   rE   r|   s          r   !test_query_ea_equality_comparisonzCTestDataFrameQueryBacktickQuoting.test_query_ea_equality_comparisonu  s     %+i$7.TY'8KK/0$$	*'2	QV9WX
 ''0 	7XXhvX6F	7QF'!Q@QF%1v>
 	fh/	7 	7s   C&&C/c                 
   t         j                  j                  d      }t        dt        j                  d d gd      it
              }|j                  d      }t        dg it
              }t        j                  ||       y )NUTCr   T)utcr  za > @now)	r   	Timestampnowr   to_datetimer  r?   r@   rA   )r0   rg  r1   rE   r|   s        r   test_all_nat_in_objectz8TestDataFrameQueryBacktickQuoting.test_all_nat_in_object  sd    llu%R^^T4LdCDFS*%c2Yf5
fh/r   N)$rS   rT   rU   r#   rV   r1   r  r  r  r"  r$  r&  r(  r*  r,  r.  r0  r2  r4  r6  r8  r:  r<  r@  rE  rG  rI  rM  rR  rV  rX  r   r   r`  rb  ri  r   r   r   r  r    s   ^^
 
B+
+
,
,
,
,
,
,
,
,
,
+
+
+
+
,
+
!
*
"
&
,*0	00 [[W&JK
0 L
0 [[X)'<=[[W&JK0 L >0(0r   r  )'ru  numpyrr   r#   pandas.errorsr   r   pandas.util._test_decoratorsutil_test_decoratorstdr   r   r   r   r   r   r	   pandas._testing_testingr@   pandas.core.computation.checkr
   rV   r   r   
skip_if_nor!   r%   r'   rX   r   r   ry  r  r  r  r  r  r   r   r   <module>rt     sT      * )    ; (+= > lfll9MBMM)4LMN	=
01 01f`- `-FGI GIT yv0 v0 v0r yu!&E u! u!p0%D 0*0%D 0*Z* Z*z? ?4s0 s0r   