
    PiK              	          d dl Z d dlm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j        d ej        d                    gd 	          d             Zd Z G d d          Z G d d          Z  G d d          Z! ej        d           G d d                      Z" ej        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(dS )$    N)
TokenError)NumExprClobberingErrorUndefinedVariableError)	DataFrameIndex
MultiIndexSeries
date_range)NUMEXPR_INSTALLEDpythonpandasc                     | S N xs    v/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/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    | dk    rt          j        d|             d S d S )Nr   zcannot evaluate with parser=)pytestskip)r   s    r   skip_if_no_pandas_parserr&   &   s4    ;6;;<<<<< 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dS )	
TestCompatc                 (    t          dg di          S )NA         r   selfs    r   dfzTestCompat.df,   s    #yyy)***r   c                 $    ||j         dk             S )Nr   r*   r1   r2   s     r   	expected1zTestCompat.expected10   s    "$(|r   c                     |j         dz   S Nr,   r4   r5   s     r   	expected2zTestCompat.expected24   s    taxr   c                     |                     d          }t          j        ||           |                    d          }t          j        ||           d S )NA>0A+1querytmassert_frame_equalevalassert_series_equalr1   r2   r6   r9   results        r   test_query_defaultzTestCompat.test_query_default8   sN     %
fi000
vy11111r   c                     |                     dd           }t          j        ||           |                    dd           }t          j        ||           d S )Nr;   r"   r<   r=   rC   s        r   test_query_NonezTestCompat.test_query_None@   sX    %--
fi000t,,
vy11111r   c                     |                     dd          }t          j        ||           |                    dd          }t          j        ||           d S )Nr;   r   rG   r<   r=   rC   s        r   test_query_pythonzTestCompat.test_query_pythonF   sX    %11
fi000x00
vy11111r   c                    t           rZ|                    dd          }t          j        ||           |                    dd          }t          j        ||           d S d}t          j        t          |          5  |                    dd           d d d            n# 1 swxY w Y   t          j        t          |          5  |                    dd           d d d            d S # 1 swxY w Y   d S )Nr;   r   rG   r<   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?   r@   rA   rB   r$   raisesImportError)r1   r2   r6   r9   rD   msgs         r   test_query_numexprzTestCompat.test_query_numexprL   s{    	1XXeIX66F!&)444WWU9W55F"6955555! 
 {#666 2 2y1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2{#666 1 1i0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s$   ?B##B'*B'	C..C25C2N)__name__
__module____qualname__r$   fixturer2   r6   r9   rE   rH   rJ   rQ   r   r   r   r(   r(   +   s        ^+ + ^+ ^  ^ ^  ^2 2 22 2 22 2 21 1 1 1 1r   r(   c                       e Zd Zej                            dddg          ej                            dg d          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S )TestDataFrameEvaln   i  zop_str,op,rop))+__add____radd__)-__sub____rsub__)*__mul____rmul__)/__truediv____rtruediv__c                 t   t          dt          |          t          d                    }d|j        d<   |                                }t          t          j        |j        |                              |d          t          d                    }t          d| d	          }t          d
| d	          }	t          j        |	|           |dv r0 t          ||          |          }	t          j        |	|           d S |dv r0 t          ||          |          }	t          j        |	|           d S d S )Nr,   abcdindexcolumnsr-   r   rj   zbase z dfzm )rZ   r`   )r]   rc   )r   rangelistilocmeannptilevaluesreshaperA   r?   r@   getattr)
r1   op_stroproprX   r2   mbaseexpectedrD   s
             r   test_opszTestDataFrameEval.test_ops`   sF    qa$v,,???
GGIIGAHa  ((B//f
 
 
 ++++,, &6&&&''
fh/// $WR__Q''F!&(33333 :%WR%%a((F!&(33333 r   c                 n   t          dt          j                            d                              d          i          }t          j        |j        dd<   dt          j        |j        dd                   z
  }dt          j        |          z
  j        dd         }t          j	        ||           d S )Nr*   r-   ia  r      r,      )
r   rq   randomdefault_rngstandard_normalnanro   isnanr?   r@   )r1   r2   r{   rD   s       r   test_dataframe_sub_numexpr_pathz1TestDataFrameEval.test_dataframe_sub_numexpr_path   s     RY22155EEeLLMNNv!rx"...bhrll"(2.
fh/////r   c                 Z   t          g dg dd          }d}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 )Nr+   )abr   r*   Bz%expr must be a string to be evaluatedrL   c                     | j         dk    S )Nr   )r   r   s    r   r   z6TestDataFrameEval.test_query_non_str.<locals>.<lambda>   s    qscz r   o   r   r$   rN   
ValueErrorr>   r1   r2   rP   s      r   test_query_non_strz$TestDataFrameEval.test_query_non_str   s.   YYY___==>>5]:S111 	+ 	+HH))***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ ]:S111 	 	HHSMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s#   AAA=B  B$'B$c                     t          dg di          }d}t          j        t          |          5  |                    d           d d d            d S # 1 swxY w Y   d S )Nr*   r+   zexpr cannot be an empty stringrL    r   r   s      r   test_query_empty_stringz)TestDataFrameEval.test_query_empty_string   s    YYY'((.]:S111 	 	HHRLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                 0   t          t          d          t          d          t          d          d                              ddi          }|                    d||          }t          g dgg d	d
g          }t	          j        ||           d S )Nr.   )r*   r   Cr   r*   rl   zC == 1r"   r   )r,   r,   r,   )r*   r*   r   r,   )rj   ri   )r   rm   renamer>   r?   r@   )r1   r"   r   r2   resexpects         r    test_query_duplicate_column_namez2TestDataFrameEval.test_query_duplicate_column_name   s    U1XXE!HH588DDEELL#J M 
 
 hhxvh>>III;sKKK
c6*****r   c                 h   t          t          j                            d                              d          t          d                    }ddi}ddi}|                    d||g	          |d         |d         z   k    sJ t          j        d||g	          |d         |d         z   k    sJ d S )
Nr-   
   r-   abrl   r   r,   r   a + b	resolvers)r   rq   r   r   r   rn   rA   pd)r1   r2   dict1dict2s       r   test_eval_resolvers_as_listz-TestDataFrameEval.test_eval_resolvers_as_list   s    I!!!$$44W==tDzz
 
 
 aawww5%.w99U3Z%PS*=TTTTTww5%.999U3Z%PS*=TTTTTTTr   c                 8   t          t          j                            d                              d          t          d                    }ddi}|                    d|g          }|d         |d	         |d         z  z   }t          j        ||           d S )
Nr-   r   r   rl   cz	a + b * cr   r   r   )	r   rq   r   r   r   rn   rA   r?   rB   )r1   r2   r   rD   r{   s        r   test_eval_resolvers_combinedz.TestDataFrameEval.test_eval_resolvers_combined   s    I!!!$$44W==tDzz
 
 
 a 88c7RWuSz11
vx00000r   c                     t          dddgi          }|                    d          }t          ddgddgd          }t          j        ||           d S )Na1YNzc = ((a1 == 'Y') & True)TF)r   r   )r   rA   r?   r@   )r1   r2   r   r{   s       r   test_eval_object_dtype_binopz.TestDataFrameEval.test_eval_object_dtype_binop   s`    sCj)**gg011S#JdE]CCDD
c8,,,,,r   c                     t          |           t          g dd                                          }|                    d||          }t	          j        |d                   }t          j        ||           d S )Ng?g      ?gffffff@r   namez@np.floor(a)r   )r&   r	   to_framerA   rq   floorr?   rB   r1   r"   r   r2   r   r{   s         r   test_using_numpyz"TestDataFrameEval.test_using_numpy   su     (((OOO#...7799ggnVFgCC8BsG$$
x-----r   c                     t          g dd                                          }|                    d||          }|d         }t          j        ||           d S )Nr   r   r   r   )r	   r   rA   r?   rB   r   s         r   test_eval_simplez"TestDataFrameEval.test_eval_simple   s]    OOO#...7799ggc&g88c7
x-----r   c                    |dk    r5t           j                            d          }|                    |           t	          t          j        g d          t          j        g d          d          }|                    d||          }t          t          j        g d	                    }t          j
        ||           d S )
Nr   z/numexpr does not support extension array dtypes)reasonr+   rY   r~      r   r   za / br   )g      ?g?      ?)r$   markxfailapplymarkerr   r   arrayrA   r	   r?   rB   )r1   r"   r   r   r   r2   rD   r{   s           r   test_extension_array_evalz+TestDataFrameEval.test_extension_array_eval   s    Y;$$H %  D %%%RXiii00rx			7J7JKKLL??"(#5#5#56677
vx00000r   c                     t          dgdgd          }|                    d||          }t          dg          }t          j        ||           d S )Ny      ?       @y      ?      ?r   za/br   y      ?      ?)r   rA   r	   r?   rB   )r1   r"   r   r2   rD   r{   s         r   test_complex_evalz#TestDataFrameEval.test_complex_eval   sZ    fXVH5566vf==:,''
vx00000r   N)rR   rS   rT   r$   r   parametrizer|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rW   rW   ^   s       [S1d),,[	
 	
 	
 4 4  -,480 0 0	 	 	  	+ 	+ 	+U U U1 1 1- - -. . .. . .
1 
1 
11 1 1 1 1r   rW   c                   &    e Zd Zd Zd Zd Zd ZdS ) TestDataFrameQueryWithMultiIndexc                 \   t          |           t          j                            d                              ddgd          }t          j                            d                              ddgd          }t          j        ||gdd	g
          }t          t          j                            d                              d          |          }t          |j
                            d          j        |d          }|                    d||          }|                    d||          }	||dk             }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||dk             }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||                    dg                   }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||                    dg                    }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||                    dg                   }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||                    dg                    }
t          j        ||
           t          j        |	|
           d S )Nr-   redgreenr   sizeeggshamcolorfoodnamesr   ri   ri   r   z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&   rq   r   r   choicer   from_arraysr   r   r	   ri   get_level_valuesrs   r>   r?   r@   isinr1   r   r"   r   r   ri   r2   indres1res2exps              r    test_query_with_named_multiindexzATestDataFrameQueryWithMultiIndex.test_query_with_named_multiindex   sz    (((I!!!$$++UG,<2+FFI!!!$$++VUO"+EE&1vgv5FGGGry,,Q//??HHPUVVVH%%g..5U
 
 

 xx(xGGxx(xGG
dC(((
dC((( xx(xGGxx(xGG
dC(((
dC((( xx*6&xIIxx*6&xII5'""#
dC(((
dC(((xx*6&xIIxx*6&xII#((E7###$
dC(((
dC((( xx*6&xIIxx(xGG5'""#
dC(((
dC(((xx.vfxMMxx,VFxKK#((E7###$
dC(((
dC(((((r   c                    t          |           t          j                            d                              ddgd          }t          j                            d                              ddgd          }t          j        ||g          }t          t          j                            d                              d          |	          }t          |j
                            d
          j        |	          }|                    d||          }|                    d||          }	||dk             }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||dk             }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||                    dg                   }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||                    dg                    }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||                    dg                   }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||                    dg                    }
t          j        ||
           t          j        |	|
           t          |j
                            d          j        |	          }|                    d||          }|                    d||          }	||dk             }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||dk             }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d||          }	||                    dg                   }
t          j        ||
           t          j        |	|
           |                    d||          }|                    d ||          }	||                    dg                    }
t          j        ||
           t          j        |	|
           |                    d!||          }|                    d"||          }	||                    dg                   }
t          j        ||
           t          j        |	|
           |                    d#||          }|                    d$||          }	||                    dg                    }
t          j        ||
           t          j        |	|
           d S )%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   s    (((I!!!$$++UG,<2+FFI!!!$$++VUO"+EE&1v..ry,,Q//??HHPUVVVRX..q118FFFxx+F6xJJxx+F6xJJ
dC(((
dC((( xx+F6xJJxx+F6xJJ
dC(((
dC((( xx-fVxLLxx-fVxLL5'""#
dC(((
dC(((xx-fVxLLxx-fVxLL#((E7###$
dC(((
dC((( xx-fVxLLxx+F6xJJ5'""#
dC(((
dC(((xx1&xPPxx/vxNN#((E7###$
dC(((
dC((( RX..q118FFFxx,VFxKKxx,VFxKK
dC(((
dC((( xx,VFxKKxx,VFxKK
dC(((
dC((( xx.vfxMMxx.vfxMM6(##$
dC(((
dC(((xx.vfxMMxx.vfxMM#((F8$$$%
dC(((
dC((( xx.vfxMMxx,VFxKK6(##$
dC(((
dC(((xx26&xQQxx0xOO#((F8$$$%
dC(((
dC(((((r   c                    t          |           t          j                            d                              ddgd          }t          j        d          }t          j        ||g          }d dg|_        t          t          j                            d          
                    d          |          }|                    d	||
          }t          |j                            d          j        |d          }||dk             }	t!          j        ||	           |                    d||
          }t          |j                            d          j        |d          }||dk             }	t!          j        ||	           |                    d||
          }t          |j                            d          j        |          }||dk             }	t!          j        ||	           |                    d||
          }t          |j                            d          j        |          }||dk             }	t!          j        ||	           d S )Nr-   r   r   r   r   ratingr   r   zrating == 1r   r   r,   zrating != 1r   r   r   )r&   rq   r   r   r   aranger   r   r   r   r   r>   r	   ri   r   rs   r?   r@   )
r1   r   r"   r   r   ri   r2   r   r   r   s
             r   *test_query_with_partially_named_multiindexzKTestDataFrameQueryWithMultiIndex.test_query_with_partially_named_multiindexx  s+    (((I!!!$$++UG,<2+FFIbMM&1v..X&ry,,Q//??HHPUVVVhh}VFhCCH%%h//6e(
 
 
 l
c3'''hh}VFhCCH%%h//6e(
 
 
 l
c3'''hh*6&hIIRX..q118FFF
c3'''hh*6&hIIRX..q118FFF
c3'''''r   c           	      t   t          t          j        d          t          j        d t          d          D             ddg                    }|                                }d }|j                                        }|j	        | ||j	        d           ||j	        d          |d	}|
                                D ]w\  }}t          |t                    r|                    ||                   sJ 8t          |t                    rt          j        |||                    it#          d
          d S )Nr   r.   c                 ,    g | ]}t          d           S )r   )rm   ).0_s     r   
<listcomp>z^TestDataFrameQueryWithMultiIndex.test_query_multiindex_get_index_resolvers.<locals>.<listcomp>  s    ---qr---r   r-   spamr   r   r   c                 f    |                      |          }|                                }| |_        |S r   )r   	to_seriesri   )milevellevel_valuesss       r   r   z]TestDataFrameQueryWithMultiIndex.test_query_multiindex_get_index_resolvers.<locals>.to_series  s2    ..u55L&&((AAGHr   )ri   rj   r   r   clevel_0z object must be a Series or Index)r   rq   onesr   r   rm   _get_index_resolversrj   r   ri   items
isinstancer   is_r	   r?   rB   AssertionError)r1   r2   r   r   
col_seriesr{   kvs           r   )test_query_multiindex_get_index_resolverszJTestDataFrameQueryWithMultiIndex.test_query_multiindex_get_index_resolvers  sa   GG(--E!HH---ff5E  
 
 
 ++--		 	 	 Z))++
X!Ibh//Ibh//"
 
 OO%% 	I 	IDAq!U## IuuXa[))))))Av&& I&q(1+6666$%GHHH	I 	Ir   N)rR   rS   rT   r   r   r   r   r   r   r   r   r      sZ        0) 0) 0)dV) V) V)p( ( (>I I I I Ir   r   c                   F   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                            ddej         gdej!        gg          d             Z"d Z#d Z$dS ) TestDataFrameQueryNumExprPandasc                     dS Nr   r   r0   s    r   r"   z&TestDataFrameQueryNumExprPandas.engine      yr   c                     dS Nr   r   r0   s    r   r   z&TestDataFrameQueryNumExprPandas.parser      xr   c                    t          |           t          t          j                            d                              d                    }t          dd          |d<   t          dd          |d<   t          d	d          |d
<   |                    d||          }||j        dk     d|j	        k     z           }t          j        ||           d S )Nr-   r~   r.   1/1/2012r~   periodsdates11/1/2013dates21/1/2014dates3z"@df.dates1 < 20130101 < @df.dates3r   20130101)r&   r   rq   r   r   r   r
   r>   r  r  r?   r@   r1   r"   r   r2   r   expecs         r   %test_date_query_with_attribute_accesszETestDataFrameQueryNumExprPandas.test_date_query_with_attribute_access  s     (((ry,,Q//??GGHH!*a8888!*a8888!*a8888hh0  
 
 BI
*zBI/EFG
c5)))))r   c                    t          t          j                            d                              d                    }t          dd          |d<   t          dd          |d<   t          d	d          |d
<   |                    d||          }||j        dk     d|j        k     z           }t          j
        ||           d S )Nr-   r
  r  r~   r  r  r  r  r  r  dates1 < 20130101 < dates3r   r  r   rq   r   r   r   r
   r>   r  r  r?   r@   r  s         r   #test_date_query_no_attribute_accesszCTestDataFrameQueryNumExprPandas.test_date_query_no_attribute_access  s    ry,,Q//??GGHH!*a8888!*a8888!*a8888hh3F6hRRBI
*zBI/EFG
c5)))))r   c                    d}t          t          j                            d                              |df                    }t          d|          |d<   t          d|          |d<   t          d	|          |d
<   t          j        |j        t          j                            d                              |          dk    df<   t          j        |j        t          j                            d                              |          dk    d
f<   |	                    d||          }||j
        dk     d|j        k     z           }t          j        ||           d S )Nr   r-   r.   r  r  r  r  r  r  r  r   r  r   r  r   rq   r   r   r   r
   r   NaTlocr>   r  r  r?   r@   r1   r"   r   rX   r2   r   r  s          r   test_date_query_with_NaTz8TestDataFrameQueryNumExprPandas.test_date_query_with_NaT  s2   ry,,Q//??AGGHH!*a8888!*a8888!*a8888EGVry$$Q''..q11C7ABEGVry$$Q''..q11C7ABhh3F6hRRBI
*zBI/EFG
c5)))))r   c                    d}t          t          j                            d                              |df                    }t          d|          |d<   t          d|          |d<   |                    dd	d	
          }|J |                    d||          }||j        dk     d|j	        k     z           }t          j        ||           d S )Nr   r-   r.   r  r  r  r  r  Tinplacedropindex < 20130101 < dates3r   r  r   rq   r   r   r   r
   	set_indexr>   ri   r  r?   r@   r1   r"   r   rX   r2   return_valuer   r  s           r   test_date_index_queryz5TestDataFrameQueryNumExprPandas.test_date_index_query  s    ry,,Q//??AGGHH!*a8888!*a8888||Hd|FF###hh26&hQQBHz)j29.DEF
c5)))))r   c                    d}t          t          j                            d                              |df                                        dt          i          }t          d|          |d<   t          d|          |d	<   t          j	        |j
        d
<   |                    ddd          }|J |                    d||          }||j        dk     d|j        k     z           }t          j        ||           d S )Nr   r-   r.   r   r  r  r  r  r  r   r   Tr"  r%  r   r  r   rq   r   r   r   astypeobjectr
   r   r  ro   r'  r>   ri   r  r?   r@   r(  s           r   test_date_index_query_with_NaTz>TestDataFrameQueryNumExprPandas.test_date_index_query_with_NaT  s    ry,,Q//??AGGHHOOK
 
 "*a8888!*a8888||Hd|FF###hh26&hQQBHz)j29.DEF
c5)))))r   c                     d}i }t          d|          |d<   t          d|          |d<   t          |          }t          j        |j        t
          j                            d                              |          dk    df<   |                    dd	d	
          }|J |	                    d||          }||j
                                        dk     d|j        k     z           }t          j        ||           d S )Nr   r  r  r  r  r  r-   r   Tr"  r  r   r  )r
   r   r   r  r  rq   r   r   r'  r>   ri   r   r  r?   r@   )	r1   r"   r   rX   dr2   r)  r   r  s	            r   )test_date_index_query_with_NaT_duplicateszITestDataFrameQueryNumExprPandas.test_date_index_query_with_NaT_duplicates  s     Q777( Q777(q\\EGVry$$Q''..q11C7AB||Hd|FF###hh3F6hRRBH&&((:5*ry:PQR
c5)))))r   c                    d}t          t          d|d          t          j        |          d          }|                    d||          }t          |          dk    sJ |                    d	||          }t          j        ||           d
}dD ]Q}t          j	        t          |          5  |                    d| d||           d d d            n# 1 swxY w Y   Rd S )Nr   r  ns)r  unit)datesnondatezdates == nondater   r   zdates != nondatez=Invalid comparison between dtype=datetime64\[ns\] and ndarray)<><=>=rL   zdates z nondate)r   r
   rq   r   r>   lenr?   r@   r$   rN   	TypeError)r1   r"   r   rX   r2   rD   rP   rw   s           r   test_date_query_with_non_datez=TestDataFrameQueryNumExprPandas.test_date_query_with_non_date	  s[   #JEEE9Q<< 
 
 ,VFKK6{{a,VFKK
fb)))N( 	N 	NBy444 N N."...vfMMMN N N N N N N N N N N N N N N	N 	Ns   2CC	"C	c                    t          t          d          t          dd          t          dd          d          }d}t          j        t          |          5  |                    d	||
           d d d            d S # 1 swxY w Y   d S )Nr   r.      rY      )irZ   rinvalid syntaxrL   zi - +r   )r   rm   r$   rN   SyntaxErrorr>   )r1   r"   r   r2   rP   s        r   test_query_syntax_errorz7TestDataFrameQueryNumExprPandas.test_query_syntax_error  s    U2YYU1b\\aMMNN];c222 	< 	<HHWVFH;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   B  BBc                    t          |           t          t          j                            d                              d          t          d                    }d\  }}|                    d||          }||j        |j	        k             }t          j        ||           |                    d||          }|||j	        k             }t          j        ||           t          j        t          d	
          5  |                    d||           d d d            n# 1 swxY w Y   t          j        t          d
          5  |                    d||           d d d            d S # 1 swxY w Y   d S )Nr-   )   r-   r   rl   )r,   r-   za > br   z@a > b!local variable 'c' is not definedrL   z@a > b > @czname 'c' is not definedz
@a > b > c)r&   r   rq   r   r   r   rn   r>   r   r   r?   r@   r$   rN   r   )r1   r"   r   r2   r   r   r   r{   s           r   test_query_scopez0TestDataFrameQueryNumExprPandas.test_query_scope#  s    (((I!!!$$44W==tDzz
 
 
 1hhwvfh==bdRTk?
c8,,,hhxvh>>a"$h<
c8,,, ]"*M
 
 
 	B 	B HH]6&HAAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B ]19RSSS 	A 	AHH\&H@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	As$   ?D$$D(+D(
E00E47E4c                 J   dx}}t          t          j                            d                              ||df          t          d                    }t          j        t          d          5  |	                    d	||
           d d d            d S # 1 swxY w Y   d S )Nr   r-   r.   r   abcrl   zname 'sin' is not definedrL   sin > 5r   )
r   rq   r   r   integersrn   r$   rN   r   r>   )r1   r"   r   rX   ry   r2   s         r   test_query_doesnt_pickup_localz>TestDataFrameQueryNumExprPandas.test_query_doesnt_pickup_local=  s    
AI!!!$$--aq!f-==tE{{
 
 

 ]19TUUU 	> 	>HHYvfH===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   2BBBc                 f   dx}}t          t          j                            d                              ||df          t          d                    }d|j        _        d}t          j	        t          |	          5  |                    d
||           d d d            d S # 1 swxY w Y   d S )Nr   r-   r.   r   rM  rl   sinzVariables in expression.+rL   rN  r   )r   rq   r   r   rO  rn   ri   r   r$   rN   r   r>   )r1   r"   r   rX   ry   r2   rP   s          r   test_query_builtinz2TestDataFrameQueryNumExprPandas.test_query_builtinG  s    
AI!!!$$--aq!f-==tE{{
 
 
 )]1=== 	> 	>HHYvfH===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s    B&&B*-B*c                    t          t          j                            d                              d          g d          }t          j        |                    d||          ||j        |j	        k                         t          j        |                    d||          ||j        |j	        z   |j	        |j
        z  k                        d S )Nr-   r   r   r   r   rl   a < br   za + b > b * c)r   rq   r   r   r   r?   r@   r>   r   r   r   r1   r"   r   r2   s       r   
test_queryz*TestDataFrameQueryNumExprPandas.test_queryR  s    I!!!$$44W==
 
 
 	HHWVFH;;Rrt_	
 	
 	
 	HH_VFHCCrtbd{RTBD[()	
 	
 	
 	
 	
r   c                    t          t          j                            d                              dd          t          t          d          d          g d          }|                    d	||
          }||j        dk     |j	        |j
        k     z           }t          j        ||           |                    d||
          }||j        |j
        k              }t          j        ||           d S )Nr-   r   r   r   blobr   rU  rh   z(blob < 5) & (a < b)r   r~   zblob < b)r   rq   r   r   rO  r   rm   r>   ri   r   r   r?   r@   r  s         r   test_query_index_with_namez:TestDataFrameQueryNumExprPandas.test_query_index_with_name_  s    I!!!$$--bw-??b		///#OO
 
 

 hh-fVhLLBHqLRTBD[12
c5)))hhz&h@@28bd?#
c5)))))r   c                    t          t          j                            d                              dd          t          d          g d          }|                    d||          }||j        |j        k              }t          j
        ||           |                    d	||          }||j        d
k              }t          j
        ||           d S )Nr-   r   r   r   rU  rh   z	index < br   z	index < 5r~   )r   rq   r   r   rO  rm   r>   ri   r   r?   r@   r  s         r   test_query_index_without_namez=TestDataFrameQueryNumExprPandas.test_query_index_without_namen  s    I!!!$$--bw-??))#OO
 
 
 hh{6&hAA28bd?#
c5))) hh{6&hAA28a< 
c5)))))r   c                     t          |           t          t          j                            d                              d                    }t          t          j                            d                              d                    }||dk    |dk    z           }|                    d||          }t          j        ||           t          j
        d||          }t          j        ||           t          j
        d||          }||dk    |dk    z  ||dk             dk    z           }t          j        ||           t          j
        d||          }|                    d	||          }t          j        ||           d S )
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   rq   r   r   r   r>   r?   r@   r   rA   )r1   r"   r   r2   df2r{   rD   s          r   test_nested_scopez1TestDataFrameQueryNumExprPandas.test_nested_scope  st    (((ry,,Q//??GGHH	--a00@@HHIIrAv#'*+26&QQ
fh///1&PPP
fh///7v
 
 
 rAv#'*baj1n=>
fh////vNNN8808OO
fh/////r   c                    t          t          j                            d                              d                    }t          j        t          d          5  |                    d||           d d d            d S # 1 swxY w Y   d S )Nr-   r
  name 'df' is not definedrL   zdf > 0r   )	r   rq   r   r   r   r$   rN   r   r>   rW  s       r   *test_nested_raises_on_local_self_referencezJTestDataFrameQueryNumExprPandas.test_nested_raises_on_local_self_reference  s    ry,,Q//??GGHH ]19STTT 	= 	=HHXfVH<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s   BBBc                    t          |           t          t          j                            d                              d          t          d                    }d}||j        |k              }|                    d||          }t          j
        ||           ||j        |j        k              }|                    d||          }t          j
        ||           d S )	Nr-   )d   r   
abcdefghijrl   r,   za < @br   rV  )r&   r   rq   r   r   r   rn   r   r>   r?   r@   r   )r1   r"   r   r2   r   r   rD   s          r   test_local_syntaxz1TestDataFrameQueryNumExprPandas.test_local_syntax  s     (((I!!!$$44Y??&&
 
 
 BD1H(6&AA
ff---BD24K'&@@
ff-----r   c                    t          |           t          d          }t          t          j                            d                              dt          |          f          |          }|                    d||          }|j	        |j
        k     |j
        |j        k     z  |j
                            |j	                   z  |j                            |j
                   z  }||         }t          j        ||           d S )NrM  r-   rf  rl   z!a < b < c and a not in b not in cr   )r&   rn   r   rq   r   r   r   r=  r>   r   r   r   r   r?   r@   )r1   r"   r   colsr2   r   r   r  s           r   test_chained_cmp_and_inz7TestDataFrameQueryNumExprPandas.test_chained_cmp_and_in  s     (((E{{I!!!$$44c3t995EFFPT
 
 
 hh/v  
 
 tbd{rtbd{+rtyy.>>"$))BD//AQQ3
c5)))))r   c                 $   t          |           t          t          j                            d                              dd          d          }t          t          j                            d                              dd          d          }t          ||d	          }|j        |j        d
z
  	                    |                   }|
                    d||          }t          j        ||           t          t          j                            d                              dd          d          }|j        |d
z
  	                    |                   }|
                    d||          }t          j        ||           d S )Nr-   r.      r   r   r   r   r   r   r,   z
b - 1 in ar   z@b - 1 in a)r&   r	   rq   r   r   rO  r   r  r   r   r>   r?   r@   )r1   r"   r   r   r   r2   r{   rD   s           r   test_local_variable_with_inz;TestDataFrameQueryNumExprPandas.test_local_variable_with_in  sV    (((29((++44QR4@@sKKK29((++44Rb4AALLLQQ''((624!8//!,,-,vfEE
h///29((++44Rb4AALLL61q5,,q//*-vFF
h/////r   c                     t          |           d}t          dg di          }|                    d||          }||j        dk             }t	          j        ||           d S )Nr,   r   )r   r   r   r   @crp  z	a == "@c"r   rp  r&   r   r>   r   r?   r@   )r1   r"   r   r   r2   rD   r{   s          r   test_at_inside_stringz5TestDataFrameQueryNumExprPandas.test_at_inside_string  sn     (((===>??+fVDDbddl#
fh/////r   c                 t   | j         | j        }}t          |           t          t          j                            d                              d          t          d                    }t          j	        t          d          5  |                    d||           d d d            d S # 1 swxY w Y   d S )	Nr-   r   r   rl   rJ  rL   za == @cr   )r"   r   r&   r   rq   r   r   rn   r$   rN   r   r>   rW  s       r   test_query_undefined_localz:TestDataFrameQueryNumExprPandas.test_query_undefined_local  s    dk (((ry,,Q//66w??dTTT]"*M
 
 
 	> 	> HHYvfH===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   B--B14B1c                 @   d}t           j        ddd         }t          |t           j                            d                              |j                  d          }d|j        _        |	                    d||          }||d         d	k             }t          j        ||           t          |t           j                            d                              |j                  d          }|	                    d
||          }|j        |j        |j        d	k                      }t          j        ||           t          |t           j                            d                              |j                  d          }d|j        _        |	                    d||          }||j        d	k             }t          j        ||           |	                    d||          }|j        |j        |j        d	k                      }t          j        ||           d S )Nr,   rI  e   r-   )ri   r   ri   z	index > 5r   r~   zilevel_0 > 5r   r   za > 5)rq   r_r   r   r   r   r   ri   r   r>   r?   r@   r  r   )r1   r"   r   rX   r   r2   rD   r{   s           r   :test_index_resolvers_come_after_columns_with_the_same_namezZTestDataFrameQueryNumExprPandas.test_index_resolvers_come_after_columns_with_the_same_name  s    E"S)bi33A66FFqvNNOO
 
  +fVDDbkAo&
fh///bi33A66FFqvNNOO
 
 .GG6"(28a<01
fh///QRY%:%:1%=%=%M%Maf%U%UVVWW'&@@bdQh<
fh///+fVDD6"(28a<01
fh/////r   zop, f==!=c                    d}t          t          j                            d                              |          t          j                            d                              |          d          }t          j        |j        d d ddf<   d| d}| ||j        t          j                           }|                    |||          }	t          j	        |	|           d S )Nr   r-   r   r   a z infr   )
r   rq   r   r   infr  r   r>   r?   r@   )
r1   rw   fr"   r   rX   r2   qr{   rD   s
             r   test_infz(TestDataFrameQueryNumExprPandas.test_inf  s    Y**1--44Q77Y**1--44Q77 
 
 sssAvMMMaabfoo&!F6::
fh/////r   c                 \   |}t          ddd|d          }t          |          }t          |          }|                    d          }t          j        ||           t          |          }|                                                    d          }t          j        ||           d S )Nz
2019-01-011Dr   time)startfreqr  tzr   r   z"2018-01-03 00:00:00+00" < time)r
   r   r>   r?   r@   reset_index)r1   tz_aware_fixturer  df_indexr{   r2   rD   s          r   test_check_tz_aware_index_queryz?TestDataFrameQueryNumExprPandas.test_check_tz_aware_index_query	  s    T2"6
 
 
 8,,,X&&&;<<
fh///X&&!!''(IJJ
fh/////r   c           	         d}t          dt          j                            d                              |          z  t          j                            d                              |          d          }||d                             d          dk             }|                    d||          }t          j        ||           t          t          j        t          j                            d                              |          d	k     t          j	        t          j                            d          
                    |                    t          j                            d          
                    |          d          }||d                                                  }|                    d
||          }t          j        ||           d S )Nr   r-   r   r   intr   za.astype('int') == 0r   r   za.notnull())r   rq   r   r   r.  r>   r?   r@   wherer   r   notnull)r1   r"   r   rX   r2   r{   rD   s          r   test_method_calls_in_queryz:TestDataFrameQueryNumExprPandas.test_method_calls_in_query  s   ..q1188;;;Y**1--44Q77 
 
 bgnnU++q010OO
fh///XI))!,,33A66<FI))!,,<<Q?? 
 Y**1--==a@@ 	
 	
 bgoo''(-vFF
fh/////r   N)%rR   rS   rT   r$   rU   r"   r   r  r  r   r*  r0  r3  r?  rG  rK  rP  rS  rX  r[  r]  ra  rd  rh  rk  rn  rr  rt  rx  r   r   operatoreqner  r  r  r   r   r   r  r    s       ^  ^ ^  ^
* 
* 
** * *
* 
* 
*	* 	* 	** * ** * *N N N(< < <A A A4> > >	> 	> 	>
 
 
* * ** * *"0 0 0.= = =. . . * * *0 0 00 0 0> > >0 0 0> [Whk':T8;<O&PQQ0 0 RQ00 0 00 0 0 0 0r   r  c                   x    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
S )TestDataFrameQueryNumExprPythonc                     dS r  r   r0   s    r   r"   z&TestDataFrameQueryNumExprPython.engine6  r  r   c                     dS Nr   r   r0   s    r   r   z&TestDataFrameQueryNumExprPython.parser:  r  r   c                    t          t          j                            d                              d                    }t          dd          |d<   t          dd          |d<   t          d	d          |d
<   |                    d||          }||j        dk     d|j        k     z           }t          j
        ||           d S )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    ry,,Q//??GGHH!*a8888!*a8888!*a8888hh7v  
 
 BI
*zBI/EFG
c5)))))r   c                    d}t          t          j                            d                              |df                    }t          d|          |d<   t          d|          |d<   t          d	|          |d
<   t          j        |j        t          j                            d                              |          dk    df<   t          j        |j        t          j                            d                              |          dk    d
f<   |	                    d||          }||j
        dk     d|j        k     z           }t          j        ||           d S )Nr   r-   r.   r  r  r  r  r  r  r  r   r  r   r  r  r  s          r   r   z8TestDataFrameQueryNumExprPython.test_date_query_with_NaTI  s;   ry,,Q//??AGGHH!*a8888!*a8888!*a8888EGVry$$Q''..q11C7ABEGVry$$Q''..q11C7ABhh7v  
 
 BI
*zBI/EFG
c5)))))r   c                    d}t          t          j                            d                              |df                    }t          d|          |d<   t          d|          |d<   |                    dd	d	
          }|J |                    d||          }||j        dk     d|j	        k     z           }t          j        ||           d S )Nr   r-   r.   r  r  r  r  r  Tr"  ((index < 20130101) & (20130101 < dates3)r   r  r&  r(  s           r   r*  z5TestDataFrameQueryNumExprPython.test_date_index_queryW  s    ry,,Q//??AGGHH!*a8888!*a8888||Hd|FF###hh6vf  
 
 BHz)j29.DEF
c5)))))r   c                    d}t          t          j                            d                              |df                                        dt          i          }t          d|          |d<   t          d|          |d	<   t          j	        |j
        d
<   |                    ddd          }|J |                    d||          }||j        dk     d|j        k     z           }t          j        ||           d S )Nr   r-   r.   r   r  r  r  r  r  r,  Tr"  r  r   r  r-  r(  s           r   r0  z>TestDataFrameQueryNumExprPython.test_date_index_query_with_NaTd  s   ry,,Q//??AGGHHOOK
 
 "*a8888!*a8888||Hd|FF###hh6vf  
 
 BHz)j29.DEF
c5)))))r   c                 D   d}t          t          j                            d                              |df                    }t          d|          |d<   t          d|          |d<   t          j        |j        t          j                            d                              |          d	k    df<   |	                    dd
d
          }|J d}t          j        t          |          5  |                    d||           d d d            d S # 1 swxY w Y   d S )Nr   r-   r.   r  r  r  r  r  r   Tr"  "'BoolOp' nodes are not implementedrL   r%  r   )r   rq   r   r   r   r
   r   r  r  r'  r$   rN   NotImplementedErrorr>   )r1   r"   r   rX   r2   r)  rP   s          r   r3  zITestDataFrameQueryNumExprPython.test_date_index_query_with_NaT_duplicatesu  sg   ry,,Q//??AGGHH!*a8888!*a8888EGVry$$Q''..q11C7AB||Hd|FF###3].c::: 	P 	PHH0HOOO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Ps   /DDDc                    d}t          j        d||          }|dk    sJ t          t          j                            d                              d                    }t          t          j                            d                              d                    }d}t          j        t          |          5  |
                    d||           d d d            n# 1 swxY w Y   t          j        t          d	          5  |
                    d
||           d d d            n# 1 swxY w Y   ||dk    |dk    z           }t          j        d||          }t          j        ||           ||dk    |dk    z  ||dk             dk    z           }t          j        d||          }t          j        ||           d S )Nr,   zx + 1r   r-   r
  z5The '@' prefix is only supported by the pandas parserrL   r_  rc  z(df>0) & (df2>0)r   zdf[(df > 0) & (df2 > 0)]z+df[(df > 0) & (df2 > 0) & (df[df > 0] > 0)])r   rA   r   rq   r   r   r   r$   rN   rF  r>   r   r?   r@   )	r1   r"   r   r   rD   r2   r`  rP   r{   s	            r   ra  z1TestDataFrameQueryNumExprPython.test_nested_scope  sX   ???{{{{ry,,Q//??GGHH	--a00@@HHII G];c222 	I 	IHH)&HHHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I ]19STTT 	G 	GHH'vHFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G rAv#'*+3F6RRR
h///rAv#'*baj1n=>9&QW
 
 
 	h/////s$   =C""C&)C&D--D14D1c                 \   t          g dg dd          }d}t          j        t          |          5  |                    d           d d d            n# 1 swxY w Y   d}t          j        t          |          5  |                    d           d d d            d S # 1 swxY w Y   d S )	Nr+   r   )minmaxzMVariables in expression \"\(min\) == \(1\)\" overlap with builtins: \('min'\)rL   zmin == 1zMVariables in expression \"\(max\) == \(1\)\" overlap with builtins: \('max'\)zmax == 1)r   r$   rN   r   r>   )r1   r2   regex_to_matchs      r   +test_query_numexpr_with_min_and_max_columnszKTestDataFrameQueryNumExprPython.test_query_numexpr_with_min_and_max_columns  s@   yyy;;<<0 	 ]1HHH 	! 	!HHZ   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!0 	 ]1HHH 	! 	!HHZ   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s#   AAA>B!!B%(B%N)rR   rS   rT   r$   rU   r"   r   r  r   r*  r0  r3  ra  r  r   r   r   r  r  4  s        ^  ^ ^  ^	* 	* 	** * ** * ** * *"
P 
P 
P0 0 06! ! ! ! !r   r  c                   T    e Zd Zej        d             Zej        d             Zd ZdS )TestDataFrameQueryPythonPandasc                     dS r  r   r0   s    r   r"   z%TestDataFrameQueryPythonPandas.engine  r  r   c                     dS r  r   r0   s    r   r   z%TestDataFrameQueryPythonPandas.parser  r  r   c                 F   dx}}t          t          j                            d                              ||df          t          d                    }d|j        _        ||j        dk             }|                    d	||
          }t          j
        ||           d S Nr   r-   r.   r   rM  rl   rR  r~   rN  r   r   rq   r   r   rO  rn   ri   r   r>   r?   r@   r1   r"   r   rX   ry   r2   r{   rD   s           r   rS  z1TestDataFrameQueryPythonPandas.test_query_builtin      
AI!!!$$--aq!f-==tE{{
 
 
 bhl#)F6BB
h/////r   NrR   rS   rT   r$   rU   r"   r   rS  r   r   r   r  r    [        ^  ^ ^  ^	0 	0 	0 	0 	0r   r  c                   T    e Zd Zej        d             Zej        d             Zd ZdS )TestDataFrameQueryPythonPythonc                     dS r  r   r0   s    r   r"   z%TestDataFrameQueryPythonPython.engine  r  r   c                     dS r  r   r0   s    r   r   z%TestDataFrameQueryPythonPython.parser  r  r   c                 F   dx}}t          t          j                            d                              ||df          t          d                    }d|j        _        ||j        dk             }|                    d	||
          }t          j
        ||           d S r  r  r  s           r   rS  z1TestDataFrameQueryPythonPython.test_query_builtin  r  r   Nr  r   r   r   r  r    r  r   r  c            
       2   e Zd Zd Zd Zd Zd Zd Zd Ze	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
                            dg dg dg dg dg dg dg          d             ZdS )TestDataFrameQueryStringsc           	         t          t          j                            d                              d          dg          }t          t          d                    |d<   ||j        dk             }|dk    rd}d	}|gdz  |gdz  z   }|d d d
         }d\  }	}
d|	|
gz  }d}t          |||          D ]c\  }}}| d| d| }t          j
        t          |          5  |                    |||d|j        i           d d d            n# 1 swxY w Y   dd S |                    d||          }t          j        ||           |                    d||          }t          j        ||           t          j        |||j                            dg                              ||j        dk             }|                    d||          }t          j        ||           |                    d||          }t          j        ||           t          j        |||j                            dg                               d S )Nr-   r   r,   r   rl   
aabbccddeestringsr   r   z"a"rk   ry  rz  $'(Not)?In' nodes are not implemented rL   )r"   r   
local_dictz"a" == stringsr   zstrings == "a"zstrings != "a"z"a" != strings)r   rq   r   r   r   r	   rn   r  zipr$   rN   r  r>   r?   r@   r   )r1   r   r"   r2   r   collstlhsrhsr  r  opsrP   lhop_rhexr   s                     r   test_str_query_methodz/TestDataFrameQueryStrings.test_str_query_method  s   ry,,Q//??HHSVRWXXXtL11229BJ#%&XCC%!)seai'Cddd)CFBBx.C9C"3S11  C''S''2'']#6cBBB  HH%%$-rz#:	                    ((+F6(JJC!#v...((+F6(JJC!#v...!#r"*//3%*@*@'ABBB
c)*F((+F6(JJC!#v...((+F6(JJC!#v...!#r2:??C5+A+A*A'BCCCCCs   !DD	D	c                    t          t          j                            d                              d          dg          }t          t          d                    |d<   ||j                            ddg                   }|dk    rd}d	}|gdz  |gdz  z   }|d d d
         }d\  }	}
d|	|
gz  }d}t          |||          D ][\  }}}| d| d| }t          j        t          |          5  |                    |||           d d d            n# 1 swxY w Y   \d S |                    d||          }t          j        ||           |                    d||          }t          j        ||           ||j                            ddg                    }|                    d||          }t          j        ||           |                    d||          }t          j        ||           d S )Nr-   r  r   rl   r  r  r   r   z
["a", "b"]rk   r  r  r  rL   r   zstrings == ["a", "b"]z["a", "b"] == stringszstrings != ["a", "b"]z["a", "b"] != strings)r   rq   r   r   r   r	   rn   r  r   r  r$   rN   r  r>   r?   r@   )r1   r   r"   r2   r   r  r  r  r  r  r  r  rP   r  ops_r  r  r   s                     r   test_str_list_query_methodz4TestDataFrameQueryStrings.test_str_list_query_method  s]   ry,,Q//??HHSVRWXXXtL11229BJOOS#J//0XCC%!)seai'Cddd)CFBBx.C9C #Cc 2 2 ? ?D"((T((B((]#6cBBB ? ?HHRvH>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?
 ((26&(QQC!#v...((26&(QQC!#v...#s4445F((26&(QQC!#v...((26&(QQC!#v.....s   0DD	D	c           	         t          t          d          t          d          t          j                            d                              dd          t          j                            d                              dd          d          }|d	k    r|                    d
||          }||j                            |j	                           }t          j        ||           |                    d||          }||j                            |j	                  |j        |j        k     z           }t          j        ||           d S d}t          j        t           |          5  |                    d
||           d d d            n# 1 swxY w Y   d}t          j        t           |          5  |                    d||           d d d            d S # 1 swxY w Y   d S )Naaaabbbbccccaabbccddeeffr-   r~      r   	   r   r   r   r2  r   za in br   za in b and c < dr  rL   r  )r   rn   rq   r   r   rO  r>   r   r   r   r?   r@   r   r2  r$   rN   r  )r1   r   r"   r2   r   r  rP   s          r   test_query_with_string_columnsz8TestDataFrameQueryStrings.test_query_with_string_columns$  si   .)).))Y**1--66qr6BBY**1--66qr6BB	 
 
 X((8F6(BBCrtyy'E!#u---((-fV(LLCrtyy"$+67E!#u-----9C2#>>> A A&@@@A A A A A A A A A A A A A A A 8C2#>>> K K+F6JJJK K K K K K K K K K K K K K K K K Ks$   -FFF:G  G$'G$c           	      6   t          t          d          t          d          t          j                            d                              dd          t          j                            d                              dd          d          }|                    d	||
          }||j        |j        k             }t          j
        ||           |                    d||
          }||j        |j        k             }t          j
        ||           d S )Nr  r  r-   r~   r  r   r  r  za == br   za != b)r   rn   rq   r   r   rO  r>   r   r   r?   r@   )r1   r   r"   r2   r   r   s         r   test_object_array_eq_nez1TestDataFrameQueryStrings.test_object_array_eq_ne>  s    .)).))Y**1--66qr6BBY**1--66qr6BB	 
 
 hhxvh>>
c3'''hhxvh>>
c3'''''r   c                    t          |           d t          dd          D             dz  }t          ddd          }t          d	dd          }t          t	          j        dd
                              d          ||                    |          d          }||j        dk             }|	                    d||          }t          j        ||           d S )Nc                 (    g | ]}d D ]
}d| d| S ))loadexitzpage r  r   )r   rX   acts      r   r   zLTestDataFrameQueryStrings.test_query_with_nested_strings.<locals>.<listcomp>Q  sK     
 
 
"#>N
 
7:A
 
 
 
r   r,   rY   r-   z2014-01-01 0:00:0130sr   )r  r  z2014-02-01 1:00:01   )idevent	timestampz"page 1 load"z'"page 1 load"' in eventr   )r&   rm   r
   r   rq   r   repeatappendr  r>   r?   r@   )	r1   r   r"   eventsstamps1stamps2r2   r{   r   s	            r   test_query_with_nested_stringsz8TestDataFrameQueryStrings.test_query_with_nested_stringsO  s     (((
 
',Q{{
 
 
 1qIII1qIIIi1oo,,Q//$^^G44 
 
 bh/12hh5fVhTT
h,,,,,r   c                     t          |           t          g dg dd          }|                    d||          }||j        dk             }t	          j        ||           d S )N)r   r   test & testr+   r   za == "test & test"r   r  rq  )r1   r   r"   r2   r   r  s         r   (test_query_with_nested_special_characterzBTestDataFrameQueryStrings.test_query_with_nested_special_characterb  sr     (((666YYYGGHHhh+F6hJJ24=()
c5)))))r   zop, funcr9  r:  r;  r<  c                    t          t          j                            d                              t          d          d                    }t          t          j        |j                            }t          ||d          }|	                    d| d||          }| ||j
        d                   }	t          j        ||	           d S )	Nr-   abcderI  )Xr   zX z "d"r   r2  )r	   rq   r   r   r   rn   r   r   r   r>   r  r?   r@   )
r1   r   r"   rw   funcr   r   r2   r   r{   s
             r   test_query_lex_compare_stringsz8TestDataFrameQueryStrings.test_query_lex_compare_stringsi  s     29((++224=="EEFF29QV$$%%QQ''((hh}B}}}VFhCCdd24oo&
c8,,,,,r   c                 f   d}t           j                            d                              ddt	          |          f                              t                    }t          ||          }|                    d||          }||j	        |j
        z           }t          j        ||           d S )N)bidbidsizeaskasksizer-   r,   r   rl   z	bid & askr   )rq   r   r   rO  r=  r.  boolr   r>   r  r  r?   r@   )r1   r   r"   rj   datar2   r   r{   s           r   "test_query_single_element_booleansz<TestDataFrameQueryStrings.test_query_single_element_booleans{  s    4y$$Q''00!S\\9J0KKRRSWXXtW---hh{6&hAAbfrvo&
c8,,,,,r   c                     t          |           t          g dg dd          }||j        dk             }d}|                    d||          }t	          j        ||           d S )N)BUD USr  IBM USr  )gl[@gGzn[@gf@g33333f@)SymbolPricer  zSymbol == @symbr   )r&   r   r  r>   r?   r@   )r1   r   r"   r2   esymbrD  s          r   !test_query_string_scalar_variablez;TestDataFrameQueryStrings.test_query_string_scalar_variable  s     (((BBB999 
 
 ryH$%HH&vfHEE
a#####r   in_list)Nasdfghjk)r  Nr  )r  r  N)NNr  )r  NN)NNNc                 Z   d}d}d t          |          D             }t          d|id          }|j                            d          |_        t          d|id          }t	          t          |j                  |j        j                  |_        |                    d||	          }||d         d
k             }|                    d||	          }	t          j	        ||           t          j	        ||           t          j	        ||	           t          j	        ||	           d S )Nr   r   c                 &    i | ]\  }}|d k    ||S )r  r   )r   rC  values      r   
<dictcomp>zMTestDataFrameQueryStrings.test_query_string_null_elements.<locals>.<dictcomp>  s#    SSSE5F??Au???r   r   stringdtypeint64za == 'asdf'r   r  za <= 'asdf')
	enumerater   ri   r.  r   rn   r	  r>   r?   r@   )
r1   r   r   r"   r{   df_expectedr2   r   r   res3s
             r   test_query_string_null_elementsz9TestDataFrameQueryStrings.test_query_string_null_elements  s!    SSYw-?-?SSShx@@@'-44W==W~X666bhrx~>>>xxfVxDD"S'V#$xxfVxDD
dK000
dD)))
dD)))
dD)))))r   N)rR   rS   rT   r  r  r  r  r  r  r$   r   r   r  ltgtleger  r  r  r  r   r   r   r  r    sb       'D 'D 'DR!/ !/ !/FK K K4( ( ("- - -&* * * [(+(+8;8;		
 - - -- - -$ $ $ ["""""""""      	

 
* *
 
* * *r   r  c                       e Zd Zej        d             Zd Zd Zej        	                    dg d          d             Z
dS )TestDataFrameEvalWithFramec                     t          t          j                            d                              d          t          d                    S )Nr-   r   rM  rl   )r   rq   r   r   r   rn   r0   s    r   framez TestDataFrameEvalWithFrame.frame  sB    I!!!$$44W==tE{{
 
 
 	
r   c                 ~    |                     d||          }|j        |j        z   }t          j        ||           d S )Nr   r   rA   r   r   r?   rB   r1   r  r   r"   r   r   s         r   test_simple_exprz+TestDataFrameEvalWithFrame.test_simple_expr  s@    jjj??57"
sF+++++r   c                     |                     d||          }|j        |j        dk              |j        z   }t          j        ||           d S )Nza[a < 1] + br   r,   r  r  s         r   test_bool_arith_exprz/TestDataFrameEvalWithFrame.test_bool_arith_expr  sK    jjvjFF1%/
sF+++++r   rw   )rZ   r]   r`   rc   c                     t          ddgddgd          }d}t          j        t          |          5  |                    d| d	||
           d d d            d S # 1 swxY w Y   d S )Nr,   r-   r   r2  r   z:unsupported operand type\(s\) for .+: '.+' and '.+'|CannotrL   r|  z br   )r   r$   rN   r>  rA   )r1   r   r"   rw   r2   rP   s         r   %test_invalid_type_for_operator_raisesz@TestDataFrameEvalWithFrame.test_invalid_type_for_operator_raises  s    aV3*5566K]9C000 	? 	?GGKKKKvG>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   AA"%A"N)rR   rS   rT   r$   rU   r  r  r  r   r   r  r   r   r   r  r    s        ^
 
 ^

, , ,
, , ,
 [T#7#7#788? ? 98? ? ?r   r  c                   Z   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d Zd Z d Z!d Z"d Z#ej$        %                    d g d!          d"             Z&d# Z'd$ Z(d% Z)d& Z*d' Z+d( Z,d) Z-d* Z.d+ Z/d, Z0d- Z1d. Z2ej$        %                    d/g d0          d1             Z3ej$        %                    d2d3d4g          ej$        %                    d/g d0          d5                         Z4d6 Z5d7S )8!TestDataFrameQueryBacktickQuotingc                     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g d&g d'd(          S ))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  rY   r.   C_C)   r  r   D_D D)   r,   rv  E.E)r   r.   r~   F-F)r&  r,   r   1e1)r-   rY   r&  def)r   r(  r-   A (x))rY   r,   r.   zB(x))r,   r,   r~   zB (x))r-   r  rY        &^ :!€$?(} >    <++*''  )r-   r~   r   r   )r   r(  r,    A)rY   r  r    r,   r-   r,   )r   r.   r,   )r  r,   r&  )r&  r  r   )r-   rY   r~   )r~   r  r  )it'sthat's   ☺
   xy （z）   xy （z\uff09foo#barr,   r/   r0   s    r   r2   z$TestDataFrameQueryBacktickQuoting.df  si    YYYyyy yyy 				
 zzz  yyy zzz yyy {{{  			  /			 KKK  iii!" iii#$ "		#)) yy'ii"+))$99991  
 
 	
r   c                 ~    |                     d          }|d|d         k              }t          j        ||           d S )Nz	1 < `B B`r,   r"  r>   r?   r@   r1   r2   r   r   s       r   #test_single_backtick_variable_queryzETestDataFrameQueryBacktickQuoting.test_single_backtick_variable_query  s>    hh{##A5	M"
c6*****r   c                     |                     d          }|d|d         k     d|d         k     z           }t          j        ||           d S )Nz1 < `B B` and 4 < `C C`r,   r"  rY   r#  r9  r:  s       r   !test_two_backtick_variables_queryzCTestDataFrameQueryBacktickQuoting.test_two_backtick_variables_query  sL    hh011QE]q2e9}56
c6*****r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )Nz	A + `B B`r*   r"  rA   r?   rB   r:  s       r   "test_single_backtick_variable_exprzDTestDataFrameQueryBacktickQuoting.test_single_backtick_variable_expr  >    ggk""C2e9$
sF+++++r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )Nz`B B` + `C C`r"  r#  r?  r:  s       r    test_two_backtick_variables_exprzBTestDataFrameQueryBacktickQuoting.test_two_backtick_variables_expr  s>    ggo&&ERY&
sF+++++r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )Nz	`C_C` + Ar%  r*   r?  r:  s       r    test_already_underscore_variablezBTestDataFrameQueryBacktickQuoting.test_already_underscore_variable  s>    ggk""ERW$
sF+++++r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )NzC_C + `C C`r%  r#  r?  r:  s       r   test_same_name_but_underscoresz@TestDataFrameQueryBacktickQuoting.test_same_name_but_underscores  s>    ggm$$ERY&
sF+++++r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )NzA + `D_D D`r*   r'  r?  r:  s       r   !test_mixed_underscores_and_spaceszCTestDataFrameQueryBacktickQuoting.test_mixed_underscores_and_spaces  s>    ggm$$C2g;&
sF+++++r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )Nz	A + `C_C`r*   r%  r?  r:  s       r   'test_backtick_quote_name_with_no_spaceszITestDataFrameQueryBacktickQuoting.test_backtick_quote_name_with_no_spaces  rA  r   c                     |                     d          }|d         |d         z   |d         z
  }t          j        ||           d S )Nz`E.E` + `F-F` - Ar)  r*  r*   r?  r:  s       r   test_special_charactersz9TestDataFrameQueryBacktickQuoting.test_special_characters  sH    gg)**ERY&C0
sF+++++r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )Nz	A + `1e1`r*   r+  r?  r:  s       r   test_start_with_digitz7TestDataFrameQueryBacktickQuoting.test_start_with_digit  rA  r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )Nz	A + `def`r*   r,  r?  r:  s       r   test_keywordz.TestDataFrameQueryBacktickQuoting.test_keyword  rA  r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nz`A` > 2r*   r-   r9  r:  s       r   test_unneeded_quotingz7TestDataFrameQueryBacktickQuoting.test_unneeded_quoting$  s=    hhy!!BsGaK
c6*****r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nz`A (x)` > 2r-  r-   r9  r:  s       r   test_parenthesisz2TestDataFrameQueryBacktickQuoting.test_parenthesis)  s>    hh}%%BwK!O$
c6*****r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nz`` > 5r   r~   r9  r:  s       r   test_empty_stringz3TestDataFrameQueryBacktickQuoting.test_empty_string.  s=    hhx  BrFQJ
c6*****r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nz
`C  C` > 5r$  r~   r9  r:  s       r   test_multiple_spacesz6TestDataFrameQueryBacktickQuoting.test_multiple_spaces3  s>    hh|$$BvJN#
c6*****r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )Nz` A` + `  `r/  r0  r?  r:  s       r   test_start_with_spacesz8TestDataFrameQueryBacktickQuoting.test_start_with_spaces8  s>    ggm$$DBtH$
sF+++++r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nz`1` == 7r,   r  r9  r:  s       r   	test_intsz+TestDataFrameQueryBacktickQuoting.test_ints=  s=    hhz""BqEQJ
c6*****r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nu"   `  &^ :!€$?(} >    <++*''  ` > 4r.  rY   r9  r:  s       r   test_lots_of_operators_stringz?TestDataFrameQueryBacktickQuoting.test_lots_of_operators_stringB  sB    hh;<<B56:;
c6*****r   c                     d}t          j        t          |          5  |                    d           d d d            d S # 1 swxY w Y   d S )Nz(module 'pandas' has no attribute 'thing'rL   z	@pd.thing)r$   rN   AttributeErrorrA   )r1   r2   messages      r   test_missing_attributez8TestDataFrameQueryBacktickQuoting.test_missing_attributeG  s    <]>999 	! 	!GGK   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   AAAc                     |                     d          }||d         |d         k             }t          j        ||           d S )Nz`it's` > `that's`r2  r3  r9  r:  s       r   
test_quotez,TestDataFrameQueryBacktickQuoting.test_quoteL  sD    hh*++BvJH-.
c6*****r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nu	   `☺` > 4r4  rY   r9  r:  s       r   #test_character_outside_range_smileyzETestDataFrameQueryBacktickQuoting.test_character_outside_range_smileyQ  s>    hh{##BuIM"
c6*****r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nu   `xy （z）` == 2r5  r-   r9  r:  s       r   *test_character_outside_range_2_byte_parenszLTestDataFrameQueryBacktickQuoting.test_character_outside_range_2_byte_parensV  sA    hh*++B|$)*
c6*****r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nu   `xy （z\uff09` == 2r6  r-   r9  r:  s       r   1test_character_outside_range_and_actual_backslashzSTestDataFrameQueryBacktickQuoting.test_character_outside_range_and_actual_backslash\  sB    hh.//B*+q01
c6*****r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nz`foo#bar` > 4r7  rY   r9  r:  s       r   test_hashtagz.TestDataFrameQueryBacktickQuoting.test_hashtagb  s?    hh''ByMA%&
c6*****r   c                     t          ddg          }|                    d          }||d         dk              }t          j        ||           d S )Nr+   a#rl   z`a#` < 2r-   r   r>   r?   r@   r1   r2   rD   r{   s       r   1test_expr_with_column_name_with_hashtag_characterzSTestDataFrameQueryBacktickQuoting.test_expr_with_column_name_with_hashtag_characterg  sR    y4&111*%%bhl#
fh/////r   c                     t          ddg          }|                    d          }||d         dk              }t          j        ||           d S )Nr+   ro  rl   z`a#` < 2  # This is a commentr-   rp  rq  s       r   test_expr_with_commentz8TestDataFrameQueryBacktickQuoting.test_expr_with_commentn  sS    y4&1119::bhl#
fh/////r   c                     t          ddg          }|                    d          }||d         dk              }t          j        ||           d S )Nr+   za`#brl   z`a``#b` < 2r-   rp  rq  s       r   1test_expr_with_column_name_with_backtick_and_hashzSTestDataFrameQueryBacktickQuoting.test_expr_with_column_name_with_backtick_and_hashu  sR    y6(333-((bj1n%
fh/////r   c                     t          ddd          }|                    d          }||d         dk              }t          j        ||           d S )Nr+   r   )a`br   z
`a``b` < 2rx  r-   rp  rq  s       r   (test_expr_with_column_name_with_backtickzJTestDataFrameQueryBacktickQuoting.test_expr_with_column_name_with_backtick|  sS    y	::;;,''bi!m$
fh/////r   c                     t          ddg          }|                    d          }|d|d         k              }t          j        ||           d S )N`z`````z
``````````
#backticksrl   z'```' < `#backticks`z```rp  rq  s       r   $test_expr_with_string_with_backtickszFTestDataFrameQueryBacktickQuoting.test_expr_with_string_with_backticks  sV    3l^LLL011eb../
fh/////r   c                     t          ddg          }|                    d          }|d|d         k              }t          j        ||           d S )Nr{  r}  rl   z'`#backticks`' < `#backticks`z`#backticks`rp  rq  s       r   Ctest_expr_with_string_with_backticked_substring_same_as_column_namezeTestDataFrameQueryBacktickQuoting.test_expr_with_string_with_backticked_substring_same_as_column_name  sV    3l^LLL9::nr,'778
fh/////r   zcol1,col2,expr))r2  r3  z`it's` < `that's`)zit"szthat"sz`it"s` < `that"s`)r2  zthat's "nice"z`it's` < `that's "nice"`)r2  zthat's #coolz+`it's` < `that's #cool` # This is a commentc           	          t          |d|di|d|di|d|di|d|dig          }|                    |          }|||         ||         k              }t          j        ||           d S )	Nr,   r-   r.   rY   rk   rp  )r1   col1col2exprr2   rD   r{   s          r   3test_expr_with_column_names_with_special_characterszUTestDataFrameQueryBacktickQuoting.test_expr_with_column_names_with_special_characters  s     q$"q$"r4$r4$	
 
 $bhD)*
fh/////r   c                     t          ddg          }|                    d          }|d|d         k              }t          j        ||           d S )Naaavvvzzzcolumn_namerl   z'value' < column_namer  rp  rq  s       r   test_expr_with_no_backticksz=TestDataFrameQueryBacktickQuoting.test_expr_with_no_backticks  sV    ,}oFFF122g= 112
fh/////r   c                     t          ddg          }t          j        t          t          fd          5  |                    d           d d d            d S # 1 swxY w Y   d S )Nr,   r~   r   column-namerl   rE  rL   z5 < `column-namer   r$   rN   rF  r   r>   r5   s     r   2test_expr_with_no_quotes_and_backtick_is_unmatchedzTTestDataFrameQueryBacktickQuoting.test_expr_with_no_quotes_and_backtick_is_unmatched  s    zM?;;;]K4<LMMM 	) 	)HH'(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)   AAAc                     t          ddg          }|                    d          }|d|d         k              }t          j        ||           d S )Nr  r  rl   z5 < `column-name`r~   rp  rq  s       r   0test_expr_with_no_quotes_and_backtick_is_matchedzRTestDataFrameQueryBacktickQuoting.test_expr_with_no_quotes_and_backtick_is_matched  sU    zM?;;;-..a"]++,
fh/////r   c                     t          ddg          }t          j        t          t          fd          5  |                    d           d d d            d S # 1 swxY w Y   d S )Nr  It'srl   unterminated string literalrL   z	5 < `It'sr  r5   s     r   Etest_expr_with_backtick_opened_before_quote_and_backtick_is_unmatchedzgTestDataFrameQueryBacktickQuoting.test_expr_with_backtick_opened_before_quote_and_backtick_is_unmatched  s    zF8444]*%-J
 
 
 	" 	" HH[!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"r  c                     t          ddg          }|                    d          }|d|d         k              }t          j        ||           d S )Nr  r  rl   z
5 < `It's`r~   rp  rq  s       r   Ctest_expr_with_backtick_opened_before_quote_and_backtick_is_matchedzeTestDataFrameQueryBacktickQuoting.test_expr_with_backtick_opened_before_quote_and_backtick_is_matched  sR    zF8444,''a"V*n%
fh/////r   c                     t          ddg          }t          j        t          t          fd          5  |                    d           d d d            d S # 1 swxY w Y   d S )Nr  r  rl   r  rL   z+`column-name` < 'It`s that\'s "quote" #hashr  r5   s     r   Btest_expr_with_quote_opened_before_backtick_and_quote_is_unmatchedzdTestDataFrameQueryBacktickQuoting.test_expr_with_quote_opened_before_backtick_and_quote_is_unmatched  s    ,}oFFF]*%-J
 
 
 	G 	G HHEFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gr  c                     t          ddg          }|                    d          }||d         dk              }t          j        ||           d S )Nr  r  rl   z,`column-name` < 'It`s that\'s "quote" #hash'It`s that's "quote" #hashrp  rq  s       r   Gtest_expr_with_quote_opened_before_backtick_and_quote_is_matched_at_endziTestDataFrameQueryBacktickQuoting.test_expr_with_quote_opened_before_backtick_and_quote_is_matched_at_end  sW    ,}oFFFKLLb'*FFG
fh/////r   c                     t          ddg          }|                    d          }|d|d         k              }t          j        ||           d S )Nr  r  rl   z,'It`s that\'s "quote" #hash' < `column-name`r  rp  rq  s       r   Gtest_expr_with_quote_opened_before_backtick_and_quote_is_matched_in_midziTestDataFrameQueryBacktickQuoting.test_expr_with_quote_opened_before_backtick_and_quote_is_matched_in_mid  sW    ,}oFFFKLL2R5FFG
fh/////r   c                 ^   d }|g}|                     d           t          j        t          d          5  |                     d           ddd           n# 1 swxY w Y   t          j        t          d          5  |                     d           ddd           dS # 1 swxY w Y   dS )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                      dS r8   r   )r   s    r   r  zNTestDataFrameQueryBacktickQuoting.test_call_non_named_expression.<locals>.func  s    1r   z@func()z"Only named functions are supportedrL   z@funcs[0]()Nz@funcs[0].__call__())rA   r$   rN   r>  )r1   r2   r  funcss       r   test_call_non_named_expressionz@TestDataFrameQueryBacktickQuoting.test_call_non_named_expression  s8   	 	 	 
	]9,PQQQ 	# 	#GGM"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# ]9,PQQQ 	, 	,GG*+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s#   AA A?B""B&)B&c                 :   t          ddgddggddg|          }t          rt          nd }t          j        |          5  |                    d          }d d d            n# 1 swxY w Y   t          g d	g d
gg d|          }t          j        ||           d S )Nr,   r-   r.   rY   r   r   rj   r	  z	c = b - ar1  )r.   rY   r,   rU  r   r   RuntimeWarningr?   assert_produces_warningrA   r@   )r1   any_numeric_ea_and_arrow_dtyper2   warningrD   r{   s         r   test_ea_dtypesz0TestDataFrameQueryBacktickQuoting.test_ea_dtypes  s    VaVsCj8V
 
 
 %6?..4'00 	* 	*WW[))F	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*YY			"#OO0
 
 

 	fh/////   A!!A%(A%c                 :   t          ddgddggddgd          }t          rt          nd }t          j        |          5  |                    d	          }d d d            n# 1 swxY w Y   t          g d
g dgg dd          }t          j        ||           d S )Nr,   r-   r.   rY   r   r   Float64r  z	c = b - 1r1  )r.   rY   r.   rU  r  )r1   r2   r  rD   r{   s        r   test_ea_dtypes_and_scalarz;TestDataFrameQueryBacktickQuoting.test_ea_dtypes_and_scalar  s    AA'#s9MMM$5?..4'00 	* 	*WW[))F	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*YY			"OOO9
 
 
 	fh/////r  c           	      0   t          ddgddggddg|          }|                    d          }t          t          ddg|	          t          ddg|	          t          ddg|d
         j        	          d          }t	          j        ||           d S )Nr,   r-   r.   rY   r   r   r  z	c = 2 - 1r  r   rU  )r   rA   r	   r	  r?   r@   )r1   r  r2   rD   r{   s        r   #test_ea_dtypes_and_scalar_operationzETestDataFrameQueryBacktickQuoting.test_ea_dtypes_and_scalar_operation  s    VaVsCj8V
 
 
 %%QF*HIIIQF*HIIIQF&+*;<<< 
 
 	fh/////r   r	  )r
  Int64int64[pyarrow]c                    |dk    rt          j        d           t          dddgi|          }dh}|dk    rt          rt          nd }t          j        |          5  |                    d          }d d d            n# 1 swxY w Y   t          ddgit          dd          |	          }t          j	        ||           d S )
Nr  pyarrowr   r,   r-   r  r  z	a in @ref)ri   r	  )
r$   importorskipr   r   r  r?   r  r>   rm   r@   )r1   r	  r2   refr  rD   r{   s          r   test_query_ea_dtypesz6TestDataFrameQueryBacktickQuoting.test_query_ea_dtypes   s   $$$	***aV}E222c$)W$4$49J$4..PT'00 	+ 	+XXk**F	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+cA3ZuQ{{%HHH
fh/////s   A??BBr"   r   r   c                 Z   |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  |	                    d
|          }d d d            n# 1 swxY w Y   t          t          ddgdt          ddd                    t          ddg|t          ddd                    d	          }t          j        ||           d S )Nr   znumexpr not installedr  r  )r,   r,   r-   r  r  )r,   r-   r-   r   zA == BrG   r,   r-   r   rY   )r	  ri   )r  r   r$   r%   r  r   r	   r?   r  r>   rm   r@   )r1   r	  r"   r  r2   rD   r{   s          r   !test_query_ea_equality_comparisonzCTestDataFrameQueryBacktickQuoting.test_query_ea_equality_comparison-  s    %+i$7$7..TY'8K/000$$$	***'222			QV9W9W9WXX
 
 '00 	7 	7XXhvX66F	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7QF'q!QHHHQF%uQ1~~FFF 
 
 	fh/////s   B77B;>B;c                 $   t           j                            d          }t          dt          j        d d gd          it
                    }|                    d          }t          dg it
                    }t          j        ||           d S )NUTCr   T)utcr  za > @now)	r   	Timestampnowr   to_datetimer/  r>   r?   r@   )r1   r  r2   rD   r{   s        r   test_all_nat_in_objectz8TestDataFrameQueryBacktickQuoting.test_all_nat_in_objectC  s    lu%%R^T4LdCCCDFSSS*%%c2Yf555
fh/////r   N)6rR   rS   rT   r$   rU   r2   r;  r=  r@  rC  rE  rG  rI  rK  rM  rO  rQ  rS  rU  rW  rY  r[  r]  r_  rc  re  rg  ri  rk  rm  rr  rt  rv  ry  r~  r  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r     s       ^!
 !
 ^!
F+ + +
+ + +
, , ,
, , ,
, , ,
, , ,
, , ,
, , ,
, , ,
, , ,
, , ,
+ + +
+ + +
+ + +
+ + +
, , ,
+ + +
+ + +
! ! !
+ + +
+ + +
+ + ++ + ++ + +
0 0 00 0 00 0 00 0 00 0 00 0 0 [	
 	
 	
 0 0 00 0 0) ) )0 0 0" " "0 0 0G G G0 0 00 0 0, , ,*0 0 0	0 	0 	00 0 0 [W&J&J&JKK
0 
0 LK
0 [X)'<==[W&J&J&JKK0 0 LK >=0(0 0 0 0 0r   r   ))r  tokenizer   numpyrq   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   rU   r   r   
skip_if_nor"   r&   r(   rW   r   r  r  r  r  r  r  r   r   r   r   <module>r     s                      * ) ) ) ) ) ) ) )                        ; ; ; ; ; ; (+===  >= lfl9MBM)4L4LMMMN   	 = = =
01 01 01 01 01 01 01 01fL1 L1 L1 L1 L1 L1 L1 L1^GI GI GI GI GI GI GI GIT yy0 y0 y0 y0 y0 y0 y0 y0x yu! u! u! u! u!&E u! u! u!p0 0 0 0 0%D 0 0 0*0 0 0 0 0%D 0 0 0*T* T* T* T* T* T* T* T*n? ? ? ? ? ? ? ?4A0 A0 A0 A0 A0 A0 A0 A0 A0 A0r   