U
    f/e                     @   sb   d Z ddlZddlZddlmZmZmZmZ ddl	m
Z ddlmZ dddZdd Zd	d
 ZdS )z)
Assertion helpers for arithmetic tests.
    N)	DataFrameIndexSeriesarray)PandasArrayc              	   C   s   t jt|d | |  W 5 Q R X t jt|d ||   W 5 Q R X t jt|d | |  W 5 Q R X t jt|d ||   W 5 Q R X dS )z
    Helper to assert that left and right can be neither added nor subtracted.

    Parameters
    ----------
    left : object
    right : object
    msg : str or None, default None
    matchN)pytestraises	TypeError)leftrightmsg r   B/tmp/pip-unpacked-wheel-tiezk1ph/pandas/tests/arithmetic/common.pyassert_invalid_addsub_type   s    
r   c                 C   sF   | t kst|t rt S | tks(t|tr,tS | tks>t|trBtS | S )z?
    Given two box-types, find the one that takes priority
    )r   
isinstancer   r   )boxZvectorr   r   r   get_upcast_box%   s    r   c              	   C   s  |t tfkr|ntj}dd }|| |k}|tj|jtjd}t|| ||| k}t|| || |k}t||  ||| k}t||  dddddd	g}t	j
t|d
 | |k  W 5 Q R X t	j
t|d
 | |k W 5 Q R X t	j
t|d
 | |k W 5 Q R X t	j
t|d
 | |k W 5 Q R X t	j
t|d
 || k  W 5 Q R X t	j
t|d
 || k W 5 Q R X t	j
t|d
 || k W 5 Q R X t	j
t|d
 || k W 5 Q R X dS )a  
    Assert that comparison operations with mismatched types behave correctly.

    Parameters
    ----------
    left : np.ndarray, ExtensionArray, Index, or Series
    right : object
    box : {pd.DataFrame, pd.Series, pd.Index, pd.array, tm.to_array}
    c                 S   s   t | tr| jS | S )N)r   r   Z_ndarray)xr   r   r   xbox2A   s    
z(assert_invalid_comparison.<locals>.xbox2)Zdtype|zInvalid comparison betweenzCannot compare typeznot supported betweenzinvalid type promotionzThe DTypes <class 'numpy.dtype\[datetime64\]'> and <class 'numpy.dtype\[int64\]'> do not have a common DType. For example they cannot be stored in a single array unless the dtype is `object`.r   N)r   r   npzerosshapeZbool_tmZassert_equaljoinr	   r
   r   )r   r   r   Zxboxr   resultexpectedr   r   r   r   assert_invalid_comparison2   sF    r   )N)__doc__Znumpyr   r	   Zpandasr   r   r   r   Zpandas._testingZ_testingr   Zpandas.core.arraysr   r   r   r   r   r   r   r   <module>   s   
