U
    NZf$                  	   @   sh  d dl Zd dlZd dlmZmZmZmZmZm	Z	m
Z
 d dlmZ dd Zdd Zdd Zejd	d
dgdd Zdd Zdd Zdd Zdd Zdd Zejddd
gdd Zdd Zejddd ejejfe	e	feje	fgd!d" Zd#d$ Zejd	d
dgd%d& Zd'd( Zd)d* Z d+d, Z!d-d. Z"d/d0 Z#ejd1dd
gejd2dd
gd3d4 Z$dS )5    N)NACategoricalCategoricalIndexIndex
MultiIndexNaT
RangeIndexc               	   C   sR   d} t dddg}tddddg}tjt| d	 tj||d
d W 5 Q R X d S )NzIndex are different

Index levels are different
\[left\]:  1, Index\(\[1, 2, 3\], dtype='int64'\)
\[right\]: 2, MultiIndex\(\[\('A', 1\),
            \('A', 2\),
            \('B', 3\),
            \('B', 4\)\],
           \)         Ar	   r   r
   Br   r      matchFexact)r   r   from_tuplespytestraisesAssertionErrortmassert_index_equalmsgidx1idx2 r!   M/tmp/pip-unpacked-wheel-nbcvw55c/pandas/tests/util/test_assert_index_equal.py test_index_equal_levels_mismatch   s
    
r#   c              	   C   sV   d}t ddddg}t ddddg}tjt|d tj||| d W 5 Q R X d S )NMultiIndex level \[1\] are different

MultiIndex level \[1\] values are different \(25\.0 %\)
\[left\]:  Index\(\[2, 2, 3, 4\], dtype='int64'\)
\[right\]: Index\(\[1, 2, 3, 4\], dtype='int64'\)r   r   r   r   r   check_exactr   r   r   r   r   r   r   r&   r   r   r    r!   r!   r"    test_index_equal_values_mismatch"   s
    r)   c              	   C   sP   d}t dddg}t ddddg}tjt|d tj||| d W 5 Q R X d S )NzIndex are different

Index length are different
\[left\]:  3, Index\(\[1, 2, 3\], dtype='int64'\)
\[right\]: 4, Index\(\[1, 2, 3, 4\], dtype='int64'\)r	   r
   r   r   r   r%   r   r   r   r   r   r   r(   r!   r!   r"    test_index_equal_length_mismatch0   s
    r+   r   Fequivc                 C   s*   t dddg}td}tj||| d d S )Nr   r	   r
   r   r   )r   r   r   r   )r   r   r    r!   r!   r"   test_index_equal_class>   s    r-   c              	   C   sV   d}t dddg}t dddgtjd}tjt|d tj||d| d W 5 Q R X d S )	NzcIndex are different

Attribute "inferred_type" are different
\[left\]:  integer
\[right\]: floatingr	   r
   r   Zdtyper   Tr   r&   )r   npZfloat64r   r   r   r   r   r(   r!   r!   r"   )test_int_float_index_equal_class_mismatchF   s
    r1   c              	   C   sN   d}t dddg}ttd}tjt|d tj||d| d W 5 Q R X d S )NzkIndex are different

Index classes are different
\[left\]:  Index\(\[1, 2, 3\], dtype='int64'\)
\[right\]: r	   r
   r   r   Tr/   )r   r   ranger   r   r   r   r   r(   r!   r!   r"   %test_range_index_equal_class_mismatchT   s
    r3   c              	   C   sd   t dddg}t dddg}| rPd}tjt|d tj||| d W 5 Q R X ntj||| d d S )Nr	   r
         @go   @zIndex are different

Index values are different \(33\.33333 %\)
\[left\]:  Index\(\[1.0, 2.0, 3.0], dtype='float64'\)
\[right\]: Index\(\[1.0, 2.0, 3.0000000001\], dtype='float64'\)r   r%   r*   )r&   r   r    r   r!   r!   r"   test_index_equal_values_closeb   s    r5   c              	   C   sv   t dddg}t dddg}| |d}| s2|dk rbd}tjt|d tj||f| W 5 Q R X ntj||f| d S )	Nr	   r
   r4   g9m4 @r&   rtolgMb@?zIndex are different

Index values are different \(33\.33333 %\)
\[left\]:  Index\(\[1.0, 2.0, 3.0], dtype='float64'\)
\[right\]: Index\(\[1.0, 2.0, 3.0001\], dtype='float64'\)r   r*   r&   r7   r   r    kwargsr   r!   r!   r"   "test_index_equal_values_less_closes   s    
r:   c              	   C   sX   t dddg}t dddg}| |d}d}tjt|d tj||f| W 5 Q R X d S )Nr	   r
   r   r   r6   zIndex are different

Index values are different \(33\.33333 %\)
\[left\]:  Index\(\[1, 2, 3\], dtype='int64'\)
\[right\]: Index\(\[1, 2, 4\], dtype='int64'\)r   r*   r8   r!   r!   r"   test_index_equal_values_too_far   s    
r;   check_orderTc              	   C   sl   t dddg}t dddg}d}|rTtjt|d tj||| |dd W 5 Q R X ntj||| |dd d S )	Nr	   r
   r   zIndex are different

Index values are different \(66\.66667 %\)
\[left\]:  Index\(\[1, 2, 3\], dtype='int64'\)
\[right\]: Index\(\[3, 2, 1\], dtype='int64'\)r   T)r&   r7   r<   Fr*   )r&   r7   r<   r   r    r   r!   r!   r"   $test_index_equal_value_oder_mismatch   s&            r=   c              	   C   s`   t ddddg}t ddddg}| |d}d}tjt|d tj||f| W 5 Q R X d S )Nr   r   r   r   r6   r$   r   r'   r8   r!   r!   r"   &test_index_equal_level_values_mismatch   s    
r>   zname1,name2)Nx)r?   r?   c              	   C   s   t dddg| d}t dddg|d}| |ks4| |krBt|| nX| dkrNdn| } |dkr^dn|}d|  d| d	}tjt|d
 t|| W 5 Q R X d S )Nr	   r
   r   namer?   z'x'zBIndex are different

Attribute "names" are different
\[left\]:  \[z\]
\[right\]: \[z\]r   )r   r   r   r   r   r   )Zname1Zname2r   r    r   r!   r!   r"   test_index_equal_names   s    rB   c              	   C   sr   d}t tddg}t tddgdddgd}| r^tjt|d tj||| d W 5 Q R X ntj||| d d S )NzIndex are different

Attribute "dtype" are different
\[left\]:  CategoricalDtype\(categories=\['a', 'b'\], ordered=False\)
\[right\]: CategoricalDtype\(categories=\['a', 'b', 'c'\], ordered=False\)abc)
categoriesr   )check_categorical)r   r   r   r   r   r   r   )rG   r   r   r    r!   r!   r"   "test_index_equal_category_mismatch   s    rH   c              	   C   sl   d}t td}t ttd}| rV|rVtjt|d tj||ddd W 5 Q R X ntj||| |d d S )NzIndex are different

Index classes are different
\[left\]:  RangeIndex\(start=0, stop=10, step=1\)
\[right\]: Index\(\[0, 1, 2, 3, 4, 5, 6, 7, 8, 9\], dtype='int64'\)
   r   T)rG   r   )	r   r   listr2   r   r   r   r   r   )rG   r   r   ZrcatZicatr!   r!   r"   !test_index_equal_range_categories   s       rK   c               	   C   sL   d} t ttdg}t ttg}tjt| d t	|| W 5 Q R X d S )NzaIndex are different

Attribute "inferred_type" are different
\[left\]:  mixed
\[right\]: datetimeZnatr   )
r   r   r0   Z
datetime64r   r   r   r   r   r   r   r!   r!   r"   0test_assert_index_equal_different_inferred_types   s
    rL   c               	   C   sP   t ddgdd} t ddgdd}tjtdd tj| |dd	d
 W 5 Q R X d S )Nr	   r   rC   r@   rD   z"names" are differentr   FT)r<   check_namesr*   r   r    r!   r!   r"   9test_assert_index_equal_different_names_check_order_false  s    rO   c                  C   s"   t dddg} tj| | dd d S )NZfoobar*   Fr<   r   r   r   )idxr!   r!   r"   #test_assert_index_equal_mixed_dtype  s    rU   c                 C   s4   t ddg| d}t ddg| d}tj||dd d S )Nr	   r   r.   FrR   rS   )Zany_numeric_ea_dtyper   r    r!   r!   r"   ,test_assert_index_equal_ea_dtype_order_false  s    rV   c                  C   s4   t ddgdd} t ddgdd}tj| |dd d S )Nr	   r   objectr.   FrR   rS   rN   r!   r!   r"   /test_assert_index_equal_object_ints_order_false  s    rX   rG   rM   c              	   C   sP   t ddgdd}t dtgdd}tjtdd tj||| |d W 5 Q R X d S )Nr	   r
   ZInt64r.   z50.0 %r   )rM   rG   )r   r   r   r   r   r   r   )rM   rG   r   r    r!   r!   r"   *test_assert_ea_index_equal_non_matching_na#  s       rY   )%Znumpyr0   r   Zpandasr   r   r   r   r   r   r   Zpandas._testingZ_testingr   r#   r)   r+   markZparametrizer-   r1   r3   r5   r:   r;   r=   r>   nanrB   rH   rK   rL   rO   rU   rV   rX   rY   r!   r!   r!   r"   <module>   s@   $	



