U
    >vfc)                     @   s  d dl mZ d dlZd dlZd dlZd dlm  mZ	 d dl
Zd dlmZ d dlmZ dddddgZejdedd	 Zejded
d Zejdedd Zejdejdddddgfeejddgddggdeddgddggd ddd gfejeddgddggddddgfejddd ddgfeejeddgddggddd ddd gfgdd Zejdeejded d! Zejded"d# Zd$d% Zd&d' Z d(d) Z!d*d+ Z"e	#d,d-d. Z$d/d0 Z%dS )1    )partialN)is_extension_array_dtypeint64ZInt64ABdtypec                 C   st   t jddgddggdd}tj|ddgddgd	j| d}t |}tjt ||j|jd
| }t	|| d S N   r   r   r   r   abcolumnsindexr   r   )
nparraypd	DataFrameastypeZpositiver   r   tmassert_frame_equalr   valuesdfresultexpected r   A/tmp/pip-unpacked-wheel-vdrwu74i/pandas/tests/frame/test_ufunc.pytest_unary_unary   s     
  r!   c           	      C   s   t |st|tr(| jtjjdd tj	ddgddggdd}t
j|ddgd	d
gdj|d}t|}t|tsztt|dkstt|}t||D ](\}}t
j||j|jd}t|| qd S )Nz8Extension / mixed with multiple outputs not implemented.reasonr
   r   r   r   r   r   r   r   r      r   )r   
isinstancedictnode
add_markerpytestmarkxfailr   r   r   r   r   modftupleAssertionErrorlenzipr   r   r   r   )	requestr   r   r   Zresult_pandasZexpected_numpyr   r   r   r   r   r    test_unary_binary    s     

r2   c                 C   sx   t jddgddggdd}tj|ddgddgd	j| d}t ||}tjt |||j|jd
| }t	|| d S r	   )
r   r   r   r   r   addr   r   r   r   r   r   r   r     test_binary_input_dispatch_binop6   s     
  r4   zfunc,arg,expectedr   r$            FT)where	      r
   c                 C   s   t ddgddgg}t|}t |}|d kr@| ||d}n| |||d}t |dd}t|| t|}t|| d S )Nr   r$   r5   r6   )out)	r   r   r   r   Z
zeros_likeZreshaper   Zassert_numpy_array_equalr   )funcargr   Zarrr   Zresult_inplacer   r   r   r    test_ufunc_passes_argsB   s    


r@   dtype_adtype_bc              	   C   sF  t |s$t|ts$t |s$t|tr:| jtjjdd t	ddgddgd
|}t|trzt|trz|d|d	< t	ddgddgd

|}t||}ttddtjgddtjggtdtjdgdtjdgg}tj	|ddgddd	gd}t|| t||j}tj	ddgddggddgd}t|| d S )N7Extension / mixed with multiple inputs not implemented.r"   r   r$   r5   r6   r   r   C)r   rD   r   r   r         ?r   )r   r%   r&   r'   r(   r)   r*   r+   r   r   r   popr   	heavisider   nanr   r   r   )r1   rA   rB   df1df2r   r   r   r   r     test_binary_input_aligns_columnsf   s6    rL   c              	   C   s,  t |st|tr(| jtjjdd tj	ddgddgddd	gd

|}tj	ddgddgdddgd

|}t||}ttddgddgtjtjggtddgtjtjgddgg}tj	|dd	dgddgd}t|| t||j}tj	ddgddggddgdd	gd}t|| d S )NrC   r"   r   r$   r5   r6   r   r   r   r   cr   r   r   rE   r   )r   r%   r&   r'   r(   r)   r*   r+   r   r   r   r   rH   r   rI   r   r   r   )r1   r   rJ   rK   r   r   r   r   r    test_binary_input_aligns_index   s,    &&  rO   c               	   C   sj   t dddgi} tjtdd t| | d  W 5 Q R X tjtdd t| d |  W 5 Q R X d S )Nr   r   r$   	logaddexpmatch)r   r   r)   raisesNotImplementedErrorr   rP   r   r   r   r    test_binary_frame_series_raises   s
    rV   c                  C   s   t dddddgi} tj| }t dddddgi}t|| t ddddgdddd	gd
} tj| }t ddddgddddgd
}t|| tjj| dd}t|| tjj| dd}t ddd	dgddddgd
}t|| d S )Nr   r   r5   r$   r6   g?g      @      @g       @r   r   rE   r   )Zaxis)r   r   r   maximum
accumulater   r   )r   r   r   r   r   r    test_unary_accumulate_axis   s       r[   c               	   C   s>   t dddgi} tjtdd tj| |  W 5 Q R X d S )Nr   r   r$    rQ   )r   r   r)   rS   rT   r   subtractouterrU   r   r   r    test_frame_outer_disallowed   s    r_   c               	   C   s  t dddgdddgd} t dddgdddgd}t jddgd	d
gd}t jddgd
dgd}t dddgdddgd}td  t| | }W 5 Q R X t|| t| |j}t|| t| |}t tj	gd dddgtj	gd d}t|| t| j|}t dddgdddgd}t|| t dddgdddgd}td  t| |}W 5 Q R X t|| t| |j}t|| t tj	gd dddgtj	gd d}t| |}t|| d}t
jt|d t||  W 5 Q R X d S )Nr   r$   r5   r6   r7      rX   r   rN   r   r   rM   rN      
         r9   )r   r   rN   g      @      @g      @zFCannot apply ufunc <ufunc 'add'> to mixed DataFrame and Series inputs.rQ   )r   r   Seriesr   assert_produces_warningr   r3   r   r   rI   r)   rS   rT   )rJ   rK   s1s2r   r   msgr   r   r    #test_alignment_deprecation_enforced   s<    ( rl   numbac            	   	   C   s  ddl m} m} || | | | gdd }tdddgdd	d
gd}tdddgdd	d
gd}tdddgdd	d
gd}||||}tjtdtjdddgd}t	|| t
d  ||||}W 5 Q R X tjddgddgddggddgd}t	|| d}tjt|d ||||j W 5 Q R X t
d  |||j|j}W 5 Q R X t	|| d}tjt|d ||j|| W 5 Q R X d S )Nr   )float64	vectorizec                 S   s   | | | S Nr   xyzr   r   r    my_ufunc  s    zAtest_alignment_deprecation_many_inputs_enforced.<locals>.my_ufuncr   r$   r5   r6   r7   r`   rX   ra   )r   rN   )r5   r5   r   r   rN   rF   rW   g      (@rf   g      .@g      "@g      2@zLoperands could not be broadcast together with shapes \(3,3\) \(3,3\) \(3,2\)rQ   zLoperands could not be broadcast together with shapes \(3,2\) \(3,3\) \(3,3\))rm   rn   ro   r   r   r   fullrI   r   r   rh   r)   rS   
ValueErrorr   )	rn   ro   ru   rJ   rK   Zdf3r   r   rk   r   r   r    /test_alignment_deprecation_many_inputs_enforced   s0    
$rx   c               	   C   s   dd } t | dd}tddgddgg}|||d}tjddgdd	ggtd
}t|| tddg}d}tj	t
t|d |||| W 5 Q R X d S )Nc                 S   s   | | | S rp   r   rq   r   r   r    add3,  s    z2test_array_ufuncs_for_many_arguments.<locals>.add3r5   r   r$   r6   r7   re   r9   r   zTCannot apply ufunc <ufunc 'add3 (vectorized)'> to mixed DataFrame and Series inputs.rQ   )r   Z
frompyfuncr   r   objectr   r   rg   r)   rS   rT   reescape)ry   Zufuncr   r   r   Zserrk   r   r   r    $test_array_ufuncs_for_many_arguments*  s    r}   )&	functoolsr   r{   Znumpyr   r)   Zpandas.util._test_decoratorsutilZ_test_decoratorstdZpandasr   Zpandas._testingZ_testingr   Zpandas.api.typesr   Zdtypesr*   Zparametrizer!   r2   r4   r3   r   powerr]   negativer@   rL   rO   rV   r[   r_   rl   Z
skip_if_norx   r}   r   r   r   r    <module>   sZ   



$

 

1
0