
    d`                     b   d dl Z d dlZd dlZd dlmZmZ d dlmc m	Z
 d dlZd dlmZmZmZmZmZ d dlmZ d dlmZ  ej        ddgd           d	             Z ej        d ej        d
e
j                  gd           d             Zd Z G d d          Z G d d          Z G d d          Ze
j         G d d                      Z e
j         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)NumExprClobberingErrorUndefinedVariableError)	DataFrameIndex
MultiIndexSeries
date_range)NUMEXPR_INSTALLEDpythonpandasc                     | S N xs    ^/var/www/html/t/fyr/venv311/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    VW r   c                     | j         S r   r   r   s    r   enginer!      s     =r   c                 ^    | dk    r&t          j        dt          |                       d S d S )Nr   zcannot evaluate with parser )pytestskiprepr)r   s    r   skip_if_no_pandas_parserr&   $   s:    A4<<AABBBBB 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.expected1.   s    "$(|r   c                     |j         dz   S Nr,   r4   r5   s     r   	expected2zTestCompat.expected22   s    taxr   c                     |                     d          }t          j        ||           |                    d          }t          j        ||d           d S )NA>0A+1Fcheck_namesquerytmassert_frame_equalevalassert_series_equalr1   r2   r6   r9   results        r   test_query_defaultzTestCompat.test_query_default6   sS     %
fi000
vyeDDDDDDr   c                     |                     dd           }t          j        ||           |                    dd           }t          j        ||d           d S )Nr;   r!   r<   Fr=   r?   rE   s        r   test_query_NonezTestCompat.test_query_None>   s]    %--
fi000t,,
vyeDDDDDDr   c                     |                     dd          }t          j        ||           |                    dd          }t          j        ||d           d S )Nr;   r   rI   r<   Fr=   r?   rE   s        r   test_query_pythonzTestCompat.test_query_pythonD   s]    %11
fi000x00
vyeDDDDDDr   c                    t           r\|                    dd          }t          j        ||           |                    dd          }t          j        ||d           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   rI   r<   Fr=   z~'numexpr' is not installed or an unsupported version. Cannot use engine='numexpr' for query/eval if 'numexpr' is not installedmatch)	r
   r@   rA   rB   rC   rD   r#   raisesImportError)r1   r2   r6   r9   rF   msgs         r   test_query_numexprzTestCompat.test_query_numexprJ   s    	1XXeIX66F!&)444WWU9W55F"69%HHHHHH! 
 {#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)C00C47C4N)__name__
__module____qualname__r#   fixturer2   r6   r9   rG   rJ   rL   rS   r   r   r   r(   r(   )   s        ^+ + ^+ ^  ^ ^  ^E E EE E EE E E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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   rl   zbase z dfzm )r\   rb   )r_   re   )r   rangelistilocmeannptilevaluesreshaperC   rA   rB   getattr)
r1   op_stroproprZ   r2   mbaseexpectedrF   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                 H   t          dt          j                            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*   ia  r      r,      )	r   rs   randomrandnnanrq   isnanrA   rB   )r1   r2   r}   rF   s       r   test_dataframe_sub_numexpr_pathz1TestDataFrameEval.test_dataframe_sub_numexpr_path   s     RY__U33455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 evaluatedrN   c                     | j         dk    S )Nr   )r   r   s    r   r   z6TestDataFrameEval.test_query_non_str.<locals>.<lambda>   s    qscz r   o   r   r#   rP   
ValueErrorr@   r1   r2   rR   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 stringrN    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                 D   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 )
N
   r-   abrn   r   r,   r   a + b	resolvers)r   rs   r   r   rp   rC   pd)r1   r2   dict1dict2s       r   test_eval_resolvers_as_listz-TestDataFrameEval.test_eval_resolvers_as_list   s    ryr1--tDzzBBB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                    t          t          j                            dd          t	          d                    }ddi}|                    d|g          }|d         |d	         |d         z  z   }t          j        ||           d S )
Nr   r-   r   rn   cz	a + b * cr   r   r   )r   rs   r   r   rp   rC   rA   rD   )r1   r2   r   rF   r}   s        r   test_eval_resolvers_combinedz.TestDataFrameEval.test_eval_resolvers_combined   s    ryr1--tDzzBBB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   rC   rA   rB   )r1   r2   resr}   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   N)rT   rU   rV   r#   markparametrizer~   r   r   r   r   r   r   r   r   r   rY   rY   \   s        [S1d),,[	
 	
 	
 4 4  -,480 0 0	 	 	  U U U	1 	1 	1- - - - -r   rY   c                   &    e Zd Zd Zd Zd Zd ZdS ) TestDataFrameQueryWithMultiIndexc                    t          |           t          j                            ddgd          }t          j                            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 )Nredgreenr   sizeeggshamcolorfood)namesr-   rk   rk   namezcolor == "red"r   r!   z"red" == colorzcolor != "red"z"red" != colorzcolor == ["red"]z["red"] == colorzcolor != ["red"]z["red"] != colorz["red"] in colorz"red" in colorz["red"] not in colorz"red" not in colorr&   rs   r   choicer   from_arraysr   r   r   rk   get_level_valuesru   r@   rA   rB   isinr1   r   r!   r   r   rk   r2   indres1res2exps              r    test_query_with_named_multiindexzATestDataFrameQueryWithMultiIndex.test_query_with_named_multiindex   sO    (((IeW-B77Ife_266&1vgv5FGGGryr1--U;;;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gd          }t          j                            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   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eW-B77Ife_266&1v..ryr1--U;;;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                 j   t          |           t          j                            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   ratingr-   r   zrating == 1r   r   r,   zrating != 1r   r   r   )r&   rs   r   r   aranger   r   r   r   r   r@   r   rk   r   ru   rA   rB   )
r1   r   r!   r   r   rk   r2   r   r   r   s
             r   *test_query_with_partially_named_multiindexzKTestDataFrameQueryWithMultiIndex.test_query_with_partially_named_multiindexF  s    (((IeW-B77IbMM&1v..X&ryr1--U;;;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          j        d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 )
Nr   r.   r-   spamr   )r_idx_nlevelsr_idx_namesc                 f    |                      |          }|                                }| |_        |S r   )r   	to_seriesrk   )milevellevel_valuesss       r   r   z]TestDataFrameQueryWithMultiIndex.test_query_multiindex_get_index_resolvers.<locals>.to_seriesk  s2    ..u55L&&((AAGHr   )rk   rl   r   r   C0z object must be a Series or Index)rA   makeCustomDataframe_get_index_resolversrl   r   rk   items
isinstancer   is_r   rD   AssertionError)r1   r2   r   r   
col_seriesr}   kvs           r   )test_query_multiindex_get_index_resolverszJTestDataFrameQueryWithMultiIndex.test_query_multiindex_get_index_resolverse  s2   #0@
 
 
 ++--		 	 	 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)rT   rU   rV   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                   2   e Zd Zed             Ze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| _         d| _        d S )Nr   r   r!   r   clss    r   setup_classz+TestDataFrameQueryNumExprPandas.setup_class  s    



r   c                     | ` | `d S r   r   r   s    r   teardown_classz.TestDataFrameQueryNumExprPandas.teardown_class  s    J


r   c                    | j         | j        }}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.   1/1/2012periodsdates11/1/2013dates21/1/2014dates3z"@df.dates1 < 20130101 < @df.dates3r   20130101)r!   r   r&   r   rs   r   r   r	   r@   r   r   rA   rB   r1   r!   r   r2   r   expecs         r   %test_date_query_with_attribute_accesszETestDataFrameQueryNumExprPandas.test_date_query_with_attribute_access  s    dk (((ryq!,,--!*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                    | j         | j        }}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   dates1 < 20130101 < dates3r   r   r!   r   r   rs   r   r   r	   r@   r   r   rA   rB   r   s         r   #test_date_query_no_attribute_accesszCTestDataFrameQueryNumExprPandas.test_date_query_no_attribute_access  s    dkryq!,,--!*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                 h   | j         | j        }}d}t          t          j                            |d                    }t          d|          |d<   t          d|          |d<   t          d|          |d	<   t          j        |j	        t          j        
                    |          d
k    df<   t          j        |j	        t          j        
                    |          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   rs   r   r   r	   r   NaTlocrandr@   r   r   rA   rB   r1   r!   r   rZ   r2   r   r   s          r   test_date_query_with_NaTz8TestDataFrameQueryNumExprPandas.test_date_query_with_NaT  s   dkryq!,,--!*a8888!*a8888!*a888846Fry~~a  3&0146Fry~~a  3&01hh3F6hRRBI
*zBI/EFG
c5)))))r   c                    | j         | j        }}d}t          t          j                            |d                    }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   Tinplacedropindex < 20130101 < dates3r   r   r!   r   r   rs   r   r   r	   	set_indexr@   rk   r   rA   rB   r1   r!   r   rZ   r2   return_valuer   r   s           r   test_date_index_queryz5TestDataFrameQueryNumExprPandas.test_date_index_query  s    dkryq!,,--!*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                    | j         | j        }}d}t          t          j                            |d                                        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   r   rs   r   r   astypeobjectr	   r   r   rq   r
  r@   rk   r   rA   rB   r  s           r   test_date_index_query_with_NaTz>TestDataFrameQueryNumExprPandas.test_date_index_query_with_NaT  s    dkryq!,,--44a[AA!*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                    | j         | j        }}d}i }t          d|          |d<   t          d|          |d<   t          |          }t          j        |j        t          j        	                    |          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   Tr  r   r   r   )r!   r   r	   r   r   r   r   rs   r   r  r
  r@   rk   r   r   rA   rB   )	r1   r!   r   rZ   dr2   r  r   r   s	            r   )test_date_index_query_with_NaT_duplicateszITestDataFrameQueryNumExprPandas.test_date_index_query_with_NaT_duplicates  s    dk Q777( Q777(q\\46Fry~~a  3&01||Hd|FF###hh3F6hRRBH&&((:5*ry:PQR
c5)))))r   c                    | j         | j        }}d}t          t          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   r   )datesnondatezdates == nondater   r   zdates != nondatez=Invalid comparison between dtype=datetime64\[ns\] and ndarray)<><=>=rN   zdates z nondate)r!   r   r   r	   rs   r   r@   lenrA   rB   r#   rP   	TypeError)r1   r!   r   rZ   r2   rF   rR   ry   s           r   test_date_query_with_non_datez=TestDataFrameQueryNumExprPandas.test_date_query_with_non_date  sa   dk Q777BIaLLQQ
 
 ,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   ?C((C,	/C,	c                 6   | j         | j        }}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.      r[      )ir\   rzinvalid syntaxrN   zi - +r   )r!   r   r   ro   r#   rP   SyntaxErrorr@   )r1   r!   r   r2   rR   s        r   test_query_syntax_errorz7TestDataFrameQueryNumExprPandas.test_query_syntax_error  s    dkU2YYU1b\\aMMNN];c222 	< 	<HHWVFH;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   (BBBc                    | j         | j        }}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 )N   r-   r   rn   )r,   r-   za > br   z@a > b!local variable 'c' is not definedrN   z@a > b > @czname 'c' is not definedz
@a > b > c)r!   r   r&   r   rs   r   r   rp   r@   r   r   rA   rB   r#   rP   r   )r1   r!   r   r2   r   r   r   r}   s           r   test_query_scopez0TestDataFrameQueryNumExprPandas.test_query_scope  s
   dk (((ryr1--tDzzBBB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$E,,E03E0c                 @   | j         | j        }}dx}}t          t          j                            ||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   abcrn   zname 'sin' is not definedrN   sin > 5r   )r!   r   r   rs   r   randintrp   r#   rP   r   r@   )r1   r!   r   rZ   r{   r2   s         r   test_query_doesnt_pickup_localz>TestDataFrameQueryNumExprPandas.test_query_doesnt_pickup_local  s    dk
Ary((!Q(88$u++NNN ]19TUUU 	> 	>HHYvfH===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   -BBBc                 \   | j         | j        }}dx}}t          t          j                            ||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-  rn   sinzVariables in expression.+rN   r.  r   )r!   r   r   rs   r   r/  rp   rk   r   r#   rP   r   r@   )r1   r!   r   rZ   r{   r2   rR   s          r   test_query_builtinz2TestDataFrameQueryNumExprPandas.test_query_builtin  s    dk
Ary((!Q(88$u++NNN)]1=== 	> 	>HHYvfH===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   ;B!!B%(B%c                    | j         | j        }}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   rn   a < br   za + b > b * c)r!   r   r   rs   r   r   rA   rB   r@   r   r   r   r1   r!   r   r2   s       r   
test_queryz*TestDataFrameQueryNumExprPandas.test_query   s    dkryr1--GGG
HHWVFH;;Rrt_	
 	
 	
 	HH_VFHCCrtbd{RTBD[()	
 	
 	
 	
 	
r   c                    | j         | j        }}t          t          j                            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   blobr   r5  rj   z(blob < 5) & (a < b)r   r   zblob < b)r!   r   r   rs   r   r/  r   ro   r@   rk   r   r   rA   rB   r   s         r   test_query_index_with_namez:TestDataFrameQueryNumExprPandas.test_query_index_with_name,  s    dkIbw//b		///#OO
 
 

 hh-fVhLLBHqLRTBD[12
c5)))hhz&h@@28bd?#
c5)))))r   c                    | j         | j        }}t          t          j                            dd          t          d          g d          }|                    d||          }||j        |j	        k              }t          j        ||           |                    d||          }||j        d	k              }t          j        ||           d S )
Nr   r:  r   r5  rj   z	index < br   z	index < 5r   )r!   r   r   rs   r   r/  ro   r@   rk   r   rA   rB   r   s         r   test_query_index_without_namez=TestDataFrameQueryNumExprPandas.test_query_index_without_name<  s    dkIbw//))#OO
 
 
 hh{6&hAA28bd?#
c5))) hh{6&hAA28a< 
c5)))))r   c                    | j         }| j        }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   r&   r   rs   r   r   r@   rA   rB   r   rC   )r1   r!   r   r2   df2r}   rF   s          r   test_nested_scopez1TestDataFrameQueryNumExprPandas.test_nested_scopeN  sf    (((ryq!,,--	1--..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| j        | j	                   d d d            d S # 1 swxY w Y   d S )Nr   r.   name 'df' is not definedrN   zdf > 0r   )
r   rs   r   r   r#   rP   r   r@   r!   r   r5   s     r   *test_nested_raises_on_local_self_referencezJTestDataFrameQueryNumExprPandas.test_nested_raises_on_local_self_referenceh  s    ryq!,,-- ]19STTT 	G 	GHHXdk$+HFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   	#A99A= A=c                    t          | j                   | j        | j        }}t          t          j                            dd          t          d                    }d}||j        |k              }|	                    d||          }t          j        ||           ||j        |j        k              }|	                    d||          }t          j        ||           d S )	Nd   r   
abcdefghijrn   r,   za < @br   r6  )r&   r   r!   r   rs   r   r   rp   r   r@   rA   rB   r   )r1   r!   r   r2   r   expectrF   s          r   test_local_syntaxz1TestDataFrameQueryNumExprPandas.test_local_syntaxo  s     ---dkrysB//l9K9KLLLBD1H(6&AA
ff---BD24K'&@@
ff-----r   c                    t          | j                   | j        | j        }}t          d          }t	          t
          j                            dt          |                    |          }|	                    d||          }|j
        |j        k     |j        |j        k     z  |j                            |j
                   z  |j                            |j                   z  }||         }t          j        ||           d S )Nr-  rH  rn   z!a < b < c and a not in b not in cr   )r&   r   r!   rp   r   rs   r   r   r  r@   r   r   r   r   rA   rB   )r1   r!   r   colsr2   r   r   r   s           r   test_chained_cmp_and_inz7TestDataFrameQueryNumExprPandas.test_chained_cmp_and_in}  s     ---dkE{{rysCII66EEEhh/v  
 
 tbd{rtbd{+rtyy.>>"$))BD//AQQ3
c5)))))r   c                    | j         | j        }}t          |           t          t          j                            dd          d          }t          t          j                            dd          d          }t          ||d          }|j        |j	        d	z
  
                    |                   }|                    d
||          }t          j        ||           t          t          j                            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   r&   r   rs   r   r/  r   r   r   r   r@   rA   rB   )r1   r!   r   r   r   r2   r}   rF   s           r   test_local_variable_with_inz;TestDataFrameQueryNumExprPandas.test_local_variable_with_in  s9   dk (((29$$QR$00s;;;29$$Rb$11<<<QQ''((624!8//!,,-,vfEE
h///29$$Rb$11<<<61q5,,q//*-vFF
h/////r   c                     | j         | j        }}t          |           d}t          dg di          }|                    d||          }||j        dk             }t          j        ||           d S )Nr,   r   )r   r   r   r   @crT  z	a == "@c"r   rT  )r!   r   r&   r   r@   r   rA   rB   )r1   r!   r   r   r2   rF   r}   s          r   test_at_inside_stringz5TestDataFrameQueryNumExprPandas.test_at_inside_string  s{    dk (((===>??+fVDDbddl#
fh/////r   c                 P   | 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   rn   r*  rN   za == @cr   )r!   r   r&   r   rs   r   r  rp   r#   rP   r   r@   r7  s       r   test_query_undefined_localz:TestDataFrameQueryNumExprPandas.test_query_undefined_local  s    dk (((ry~~b!,,d4jjAAA]"*M
 
 
 	> 	> HHYvfH===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   5BB"Bc                    d}t           j        ddd         }t          |t           j                            |j                  d          }d|j        _        |                    d| j	        | j
                  }||d         dk             }t          j        ||           t          |t           j                            |j                  d          }|                    d	| j	        | j
                  }|j        |j        |j        dk                      }t          j        ||           t          |t           j                            |j                  d
          }d|j        _        |                    d| j	        | j
                  }||j        dk             }t          j        ||           |                    d| j	        | j
                  }|j        |j        |j        dk                      }t          j        ||           d S )Nr,   r)  e   )rk   r   rk   z	index > 5r   r   zilevel_0 > 5rQ  r   za > 5)rs   r_r   r   r   r   rk   r   r@   r!   r   rA   rB   r   r   )r1   rZ   r   r2   rF   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))@)@AABB+dk$+NNbkAo&
fh///)@)@AABB.T[QQ6"(28a<01
fh///QRY__QV%<%<==>>'$+dkJJbdQh<
fh///+dk$+NN6"(28a<01
fh/////r   zop, f==!=c                    d}t          t          j                            |          t          j                            |          d          }t          j        |j        d d ddf<   d| d}| ||j        t          j                           }|                    || j        | j	                  }t          j        ||           d S )Nr   rQ  r-   r   a z infr   )r   rs   r   r  infr   r   r@   r!   r   rA   rB   )r1   ry   frZ   r2   qr}   rF   s           r   test_infz(TestDataFrameQueryNumExprPandas.test_inf  s    RY^^A..RY^^A5F5FGGHHsssAvMMMaabfoo&!DKDD
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@   rA   rB   reset_index)r1   tz_aware_fixtureri  df_indexr}   r2   rF   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                            |          z  t          j                            |          d          }||d                             d          dk             }|                    d| j        | j                  }t          j	        ||           t          t          j
        t          j                            |          d	k     t          j        t          j                            |                    t          j                            |          d          }||d                                                  }|                    d
| j        | j                  }t          j	        ||           d S )Nr   r-   rQ  r   intr   za.astype('int') == 0r   r   za.notnull())r   rs   r   r  r  r@   r!   r   rA   rB   wherer   r   notnull)r1   rZ   r2   r}   rF   s        r   test_method_calls_in_queryz:TestDataFrameQueryNumExprPandas.test_method_calls_in_query  s@   Q!2!229J9JKKLLbgnnU++q01"4;t{  
 
 	fh///XbinnQ//#5rvryq?Q?QRRY__Q'' 
 
 bgoo''(-DKPP
fh/////r   N)%rT   rU   rV   classmethodr   r   r   r   r  r  r  r  r   r'  r+  r0  r3  r8  r=  r?  rC  rF  rK  rN  rR  rU  rW  r[  r#   r   r   operatoreqnerc  rm  rr  r   r   r   r   r     s         [ # # [#* * ** * ** * *
* 
* 
** * ** * *N N N&< < <A A A2> > >	> 	> 	>

 

 

* * * * * *$0 0 04G G G. . .
* 
* 
*0 0 0 0 0 0> > >0 0 02 [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 fd            Zd Zd Zd Zd Zd Z	d Z
d Z xZS )	TestDataFrameQueryNumExprPythonc                 d    t                                                       d| _        d| _        d S )Nr   r   superr   r!   r   r   	__class__s    r   r   z+TestDataFrameQueryNumExprPython.setup_class  s+    



r   c                    | j         | j        }}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   )(dates1 < 20130101) & (20130101 < dates3)r   r   r   r   s         r   r   zCTestDataFrameQueryNumExprPython.test_date_query_no_attribute_access  s    dkryq!,,--!*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                 h   | j         | j        }}d}t          t          j                            |d                    }t          d|          |d<   t          d|          |d<   t          d|          |d	<   t          j        |j	        t          j        
                    |          d
k    df<   t          j        |j	        t          j        
                    |          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  s          r   r  z8TestDataFrameQueryNumExprPython.test_date_query_with_NaT  s   dkryq!,,--!*a8888!*a8888!*a888846Fry~~a  3&0146Fry~~a  3&01hh7v  
 
 BI
*zBI/EFG
c5)))))r   c                    | j         | j        }}d}t          t          j                            |d                    }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   Tr  ((index < 20130101) & (20130101 < dates3)r   r   r	  r  s           r   r  z5TestDataFrameQueryNumExprPython.test_date_index_query  s    dkryq!,,--!*a8888!*a8888||Hd|FF###hh6vf  
 
 BHz)j29.DEF
c5)))))r   c                    | j         | j        }}d}t          t          j                            |d                                        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  Tr  r  r   r   r  r  s           r   r  z>TestDataFrameQueryNumExprPython.test_date_index_query_with_NaT$  s    dkryq!,,--44a[AA!*a8888!*a8888||Hd|FF###hh6vf  
 
 BHz)j29.DEF
c5)))))r   c                    | j         | j        }}d}t          t          j                            |d                    }t          d|          |d<   t          d|          |d<   t          j        |j	        t          j        
                    |          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   Tr  "'BoolOp' nodes are not implementedrN   r  r   )r!   r   r   rs   r   r   r	   r   r   r   r  r
  r#   rP   NotImplementedErrorr@   )r1   r!   r   rZ   r2   r  rR   s          r   r  zITestDataFrameQueryNumExprPython.test_date_index_query_with_NaT_duplicates4  sR   dkryq!,,--!*a8888!*a888846Fry~~a  3&01||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   C<<D D c                 f   | j         }| j        }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   r.   z5The '@' prefix is only supported by the pandas parserrN   rA  rE  z(df>0) & (df2>0)r   zdf[(df > 0) & (df2 > 0)]z+df[(df > 0) & (df2 > 0) & (df[df > 0] > 0)])r!   r   r   rC   r   rs   r   r   r#   rP   r&  r@   r   rA   rB   )	r1   r!   r   r   rF   r2   rB  rR   r}   s	            r   rC  z1TestDataFrameQueryNumExprPython.test_nested_scopeA  sJ   ???{{{{ryq!,,--	1--.. 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2DDD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[   r      )minmaxzMVariables in expression \"\(min\) == \(1\)\" overlap with builtins: \('min'\)rN   zmin == 1zMVariables in expression \"\(max\) == \(1\)\" overlap with builtins: \('max'\)zmax == 1)r   r#   rP   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%)rT   rU   rV   rs  r   r   r  r  r  r  rC  r  __classcell__r}  s   @r   rx  rx    s            [

* 
* 
** * ** * ** * * P P P0 0 0:! ! ! ! ! ! !r   rx  c                   4     e Zd Ze fd            Zd Z xZS )TestDataFrameQueryPythonPandasc                 d    t                                                       d| _        d| _        d S )Nr   r   rz  r|  s    r   r   z*TestDataFrameQueryPythonPandas.setup_classp  s+    



r   c                 <   | j         | j        }}dx}}t          t          j                            ||df          t          d                    }d|j        _        ||j        dk             }|	                    d||	          }t          j        ||           d S 
Nr   r.   r   r-  rn   r2  r   r.  r   r!   r   r   rs   r   r/  rp   rk   r   r@   rA   rB   r1   r!   r   rZ   r{   r2   r}   rF   s           r   r3  z1TestDataFrameQueryPythonPandas.test_query_builtinv      dk
Ary((!Q(88$u++NNNbhl#)F6BB
h/////r   rT   rU   rV   rs  r   r3  r  r  s   @r   r  r  o  sQ            [
	0 	0 	0 	0 	0 	0 	0r   r  c                   4     e Zd Ze fd            Zd Z xZS )TestDataFrameQueryPythonPythonc                 d    t                                                       dx| _        | _        d S )Nr   rz  r|  s    r   r   z*TestDataFrameQueryPythonPython.setup_class  s+    "**
SZZZr   c                 <   | j         | j        }}dx}}t          t          j                            ||df          t          d                    }d|j        _        ||j        dk             }|	                    d||	          }t          j        ||           d S r  r  r  s           r   r3  z1TestDataFrameQueryPythonPython.test_query_builtin  r  r   r  r  s   @r   r  r    sQ        + + + + [+	0 	0 	0 	0 	0 	0 	0r   r  c                       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dS )TestDataFrameQueryStringsc           	      v   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|
gz   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   rn   
aabbccddeestringsr   r   z"a"r-   rm   r\  r]  $'(Not)?In' nodes are not implemented rN   )r!   r   
local_dictz"a" == stringsr   zstrings == "a"zstrings != "a"z"a" != strings)r   rs   r   r   r   rp   r  zipr#   rP   r  r@   rA   rB   r   r1   r   r!   r2   rJ  collstlhsrhsru  rv  opsrR   ry   exr   s                   r   test_str_query_methodz/TestDataFrameQueryStrings.test_str_query_method  s   ryr1--u===tL11229BJ#%&XCC%!)seai'Cddd)CFBtrd{#C9C #Cc 2 2  R((b((3((]#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   !C==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|
gz   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   rn   r  r  r   r   z
["a", "b"]r-   rm   r  r  r  rN   r   zstrings == ["a", "b"]z["a", "b"] == stringszstrings != ["a", "b"]z["a", "b"] != strings)r   rs   r   r   r   rp   r  r   r  r#   rP   r  r@   rA   rB   r  s                   r   test_str_list_query_methodz4TestDataFrameQueryStrings.test_str_list_query_method  sR   ryr1--u===tL11229BJOOS#J//0XCC%!)seai'Cddd)CFBtrd{#C9C #Cc 2 2 ? ?R((b((3((]#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   !DD
	D
	c           	         t          t          d          t          d          t          j                            dd          t          j                            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  r   za in br   za in b and c < dr  rN   r  )r   rp   rs   r   r/  r@   r   r   r   rA   rB   r   r  r#   rP   r  )r1   r   r!   r2   r   r   rR   s          r   test_query_with_string_columnsz8TestDataFrameQueryStrings.test_query_with_string_columns  sM   .)).))Y&&qr&22Y&&qr&22	 
 
 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$   E,,E03E0F::F>F>c           	         t          t          d          t          d          t          j                            dd          t          j                            dd          d          }|                    d||	          }||j        |j        k             }t          j	        ||           |                    d
||	          }||j        |j        k             }t          j	        ||           d S )Nr  r  r   r  r   r  r  za == br   za != b)
r   rp   rs   r   r/  r@   r   r   rA   rB   )r1   r   r!   r2   r   r   s         r   test_object_array_eq_nez1TestDataFrameQueryStrings.test_object_array_eq_ne  s    .)).))Y&&qr&22Y&&qr&22	 
 
 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   ).0rZ   acts      r   
<listcomp>zLTestDataFrameQueryStrings.test_query_with_nested_strings.<locals>.<listcomp>  sK     
 
 
"#>N
 
7:A
 
 
 
r   r,   r[   r-   z2014-01-01 0:00:0130sr  )rh  r   z2014-02-01 1:00:01   )idevent	timestampz"page 1 load"z'"page 1 load"' in eventr   )r&   ro   r	   r   rs   r   repeatappendr  r@   rA   rB   )	r1   r   r!   eventsstamps1stamps2r2   r}   r   s	            r   test_query_with_nested_stringsz8TestDataFrameQueryStrings.test_query_with_nested_strings  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+   rQ  za == "test & test"r   r  )r&   r   r@   r   rA   rB   )r1   r   r!   r2   r   r   s         r   (test_query_with_nested_special_characterzBTestDataFrameQueryStrings.test_query_with_nested_special_character  sr     (((666YYYGGHHhh+F6hJJ24=()
c5)))))r   zop, funcr  r  r  r  c                 z   t          t          j                            t	          d          d                    }t          t          j        |j                            }t          ||d          }|                    d| d||          }| ||j	        d                   }	t          j        ||	           d S )Nabcder)  )Xr   zX z "d"r   r  )r   rs   r   r   rp   r   r   r   r@   r  rA   rB   )
r1   r   r!   ry   funcr   r   r2   r   r}   s
             r   test_query_lex_compare_stringsz8TestDataFrameQueryStrings.test_query_lex_compare_strings&  s     29##DMM2667729QV$$%%QQ''((hh}B}}}VFhCCdd24oo&
c8,,,,,r   c                 @   d}t           j                            ddt          |          f                              t
                    }t          ||          }|                    d||          }||j        |j	        z           }t          j        ||           d S )N)bidbidsizeaskasksizer-   r,   r   rn   z	bid & askr   )rs   r   r/  r  r  boolr   r@   r  r  rA   rB   )r1   r   r!   rl   datar2   r   r}   s           r   "test_query_single_element_booleansz<TestDataFrameQueryStrings.test_query_single_element_booleans8  s    4y  !S\\): ;;BB4HH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@   rA   rB   )r1   r   r!   r2   esymbr%  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   N)rT   rU   rV   r  r  r  r  r  r  r#   r   r   rt  ltgtleger  r  r  r   r   r   r  r    s        '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                 z    t          t          j                            dd          t	          d                    S )Nr   r.   r-  rn   )r   rs   r   r   rp   r0   s    r   framez TestDataFrameEvalWithFrame.frameO  s+    Q//eEEEEr   c                 ~    |                     d||          }|j        |j        z   }t          j        ||           d S )Nr   r   rC   r   r   rA   rD   r1   r  r   r!   r   rJ  s         r   test_simple_exprz+TestDataFrameEvalWithFrame.test_simple_exprS  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_exprX  sK    jjvjFF1%/
sF+++++r   ry   )r\   r_   rb   re   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   r  rQ  z3unsupported operand type\(s\) for .+: '.+' and '.+'rN   r_  z br   )r   r#   rP   r  rC   )r1   r   r!   ry   r2   rR   s         r   %test_invalid_type_for_operator_raisesz@TestDataFrameEvalWithFrame.test_invalid_type_for_operator_raises]  s    aV3*5566D]9C000 	? 	?GGKKKKvG>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   AA"%A"N)rT   rU   rV   r#   rW   r  r  r  r   r   r  r   r   r   r  r  N  s        ^F F ^F, , ,
, , ,
 [T#7#7#788? ? 98? ? ?r   r  c                      e Zd Zej        d             Zd Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej                             dg d          d             Z!ej                             ddd g          ej                             dg d          d!                         Z"d"S )#!TestDataFrameQueryBacktickQuotingc           	   #      K   t          i dg ddg ddg ddg dd	g d
dg ddg ddg ddg ddg ddg ddg ddg ddg ddg ddg d d!g d"g d#g d$g d%g d&g d'd(          V  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  r[   r.   C_C)   r  r   D_D D)   r,   rY  E.E)r  r.   r   F-F)r  r,   r   1e1)r-   r[   r  def)r   r  r-   A (x))r[   r,   r.   zB(x))r,   r,   r   zB (x))r-   r  r[        &^ :!€$?(} >    <++*''  )r-   r   r  r   )r   r  r,    A)r[   r  r    r,   r-   r,   )r  r.   r,   )r  r,   r  )r  r  r  )r-   r[   r   )r   r  r  )zit'szthat'su   ☺zfoo#barr,   Nr/   r0   s    r   r2   z$TestDataFrameQueryBacktickQuoting.dfg  ss      YYYyyy yyy 				
 zzz  yyy zzz yyy {{{  			  /			 KKK  iii!" iii#$ "		#)) yy$9999-  
 
 	
 	
 	
 	
 	
r   c                 ~    |                     d          }|d|d         k              }t          j        ||           d S )Nz	1 < `B B`r,   r  r@   rA   rB   r1   r2   r   rJ  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  r[   r  r	  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  rC   rA   rD   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  r  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  r  r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )Nz	A + `def`r*   r  r  r
  s       r   test_keywordz.TestDataFrameQueryBacktickQuoting.test_keyword  r  r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nz`A` > 2r*   r-   r	  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-   r	  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   r	  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   r	  r
  s       r   test_multiple_spacesz6TestDataFrameQueryBacktickQuoting.test_multiple_spaces  s>    hh|$$BvJN#
c6*****r   c                 |    |                     d          }|d         |d         z   }t          j        ||           d S )Nz` A` + `  `r  r  r  r
  s       r   test_start_with_spacesz8TestDataFrameQueryBacktickQuoting.test_start_with_spaces  s>    ggm$$DBtH$
sF+++++r   c                 ~    |                     d          }||d         dk             }t          j        ||           d S )Nu"   `  &^ :!€$?(} >    <++*''  ` > 4r  r[   r	  r
  s       r   test_lots_of_operators_stringz?TestDataFrameQueryBacktickQuoting.test_lots_of_operators_string  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'rN   z	@pd.thing)r#   rP   AttributeErrorrC   )r1   r2   messages      r   test_missing_attributez8TestDataFrameQueryBacktickQuoting.test_missing_attribute  s    <]>999 	! 	!GGK   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!   AAAc                     d}t          j        t          |          5  |                    d           d d d            d S # 1 swxY w Y   d S )N6(Could not convert ).*( to a valid Python identifier.)rN   z`it's` > `that's`r#   rP   r&  r@   r   s      r   test_failing_quotez4TestDataFrameQueryBacktickQuoting.test_failing_quote  s    G];c222 	* 	*HH()))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*r2  c                     d}t          j        t          |          5  |                    d           d d d            d S # 1 swxY w Y   d S )Nr4  rN   u	   `☺` > 4r5  r   s      r   $test_failing_character_outside_rangezFTestDataFrameQueryBacktickQuoting.test_failing_character_outside_range  s    G];c222 	" 	"HH[!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"r2  c                     d}t          j        t          |          5  |                    d           d d d            d S # 1 swxY w Y   d S )NzFailed to parse backticksrN   z`foo#bar` > 4r5  r   s      r   test_failing_hashtagz6TestDataFrameQueryBacktickQuoting.test_failing_hashtag  s    )];c222 	& 	&HH_%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&r2  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   )_s    r   r  zNTestDataFrameQueryBacktickQuoting.test_call_non_named_expression.<locals>.func  s    1r   z@func()z"Only named functions are supportedrN   z@funcs[0]()Nz@funcs[0].__call__())rC   r#   rP   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.   r[   r   r   rl   dtypez	c = b - ar  )r.   r[   r,   r5  r   r
   RuntimeWarningrA   assert_produces_warningrC   rB   )r1   any_numeric_ea_and_arrow_dtyper2   warningrF   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.   r[   r   r   Float64rA  z	c = b - 1r  )r.   r[   r.   r5  rC  )r1   r2   rG  rF   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/////rI  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.   r[   r   r   rA  z	c = 2 - 1rB  r   r5  )r   rC   r   rB  rA   rB   )r1   rF  r2   rF   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   rB  )int64Int64int64[pyarrow]c                    |dk    rt          j        d           t          dt          ddg|          i          }dh}|dk    rt          rt
          nd }t          j        |          5  |                    d          }d d d            n# 1 swxY w Y   t          dt          dg|dg	          i          }t          j	        ||           d S )
NrR  pyarrowr   r,   r-   rN  rQ  z	a in @refrB  rk   )
r#   importorskipr   r   r
   rD  rA   rE  r@   rB   )r1   rB  r2   refrG  rF   r}   s          r   test_query_ea_dtypesz6TestDataFrameQueryBacktickQuoting.test_query_ea_dtypes0  s   $$$	***VQF%8889::c$)W$4$49J$4..PT'00 	+ 	+XXk**F	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+c61#U1##F#F#FGHH
fh/////s   *BBBr!   r   r   c           	      &   |dk    rt           nd }|dk    rt          st          j        d           |dk    rt          j        d           t          t          g dd          t          g d|          d	          }t          j        |          5  |	                    d
|          }d d d            n# 1 swxY w Y   t          t          ddgdddg          t          ddg|ddg          d	          }t          j
        ||           d S )Nr   znumexpr not installedrR  rT  )r,   r,   r-   rQ  rN  )r,   r-   r-   r   zA == BrI   r,   r-   r   rU  )rD  r
   r#   r$   rV  r   r   rA   rE  r@   rB   )r1   rB  r!   rG  r2   rF   r}   s          r   !test_query_ea_equality_comparisonzCTestDataFrameQueryBacktickQuoting.test_query_ea_equality_comparison=  sx    %+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F%1v>>> 
 
 	fh/////s   B77B;>B;N)#rT   rU   rV   r#   rW   r2   r  r  r  r  r  r  r  r  r  r  r!  r#  r%  r'  r)  r+  r-  r1  r6  r8  r:  r?  rH  rL  rO  r   r   rX  rZ  r   r   r   r  r  f  s5       ^
 
 ^
B+ + +
+ + +
, , ,
, , ,
, , ,
, , ,
, , ,
, , ,
, , ,
, , ,
, , ,
+ + +
+ + +
+ + +
+ + +
, , ,
+ + +
! ! !
* * *
" " "
& & &
, , ,*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 0r   r  )'rt  numpyrs   r#   pandas.errorsr   r   pandas.util._test_decoratorsutil_test_decoratorstdr   r   r   r   r   r   r	   pandas._testing_testingrA   pandas.core.computation.checkr
   rW   r   r   skip_if_no_ner!   r&   r(   rY   r   r   rx  r  r  r  r  r  r   r   r   <module>re     sz                * ) ) ) ) ) ) ) )                        ; ; ; ; ; ; (+===  >= lfl9B4DEEEFKK    C C C
01 01 01 01 01 01 01 01f\- \- \- \- \- \- \- \-~DI DI DI DI DI DI DI DIN m0 m0 m0 m0 m0 m0 m0 m0` x! x! x! x! x!&E x! x! x!v0 0 0 0 0%D 0 0 0&0 0 0 0 0%D 0 0 0$w$ w$ w$ w$ w$ w$ w$ w$t? ? ? ? ? ? ? ?0k0 k0 k0 k0 k0 k0 k0 k0 k0 k0r   