3
Ud                 @   s   d dl mZmZ d dlZd dlZd dljZd dl	m
Z
 ddlmZ G dd deZG dd	 d	eZG d
d deZG dd deZdS )    )OptionalTypeN)ops   )BaseExtensionTestsc               @   s8   e Zd Zdd ZefddZefddZefddZd	S )
BaseOpsUtilc             C   s
   t j|S )N)tmget_op_from_name)selfop_name r   S/var/www/html/virt/lib64/python3.6/site-packages/pandas/tests/extension/base/ops.pyr	      s    zBaseOpsUtil.get_op_from_namec             C   s    | j |}| j||||| d S )N)r	   	_check_op)r
   sr   otherexcopr   r   r   check_opname   s    
zBaseOpsUtil.check_opnamec          
   C   s   |d krv|||}t |tjr\t|jdkr0t|jd d df j||j }| j	|| q|j||}| j
|| n tj| ||| W d Q R X d S )Nr   r   )
isinstancepd	DataFramelencolumnsNotImplementedErroriloccombineZto_frameZassert_frame_equalassert_series_equalpytestraises)r
   r   r   r   r   r   resultexpectedr   r   r   r      s    
zBaseOpsUtil._check_opc       	   
   C   s   |d kr^|||\}}|t kr2|| ||  }}n|| ||  }}| j|| | j|| n tj| t || W d Q R X d S )N)divmodr   r   r   )	r
   r   r   r   r   Z
result_divZ
result_modZexpected_divZexpected_modr   r   r   _check_divmod_op$   s    zBaseOpsUtil._check_divmod_opN)	__name__
__module____qualname__r	   	Exceptionr   r   r   r"   r   r   r   r   r      s   r   c               @   s   e Zd ZU dZeZeee  eZeee  eZ	eee  	eZ
eee  
dd Zejjddddd Zd	d
 Zdd Zdd Zdd Zdd Zdd ZdS )BaseArithmeticOpsTestsa?  
    Various Series and DataFrame arithmetic ops methods.

    Subclasses supporting various ops should set the class variables
    to indicate that they support ops of that kind

    * series_scalar_exc = TypeError
    * frame_scalar_exc = TypeError
    * series_array_exc = TypeError
    * divmod_exc = TypeError
    c             C   s,   |}t j|}| j|||jd | jd d S )Nr   )r   )r   Seriesr   r   series_scalar_exc)r
   dataall_arithmetic_operatorsr   r   r   r   r   test_arith_series_with_scalarE   s    
z4BaseArithmeticOpsTests.test_arith_series_with_scalarFz_reduce needs implementation)runreasonc             C   s.   |}t jd|i}| j|||d | jd d S )NAr   )r   )r   r   r   frame_scalar_exc)r
   r*   r+   r   dfr   r   r   test_arith_frame_with_scalarK   s    z3BaseArithmeticOpsTests.test_arith_frame_with_scalarc             C   s<   |}t j|}| j||t j|jd gt| | jd d S )Nr   )r   )r   r(   r   r   r   series_array_exc)r
   r*   r+   r   r   r   r   r   test_arith_series_with_arrayR   s    
z3BaseArithmeticOpsTests.test_arith_series_with_arrayc             C   s8   t j|}| j|td| jd | jdtj|| jd d S )Nr   )r   )r   r(   r"   r!   
divmod_excr   rdivmod)r
   r*   r   r   r   r   test_divmodZ   s    
z"BaseArithmeticOpsTests.test_divmodc             C   sJ   t j|}| j|t| |}| j|tj| t j|}| j|tj| d S )N)r   r(   r"   r!   r   r6   )r
   r*   Zdata_for_twosr   r   r   r   r   test_divmod_series_array_   s    

z/BaseArithmeticOpsTests.test_divmod_series_arrayc             C   s0   t j|}|| }t j|| }| j|| d S )N)r   r(   r   )r
   r*   r   r   r    r   r   r   $test_add_series_with_extension_arrayi   s    
z;BaseArithmeticOpsTests.test_add_series_with_extension_arrayc          
   C   s(   |}t jt t|| W d Q R X d S )N)r   r   AttributeErrorgetattr)r
   r*   r+   r   r   r   r   
test_erroro   s    z!BaseArithmeticOpsTests.test_errorc             C   sF   t j|}t|dr,|j|}|tksBtntjt|j	 dd S )N__add__z does not implement add)
r   r(   hasattrr=   NotImplementedAssertionErrorr   skiptyper#   )r
   r*   r   r   r   r   r   5test_direct_arith_with_series_returns_not_implementedu   s
    


zLBaseArithmeticOpsTests.test_direct_arith_with_series_returns_not_implementedN)r#   r$   r%   __doc__	TypeErrorr)   r   r   r0   r3   r5   r,   r   markZxfailr2   r4   r7   r8   r9   r<   rC   r   r   r   r   r'   3   s   

r'   c               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )BaseComparisonOpsTestsz4Various Series and DataFrame comparison ops methods.c          
   C   s   | j |}|dkr(|||j  stn\|dkrD|||j stn@t|||tksZttj|}tjt	 ||| W d Q R X d S )N__eq____ne__)
r	   allr@   r;   r?   r   r(   r   r   rE   )r
   r   r*   r   r   r   r   r   r   _compare_other   s    

z%BaseComparisonOpsTests._compare_otherc             C   s"   |}t j|}| j|||d d S )Nr   )r   r(   rK   )r
   r*   all_compare_operatorsr   r   r   r   r   test_compare_scalar   s    
z*BaseComparisonOpsTests.test_compare_scalarc             C   s:   |}t j|}t j|d gt| }| j|||| d S )Nr   )r   r(   r   rK   )r
   r*   rL   r   r   r   r   r   r   test_compare_array   s    
z)BaseComparisonOpsTests.test_compare_arrayc             C   s~   t j|}t|dr,|j|}|tksBtntjt|j	 dt|drd|j
|}|tksztntjt|j	 dd S )NrH   z does not implement __eq__rI   z does not implement __ne__)r   r(   r>   rH   r?   r@   r   rA   rB   r#   rI   )r
   r*   r   r   r   r   r   rC      s    




zLBaseComparisonOpsTests.test_direct_arith_with_series_returns_not_implementedN)r#   r$   r%   rD   rK   rM   rN   rC   r   r   r   r   rG      s
   rG   c               @   s   e Zd Zdd ZdS )BaseUnaryOpsTestsc             C   s4   t j|dd}| }t j| dd}| j|| d S )Nname)rP   )r   r(   r   )r
   r*   r   r   r    r   r   r   test_invert   s    zBaseUnaryOpsTests.test_invertN)r#   r$   r%   rQ   r   r   r   r   rO      s   rO   )typingr   r   r   Zpandasr   Zpandas._testingZ_testingr   Zpandas.corer   baser   r   r'   rG   rO   r   r   r   r   <module>   s   
'M0