U
    /e@                  *   @   s$  d dl Z d dlZedZd dlZd dlmZ d dl	m
Z d dlmZ d dlmZ ddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.g*Zejd/eejjd0d1d2d3eeejd1eejjd0d1d2d3ejjd0d1d2d3eejd2d4ejejjd0d1d2d3ed5d6ejeejd2ed5d6ejejjd0d1d2d3ejjd0d1d2d3eejd2d4ed5d6gejd7ed8d9 Zejd7d:d;d<d=d>d?d@dAdBg	dCdD ZdEdF ZdGdHdIdJdKdLejdMejdNgdOejdPejdNgdOdQdRdSdTdUdVdWdXdYdZd[d\d]dRdQdSgZejd7eejd^d_d` dad` gdbdc Z ejddeejjd0d1d2d3dedffejejjd0d1dgd3dhdigdjdkdlfgdmdn Z!ejd7edodp Z"dqdr Z#ejdseeejd1eejjd0d1d2d3ejjd0d1d2d3eejd2d4gejdtdue$ed gd0% gejd7edvdw Z&ejd7eejdxeejjd0d1dyd3ej'ejjd0d1dyd3dzd{fejejjd0d1dgd3dhdigdjej'ejjd0d1dgd3d|d{fgd}d~ Z(ejddddddgejd7eejdeeejd1eejjd0d1d2d3ejjd0d1d2d3eejd2d4gdd Z)ejdeejjd0d1d1d3eejjd0d1d2d3ejjd0d1d2d3eejd2d4gejddde*de+dgdd Z,dS )    Npandas)PANDAS_GT_120	assert_eqconjexploglog2log10log1pexpm1sqrtsquaresincostanZarcsinZarccosZarctansinhcoshtanhZarcsinhZarccoshZarctanhZdeg2radZrad2degisfiniteisinfisnansignbitdegreesradiansZrintfabssignabsolutefloorceiltrunclogical_notZcbrtZexp2negativeZ
reciprocalspacingpandas_input   d      sizeABCabcdefghijklmnopqrstindexufuncc              	   C   s  t t|}t t|}t| d}| j}|j}t  tdt	 t
|||sTtt||||  t
|tjrt
|||stnt
|||stt||||  t
|| |stt||||  W 5 Q R X | jjttfkrd S |dkrd S t  tdt	 t
||jtjs&tt||j|| j|dkd t
|tjrlt
||jtjstnt
||jtjstt||j||j|dkd W 5 Q R X t < tdt	 t
|| jtjstt|| ||  W 5 Q R X d S )N   ignore)r!   r   r   r   r   r#   )Zcheck_divisions)getattrdanpddfrom_pandas	__class__warningscatch_warningssimplefilterRuntimeWarning
isinstanceAssertionErrorr   r1   r0   ZdtypeobjectstrZIndexpd)r$   r1   dafuncnpfuncZ
dask_inputpandas_type	dask_type rG   C/tmp/pip-unpacked-wheel-dbjnr7gq/dask/dataframe/tests/test_ufunc.py
test_ufunc<   sN    




rI   ZisrealZ	iscomplexrealimagZanglefixZi0ZsincZ
nan_to_numc                 C   s  ddl m} | dkrtd tt| }tt| }tjtj	j
ddddtd	d
}t|d}t||tjsrt||||| t||tjsttj|||| t||tjsttj|||| tjtj	j
ddddtj	j
ddddttj	ddtd	d
}t|d}t||tjs>t||||| t||tjsfttj|||| t||tjsttj|||| dS )a"  
    some np.ufuncs doesn't call __array_wrap__
    (or __array_ufunc__ starting from numpy v.1.13.0), it should work as below

    - da.ufunc(dd.Series) => da.Array
    - da.ufunc(pd.Series) => np.ndarray
    - np.ufunc(dd.Series) => np.ndarray
    - np.ufunc(pd.Series) => np.ndarray
    r   r   rL   z3fix calls floor in a way that we do not yet supportr%   r&   r'   r(   r.   r/   r2   r*   N)Zdask.array.utilsr   pytestskipr4   r5   r6   rB   Seriesrandomrandintlistr7   r8   r>   Arrayr?   ZndarraytestingZassert_equalassert_array_equal	DataFrameabsrandn)r1   Zda_assert_eqrC   rD   sdsdfddfrG   rG   rH   test_ufunc_wrapped   s<    


 r]   c               	   C   s   t jtjjddddtdd} t| d}tj	t
dd	 t|d
 W 5 Q R X t jtjjddddtjjddddttjddtdd}t|d}tj	t
dd	 t|d
 W 5 Q R X d S )Nr%   r&   r'   r(   r.   r/   r2   z`repeat` is not implemented)match
   r*   )rB   rO   r6   rP   rQ   rR   r7   r8   rM   raisesNotImplementedErrorrepeatrV   rW   rX   )rY   rZ   r[   r\   rG   rG   rH   "test_ufunc_wrapped_not_implemented   s"     rc   Z	logaddexpZ
logaddexp2Zarctan2hypotcopysignZ	nextafterldexpzignore::RuntimeWarning)Zmarksfmodlogical_and
logical_orlogical_xormaximumZminimumZfmaxZfminZgreaterZgreater_equalZlessZ
less_equal	not_equalequalmake_pandas_inputc                   C   s   t tjjddddS )Nr%   r&   r'   r(   )rB   rO   r6   rP   rQ   rG   rG   rG   rH   <lambda>      ro   c                   C   s    t jtjjddddddgdS )Nr%   r&   r'      r(   r+   r,   columns)rB   rV   r6   rP   rQ   rG   rG   rG   rH   ro     s    c           
      C   sR  t t| }t t| }| }| }t|d}t|d}|j}|j}	t||||	sXtt|||||| t||||	stt|||||| t|tj	rt||||	stt||||	stn(t||||stt||||stt|||||| t|||||| t||||s8tt|||||| d S )Nr2      )
r4   r5   r6   r7   r8   r9   r>   r?   r   r1   )
r1   rn   rC   rD   Zpandas1Zpandas2Zdask1Zdask2rE   rF   rG   rG   rH   test_ufunc_with_2args
  s*    

rv   zpandas,min,max   2   rq   r+   r,   rs   g      @g     @D@c                 C   s   t | d}| j}|j}tt||||s0ttt|||t| || tt||||sfttt|||t| || tt| |||sttt| ||t| || d S )Nr2   )	r7   r8   r9   r>   r5   Zclipr?   r   r6   )r   minmaxdaskrE   rF   rG   rG   rH   	test_clip:  s    r|   c           
   	   C   s  t t| }t t| }tjjdddd}tj|ddgd}t|d}tjtjjddddd	d
gd}t|d}t|d}t	
 4 t	dt |||d |||d t|| W 5 Q R X t	
 2 t	dt tj||ddgd}	t||	 W 5 Q R X d S )Nr%   r&   rq   r(   r+   r,   rs   r2   YZr3   out)r4   r6   r5   rP   rQ   rB   rV   r7   r8   r:   r;   r<   r=   r   )
r1   rD   rC   input_matrixr[   r\   df_outZ
ddf_out_npZ
ddf_out_daexpectedrG   rG   rH   test_frame_ufunc_outZ  s"    

 

r   c               	   C   s.  t jjdddd} tj| ddgd}t|d}tjt jjddd	dd
ddgd}t|d}tt	 t j
||d W 5 Q R X ttdgd}tt t j
||d W 5 Q R X tjt jjddddd
dgd}t|d}t j
||d t j|d|d tjt 
| d ddgd}t|| d S )Nr%   r&   rq   r(   r+   r,   rs   r2   )r'   r2   Xr}   r~   r   r   r_   )r6   rP   rQ   rB   rV   r7   r8   rM   r`   
ValueErrorr   rO   	TypeErroraddr   )r   r[   r\   r   Zddf_outr   rG   rG   rH   test_frame_2ufunc_outs  s&      r   arg1arg2rr   c                 C   s:  t t| }t t| }t|d}|j}|j}t||||s@tt|||||| t||||sjtt|||||| t||||stt|||||| | dkrd S t||||stt|||||| t||||stt|||||| t||||s tt|||||| d S )Nr2   rf   )	r4   r6   r5   r7   r8   r9   r>   r?   r   )r1   r   r   rD   rC   r{   rE   rF   rG   rG   rH   test_mixed_types  s&    

r   zpandas,darray)r&   )rx   )chunks)r_   rr   c                 C   s   t t| }t t| }t|d}|j}t||||s:tt||||sNttj	|||
 j||j|
  t||||stt||||sttj	|||
 j||j|
  tj	|||
 j||
 |j d S )Nrr   )r4   r5   r6   r7   r8   r9   r>   r?   rT   rU   Zcomputevalues)r1   r   ZdarrayrC   rD   r{   rF   rG   rG   rH   test_2args_with_array  s(    

   r   redfuncsumprodry   rz   Zmeanc              	   C   s   t |d}tt| }tt|}trJ| dkrJ|dkrJt|tjrJt	d t
 X t
dt t
dt t||t jt jt jjfstt|||||| W 5 Q R X d S )Nr2   r   )r   r   r"   r   z7'prod' overflowing with integer columns in pandas 1.2.0r3   )r7   r8   r4   r6   r   r>   rB   rV   rM   Zxfailr:   r;   r<   r=   FutureWarningrO   coreZScalarr?   r   )r   r1   r   r{   Z
np_redfuncZnp_ufuncrG   rG   rH   test_ufunc_with_reduction  s"    





 r   scalar   gffffff0@c                 C   s(   |t j| ddk}|| k}t|| d S )Nr2   )Znpartitions)r7   r8   r   )r   r   Zdask_compareZpandas_comparerG   rG   rH   "test_ufunc_numpy_scalar_comparison  s    r   )-r:   rM   ZimportorskiprB   Znumpyr6   Z
dask.arrayarrayr5   Zdask.dataframeZ	dataframer7   Zdask.dataframe._compatr   Zdask.dataframe.utilsr   Z_BASE_UFUNCSmarkZparametrizerO   rP   rQ   rW   rX   rV   rR   rI   r]   rc   paramfilterwarningsZ_UFUNCS_2ARGrv   r|   r   r   r8   r   r   Z
from_arrayr   r   Zint64Zfloat64r   rG   rG   rG   rH   <module>   s|  
. =
6	&

$( 