U
    c/                  
   @   s  d dl Z d dlZd dlmZ d dlmZ e jddgddd Ze jdd	gdd
d Z	dd Z
dd Zdd Ze jdddgdd Ze jdeddddgiedddddgifedddgdddgdeddddgifgdd Ze jd ejddgd!d"gd#d$gd%ejd&d'gd!d"gd#d$gd%d(fejddgd)d*gd!d"gd+d$d,gd%ejd&d'gd)d*gd!d"gd+d$d,gd%d-fgd.d/ Zd0d1 Ze jdddgd2d3 Ze jdddgd4d5 Zd6d7 Ze jd ed8d9d:gd;d<d=gd>ed8d9d:gd;d<d?gd>d@fed8d9d:gd;d<d=gd>ed$d$d$gdAdAdAgd>dBfgdCdD ZdEdF ZdGdH Ze jdIdJdKgdLdM Ze jdNdOdPdQgdRdS ZdTdU ZdVdW ZdXdY Ze jdZd[d\gd]d^ Zd_d` Z dadb Z!dcdd Z"dS )e    N)	DataFrameTF)paramsc                 C   s   | j S Nparamrequest r	   M/tmp/pip-unpacked-wheel-g7fro6k3/pandas/tests/util/test_assert_frame_equal.pyby_blocks_fixture   s    r   r   ZSeriesc                 C   s   | j S r   r   r   r	   r	   r
   obj_fixture   s    r   c                 K   s$   t j| |f| t j|| f| dS )a4  
    Check that two DataFrame equal.

    This check is performed commutatively.

    Parameters
    ----------
    a : DataFrame
        The first DataFrame to compare.
    b : DataFrame
        The second DataFrame to compare.
    kwargs : dict
        The arguments passed to `tm.assert_frame_equal`.
    N)tmassert_frame_equalabkwargsr	   r	   r
   _assert_frame_equal_both   s    r   c              	   K   s2   d}t jt|d tj| |f| W 5 Q R X dS )a  
    Check that two DataFrame are not equal.

    Parameters
    ----------
    a : DataFrame
        The first DataFrame to compare.
    b : DataFrame
        The second DataFrame to compare.
    kwargs : dict
        The arguments passed to `tm.assert_frame_equal`.
    z;The two DataFrames were equal when they shouldn't have beenmatchNpytestraisesAssertionErrorr   r   )r   r   r   msgr	   r	   r
   _assert_not_frame_equal%   s    r   c                 K   s    t | |f| t || f| dS )a<  
    Check that two DataFrame are not equal.

    This check is performed commutatively.

    Parameters
    ----------
    a : DataFrame
        The first DataFrame to compare.
    b : DataFrame
        The second DataFrame to compare.
    kwargs : dict
        The arguments passed to `tm.assert_frame_equal`.
    N)r   r   r	   r	   r
   _assert_not_frame_equal_both7   s    r   
check_likec              	   C   s   t dddgdddgddd	d
gd}t dddgdddgdd
d	dgd}| s| d}tjt|d tj||| |d W 5 Q R X nt||| |d d S )N                  ABr   r   cindexz.index are differentr   r   obj)r   r   r   r   r   r   r   )r   r   df1df2r   r	   r	   r
   #test_frame_equal_row_order_mismatchJ   s    $$
r.   zdf1,df2r%   r   r   r    r!   r"   r#   r$   c              	   C   s8   | d}t jt|d tj| ||d W 5 Q R X d S )Nz are differentr   r+   r   )r,   r-   r   r   r	   r	   r
   test_frame_equal_shape_mismatchW   s    
r0   zdf1,df2,msgl1l2)r   r'   r   r(   g      ?g       @zDataFrame\.index are differentg @g      ?)r   r   r'   r   z$MultiIndex level \[0\] are differentc              	   C   sL   d|i}|r8t jt|d tj| |f| W 5 Q R X ntj| |f| d S )Ncheck_index_typer   r   )r,   r-   r   r3   r   r	   r	   r
   %test_frame_equal_index_dtype_mismatche   s
    r4   c              	   C   s~   ddg}t |d}t |d}d| i}|d d|d< | rjd}tjt|d tj||f| W 5 Q R X ntj||f| d S )NZcol1Zcol2)columnscheck_dtypeint64z)Attributes of DataFrame\..* are differentr   )r   astyper   r   r   r   r   )r6   r5   r,   r-   r   r   r	   r	   r
   test_empty_dtypes   s    

r9   c              	   C   s   | d| d}t dddgdddgd	d
ddgd}t dddgdddgd	d
ddgd}tjt|d tj||| |d W 5 Q R X d S )Nz\.index are different

z\.index values are different \(33\.33333 %\)
\[left\]:  Index\(\['a', 'b', 'c'\], dtype='object'\)
\[right\]: Index\(\['a', 'b', 'd'\], dtype='object'\)r   r   r    r!   r"   r#   r$   r   r   r'   r(   dr   r*   r   r   r   r   r   r   r   r   r   r,   r-   r	   r	   r
   test_frame_equal_index_mismatch   s
    $$r=   c              	   C   s   | d| d}t dddgdddgd	d
ddgd}t dddgdddgdd
ddgd}tjt|d tj||| |d W 5 Q R X d S )Nz\.columns are different

z\.columns values are different \(50\.0 %\)
\[left\]:  Index\(\['A', 'B'\], dtype='object'\)
\[right\]: Index\(\['A', 'b'\], dtype='object'\)r   r   r    r!   r"   r#   r$   r   r   r'   r(   )r%   r   r   r*   r;   r<   r	   r	   r
   !test_frame_equal_columns_mismatch   s
    $$r>   c              	   C   sx   |}| d| 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 W 5 Q R X d S )Nz2\.iloc\[:, 1\] \(column name="B"\) are different

z\.iloc\[:, 1\] \(column name="B"\) values are different \(33\.33333 %\)
\[index\]: \[0, 1, 2\]
\[left\]:  \[4, 5, 6\]
\[right\]: \[4, 5, 7\]r   r   r    r!   r"   r#   r$      r   Z	by_blocksr+   r;   )r   r   r+   r   r,   r-   r	   r	   r
   test_frame_equal_block_mismatch   s    rA      á   à   ä   é   è   ë)r%   Eu   e̊u   {obj}\.iloc\[:, 1\] \(column name="E"\) are different

{obj}\.iloc\[:, 1\] \(column name="E"\) values are different \(33\.33333 %\)
\[index\]: \[0, 1, 2\]
\[left\]:  \[é, è, ë\]
\[right\]: \[é, è, e̊\]eu   {obj}\.iloc\[:, 0\] \(column name="A"\) are different

{obj}\.iloc\[:, 0\] \(column name="A"\) values are different \(100\.0 %\)
\[index\]: \[0, 1, 2\]
\[left\]:  \[á, à, ä\]
\[right\]: \[a, a, a\]c              	   C   s<   |j |d}tjt|d tj| |||d W 5 Q R X d S )Nr/   r   r@   )formatr   r   r   r   r   )r,   r-   r   r   r   r	   r	   r
   test_frame_equal_unicode   s    rK   c               	   C   sb   t ddddgidd} | t}d}tj| |dd	 tjt|d
 tj| |dd	 W 5 Q R X d S )Nr   r   r   r    Int64dtypezAttributes of DataFrame\.iloc\[:, 0\] \(column name="a"\) are different

Attribute "dtype" are different
\[left\]:  Int64
\[right\]: int[32|64]Fr6   r   T)r   r8   intr   r   r   r   r   leftrightr   r	   r	   r
   0test_assert_frame_equal_extension_dtype_mismatch   s    
rT   c               	   C   sf   t dtddgidd} | t}d}tj| |dd tjt	|d	 tj| |d
d W 5 Q R X d S )Nr   r   r   intervalrM   zAttributes of DataFrame\.iloc\[:, 0\] \(column name="a"\) are different

Attribute "dtype" are different
\[left\]:  interval\[int64, right\]
\[right\]: objectFrO   r   T)
r   pdZIntervalr8   objectr   r   r   r   r   rQ   r	   r	   r
   /test_assert_frame_equal_interval_dtype_mismatch   s    
rX   right_dtypeZInt32r7   c                 C   s@   t ddddgidd}t ddddgi| d}tj||dd d S )	Nr   r   r   r    rL   rM   FrO   r   r   r   )rY   rR   rS   r	   r	   r
   7test_assert_frame_equal_ignore_extension_dtype_mismatch  s    r[   rN   ztimedelta64[ns]zdatetime64[ns, UTC]z	Period[D]c                 C   s0   t dg i| d}t dg i}tj||dd d S )Nr   rM   FrO   rZ   )rN   r,   r-   r	   r	   r
   4test_assert_frame_equal_datetime_like_dtype_mismatch  s    	r\   c               	   C   s   t  } t  jdd}t| |  t|| tj| |dd tj|| dd tjtdd t| | W 5 Q R X tjtdd t| | W 5 Q R X d S )NF)allows_duplicate_labelsZcheck_flagsz<Flagsr   )r   Z	set_flagsr   r   r   r   r   rR   rS   r	   r	   r
   test_allows_duplicate_labels!  s    r`   c                  C   s6   t dddggdddgdddgd} tj| | d	d
 d S )Nr   r   r   Zfoobar*   test)r5   r)   Tr   rZ   )Zdfr	   r	   r
   +test_assert_frame_equal_columns_mixed_dtype0  s    "re   c                 C   s$   | ddg|d}t j||dd d S )Nr   r   rM   T)check_exact)r   assert_equal)frame_or_seriesany_numeric_ea_dtyper+   r	   r	   r
    test_frame_equal_extension_dtype6  s    rj   indexer)r   r   )r   r   c              	   C   sl   |df}| ddg||d  d}| ddg||d  d}d}t jt|d tj||dd	d
 W 5 Q R X d S )Nr7   r   r   r   rM   zI(Series|DataFrame.iloc\[:, 0\] \(column name="0"\) classes) are differentr   TF)rf   r6   )r   r   r   r   rg   )rh   ri   rk   ZdtypesZobj1obj2r   r	   r	   r
   test_frame_equal_mixed_dtypes<  s    rm   c               	   C   sX   t tjg ddd} t tjddddd}tjtdd tj| |d	d
 W 5 Q R X d S )NrW   rM   r(   r   r   )startstopstepzDataFrame.index are differentr   Trd   )	r   rV   ZIndexZ
RangeIndexr   r   r   r   r   )r,   r-   r	   r	   r
   4test_assert_frame_equal_check_like_different_indexesF  s    rq   c               	   C   sv   t ddgddgg} d| j_t ddgddgg}d|j_tj| |dd tjtdd	 tj| |dd W 5 Q R X d S )
Nr   r   r    r!   FTr^   r]   r   )r   flagsr]   r   r   r   r   r   r_   r	   r	   r
   0test_assert_frame_equal_checking_allow_dups_flagN  s    rs   c               
   C   s   t dgdgdggtjtdddgtdddggd} t dgdgdggtjtdddgtdddggd}tj| |dd	 d S )
Nr   r   r    r   r   r'   r(   Trd   )r   rV   Z
MultiIndexZfrom_arraysZCategoricalr   r   r_   r	   r	   r
   3test_assert_frame_equal_check_like_categorical_midx[  s"    		rt   )#r   ZpandasrV   r   Zpandas._testingZ_testingr   Zfixturer   r   r   r   r   markZparametrizer.   r0   Zfrom_recordsr4   r9   r=   r>   rA   rK   rT   rX   r[   r\   r`   re   rj   rm   rq   rs   rt   r	   r	   r	   r
   <module>   s   


$*
  








	