HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/tests/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/tests/__pycache__/test_expressions.cpython-36.pyc
3

���h�6�@s\ddlZddlZddlZddlmZddlZddljZ	ddl
mZmZm
Z
ddlmZeedd�ed�dd	�Zeed
d�ed�dd	�Zeedj�edjd
�edjd�edjd�d��Zeedj�edjd
�edjd�edjd�d��Zeejjdd
dd�ed�dd	�Zeejjdd
dd�ed�dd	�Zejjejdd�Gdd�d��ZdS)�N)�randn)�	DataFrame�Index�Series)�expressionsi'��ABCDZfloat64)�columns�dtype�d�A�BZfloat32�CZint64�DZint32)rr
rr��')�size�eznot using numexpr)�reasonc
@s~eZdZdd�Zdd�Zdd�Zdd�Zd[d
d�Zej	j
deeee
jjd
de
je�d�eeeeg�dd��Zdd�Zej	j
dd\d]d^d_d`g�ej	j
deefeefg�d d!���Zej	j
ddadbdcdddedfg�ej	j
deefeefg�d.d/���Zej	j
d0d	d1g�ej	j
deeeeg�d2d3���Zej	j
d4dgdhdig�d7d8��Zej	j
d4djdkdlg�d9d:��Zej	j
d;ed
d<dd=gd
d<dd=ggd>d?d@dAgdB�ed1d1gd1d1ggd>dAgdB�fed
dCdd=gd
dDdd=gd
d<d<dEggd>d?d@dAgdB�ed1d1gd1d1gd1d1ggd>dAgdB�fg�dFdG��Zej	j
dHdm�ej	j
dJdn�dKdL���Zej	j
dMdNejdOej	j dPdQ�dR�dSdTg�ej	j
dUee!e"g�ej	j
dVdodWg�dXdY����Z#dZS)p�TestExpressionscCs4tj�|_tj�|_tj�|_tj�|_t	j
|_
dS)N)�_frame�copy�frame�_frame2�frame2�_mixed�mixed�_mixed2Zmixed2�expr�
_MIN_ELEMENTS)�self�method�r"�?/tmp/pip-build-5_djhm0z/pandas/pandas/tests/test_expressions.py�setup_method(s




zTestExpressions.setup_methodcCs|jt_dS)N)rr)r r!r"r"r#�teardown_method0szTestExpressions.teardown_methodcs�dt_ddddddg}x�dD]�}x�|D]��|rB�fd
d�}�|_n
tt��}tjd	�|||�}tjd�|||�}�dkr�|jdkr�|jjd
ks�t	�nt
dd�|jjD��s�t	�t
j||�q&WqWdS)Nr�add�sub�mul�mod�truediv�floordivTFcst|��|�S)N)�getattr)�x�y)�arithr"r#�<lambda>:sz0TestExpressions.run_arithmetic.<locals>.<lambda>r�fcss|]}|jdkVqdS)r1N)�kind)�.0r-r"r"r#�	<genexpr>Gsz1TestExpressions.run_arithmetic.<locals>.<genexpr>)TF)rr�__name__r,�operator�set_use_numexpr�ndimr
r2�AssertionError�all�dtypes�values�tm�assert_equal)r �df�other�
operations�	test_flex�op�expected�resultr")r/r#�run_arithmetic3s"







zTestExpressions.run_arithmeticc	s�dt_tjd�ddddddg}x�dD]�}x~|D]v�|rL�fd
d�}�|_n
tt��}tjd	�|||�}tjd�tj�|||�}tj�}|s�td��t	j
||�q0Wq&Wd
S)z�
        tests solely that the result is the same whether or not numexpr is
        enabled.  Need to test whether the function does the correct thing
        elsewhere.
        rT�gt�lt�ge�le�eq�neFcst|��|�S)N)r,)r-r.)r/r"r#r0Wsz,TestExpressions.run_binary.<locals>.<lambda>z Did not use numexpr as expected.N)TF)rrZ
set_test_moder5r,r6r7Zget_test_resultr9r=r>)	r r?r@rArBrCrDrEZused_numexprr")r/r#�
run_binaryJs"







zTestExpressions.run_binaryTcCs||j||�|r8tjd�|d}tjd�|j||�x>tt|j��D],}|j|jdd�|f|jdd�|f�qHWdS)NFrT)rFrr7rM�range�lenr	�iloc)r r?r@rMZbinary_comp�ir"r"r#�	run_framees

zTestExpressions.run_framer?r�)rcCs2dd�|jjD�}t|�dk}|j|||d�dS)NcSsh|]
}|j�qSr")r2)r3r-r"r"r#�	<setcomp>�sz2TestExpressions.test_arithmetic.<locals>.<setcomp>r)rM)r;r<rOrR)r r?ZkindsZshouldr"r"r#�test_arithmetictszTestExpressions.test_arithmeticcCs�tjtjd|j|jd�}|s"t�tjtjd|j|jd�}|sDt�tjtjd|j|jd�}|sft�tjtjd|j|jd�}|s�t�dS)N�evaluate�+)r�_can_use_numexprr6r&rr9rr)r rEr"r"r#�test_invalid�s


zTestExpressions.test_invalidz
opname,op_strr&rWr'�-r(�*r*�/�pow�**z
left,rightcsN����fdd�}tjd�|�tjd�tjd�|�tj�|�dS)Ncs��dkrdStt��}tj|���d�}|�jks6t�tj|��dd�}tj|��dd�}t|t�rrt	j
||�nt	j||j�tj|���d�}|s�t�dS)Nr]rVT)�use_numexprF)
r,r6rrX�_is_mixed_typer9rV�
isinstancerr=�assert_frame_equal�assert_numpy_array_equalr<)rCrErD)�left�op_str�opname�rightr"r#�testit�s

z/TestExpressions.test_binary_ops.<locals>.testitFTr)rr7�set_numexpr_threads)r rfrerdrgrhr")rdrerfrgr#�test_binary_ops�s


zTestExpressions.test_binary_opsrG�>rH�<rI�>=rJ�<=rK�==rL�!=csN����fdd�}tjd�|�tjd�tjd�|�tj�|�dS)Ncs��d}�d}tt��}tj|��|d�}|�jks:t�tj|�|dd�}tj|�|dd�}t|t�rvt	j
||�nt	j||j�tj|��|d�}|s�t�dS)NrrVT)r_F)
r,r6rrXr`r9rVrarr=rbrcr<)Zf12Zf22rCrErD)rdrerfrgr"r#rh�s

z3TestExpressions.test_comparison_ops.<locals>.testitFTr)rr7ri)r rfrerdrgrhr")rdrerfrgr#�test_comparison_ops�s



z#TestExpressions.test_comparison_ops�condFcsJ��fdd�}tjd�|�tjd�tjd�|�tj�|�dS)NcsXtj�jtjd�}|j��tj|�j�jd�}tj|�j�jd�}tj	||�dS)N)r
r)
�np�empty�shapeZbool_�fillr�wherer<r=rc)�crErD)rrr?r"r#rh�s

z*TestExpressions.test_where.<locals>.testitFTr)rr7ri)r rrr?rhr")rrr?r#�
test_where�s


zTestExpressions.test_wherez
op_str,opname�//r+c-Cs.ttjjd�dktjjd�dkd��}dt|��d�}tt|�}tj|�}t	j
t|d��|||�WdQRXt	j
t|d��||j|j
�WdQRXt	j
t|d��||jd�WdQRXt	j
t|d��|d|j�WdQRXt	j
t|d��|d|�WdQRXt	j
t|d��||d�WdQRXdS)	N�
g�?)�a�bz	operator z  not implemented for bool dtypes)�matchTF)rrs�random�rand�reprr,r6�re�escape�pytestZraises�NotImplementedErrorr|r})r rerfr?�msgr1�err_msgr"r"r#�!test_bool_ops_raise_on_arithmetics &

z1TestExpressions.test_bool_ops_raise_on_arithmeticc4Cs�d}ttjj|�dktjj|�dkd��}dddd�}dd	d
d�}tt|�}tt|||�}|dkrjdStjd
dd���ftjdd��&|||�}	|||�}
tj	|	|
�WdQRXtjdd��.||j
|j�}	||j
|j�}
tj|	|
�WdQRXtjdd��*||j
d
�}	||j
d
�}
tj|	|
�WdQRXtjdd��*|d|j
�}	|d|j
�}
tj|	|
�WdQRXtjdd��&|d|�}	|d|�}
tj	|	|
�WdQRXtjdd��&||d
�}	||d
�}
tj	|	|
�WdQRXWdQRXdS)Nr{g�?)r|r}�|�&�^)rWr[rZ�or_�and_�xor)r�r�r�rZT�)Zmin_elementsF)Zcheck_stacklevel)
rrsrr�r,r6r=r_Zassert_produces_warningrbr|r}Zassert_series_equal)r rerf�nr?�subsZ	sub_funcsr1Zfe�r�er"r"r#� test_bool_ops_warn_on_arithmeticsB&






z0TestExpressions.test_bool_ops_warn_on_arithmeticztest_input,expectedrZaar|r}rxr
)r	�rZbbcCs>|jdd�ddgfj|jdd�ddgf�}tj||�dS)Nr|r
)�locrLr=rb)r Z
test_inputrDrEr"r"r#�test_bool_ops_column_name_dtypeNs.z/TestExpressions.test_bool_ops_column_name_dtyper/r)�axiscCs�|j}|dkr$|jjddd�f}n|jjdd�df}dt_t||�}tjd�|||d�}tjd�|||d�}tj||�dS)NrrF)r�T)rrPrrr,r7r=rb)r r�r/r?r@Zop_funcrDrEr"r"r#�test_frame_series_axishs


z&TestExpressions.test_frame_series_axisrC�__mod__�__rmod__zGH-36552)r)Zmarks�__floordiv__�
__rfloordiv__�box�scalarr�cCs�dt_tjdd�}||�}t||�}||�}tjd�||�}tjd�tj||�xlt|�D]`\}	}
|t	kr~|j
|	df}n||	}ytt|
�|�|�}Wntk
r�Yq^X||ks^t
�q^WdS)Nr�2FTi���)rrrsZaranger,r7r=r>�	enumeraterrP�int�ZeroDivisionErrorr9)r rCr�r��data�objr!rErDrQ�elemZ
scalar_resultr"r"r#�,test_python_semantics_with_numexpr_installed�s$



z<TestExpressions.test_python_semantics_with_numexpr_installedN)T)r&rW)r'rZ)r(r[)r*r\)r]r^)rGrk)rHrl)rIrm)rJrn)rKro)rLrp)r\r*)rzr+)r^r])rWr&)r[r()rZr')r&r'r(r)r*r+)rr���)$r5�
__module__�__qualname__r$r%rFrMrRr��markZparametrize�_integer�	_integer2rsr�randintrurrrrrUrYrjrqryr�r�rr�r��paramZxfailrrr�r"r"r"r#r&sp
$ $ /$ 
r)rr)rr) r6r�ZnumpyrsZnumpy.randomrr�Zpandas._testingZ_testingr=Zpandas.core.apirrrZpandas.core.computationrr�listrrrZastyperrrr�r�r�r�ZskipifZ_USE_NUMEXPRrr"r"r"r#�<module>s0