U
    c00                     @   s  d dl Zd dlZd dlmZ d dlZd dlmZmZm	Z	 d dl
mZ dd Zdd Zdd	 Zejd
edededgdd Zejdededdfededfededfededfededfgdd Zejdddiddddgiddigdd  Zejdd!d"gejdd#dd$gejd%d dddd&d'gd(d) Zejd*e	d+d,gddgd-e	d+d,gd.d/gd-d0fejddgd1d2gd+d,gd3d4d5gd-jejd.d/gd1d2gd+d,gd3d4d5gd-jd6fgd7d8 Zejd9d:d;gd<d= Zejd>d:d;gd?d@ ZdAdB ZdCdD ZdEdF ZdGdH Z dIdJ Z!dKdL Z"dMdN Z#dOdP Z$dQdR Z%dSdT Z&ejdUdVdWgdXdY Z'dZd[ Z(d\d] Z)d^d_ Z*dS )`    N)is_extension_array_dtype)Categorical	DataFrameSeriesc                 K   s$   t j| |f| t j|| f| dS )a&  
    Check that two Series equal.

    This check is performed commutatively.

    Parameters
    ----------
    a : Series
        The first Series to compare.
    b : Series
        The second Series to compare.
    kwargs : dict
        The arguments passed to `tm.assert_series_equal`.
    N)tmassert_series_equalabkwargs r   N/tmp/pip-unpacked-wheel-g7fro6k3/pandas/tests/util/test_assert_series_equal.py_assert_series_equal_both   s    r   c                 K   s>   z$t j| |f| d}tj|d W n tk
r8   Y nX dS )a  
    Check that two Series are not equal.

    Parameters
    ----------
    a : Series
        The first Series to compare.
    b : Series
        The second Series to compare.
    kwargs : dict
        The arguments passed to `tm.assert_series_equal`.
    z7The two Series were equal when they shouldn't have been)msgN)r   r   pytestZfailAssertionError)r	   r
   r   r   r   r   r   _assert_not_series_equal"   s    r   c                 K   s    t | |f| t || f| dS )a.  
    Check that two Series are not equal.

    This check is performed commutatively.

    Parameters
    ----------
    a : Series
        The first Series to compare.
    b : Series
        The second Series to compare.
    kwargs : dict
        The arguments passed to `tm.assert_series_equal`.
    N)r   r   r   r   r   _assert_not_series_equal_both8   s    r   data   abcu   áàäc                 C   s   t t| t|  d S N)r   r   )r   r   r   r   test_series_equalK   s    r   zdata1,data2      Zxyzu   éèës   aaac                 C   s   t t| t| d S r   )r   r   )data1data2r   r   r   $test_series_not_equal_value_mismatchP   s    r   r   dtypeZfloat64index   nameZfooc                 C   s*   t d}t|}t|f| }t|| d S )Nr   )ranger   r   )r   r   s1s2r   r   r   'test_series_not_equal_metadata_mismatch^   s    	r%   )g|Pk?g9]?)gV-?g??Zfloat32ZFloat32decimals   
   c              	   C   s   d|  }t | g|d}t |g|d}|dksN|dksN|dkrt| | dkrt|r\d}nd}tjt|d tj|||d	 W 5 Q R X nt|||d	 d S )
Nr(   r   r'   r   gMb@?zExtensionArray are differentzSeries values are differentmatchrtol)	r   absr   r   raisesr   r   r   r   )r   r   r   r&   r-   r#   r$   r   r   r   r   test_less_precisen   s    
r0   z	s1,s2,msgl1l2r   g      ?g       @zSeries\.index are differentg @g      ?)r	   r
   cr	   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   r   )r#   r$   r   r5   r   r   r   r   test_series_equal_index_dtype   s
    r6   
check_likeTFc              	   C   sr   t dddgdddgd}t dddgdddgd}| s`tjtdd	 tj||| d
 W 5 Q R X nt||| d
 d S )Nr   r    r   r	   r
   r4   r3   Series.index are differentr*   )r7   r   r   r/   r   r   r   r   )r7   r#   r$   r   r   r    test_series_equal_order_mismatch   s    r:   check_indexc              	   C   sr   t dddgdddgd}t dddgdddgd}| r`tjtdd	 tj||| d
 W 5 Q R X nt||| d
 d S )Nr   r    r   r	   r
   r4   r3   r8   r*   )r;   r9   )r;   r#   r$   r   r   r    test_series_equal_index_mismatch   s    r<   c               	   C   sD   t td} t td}tjtdd tj| |ddd W 5 Q R X d S )Nr)   z0check_like must be False if check_index is Falser*   FT)r;   r7   )r   objectr   r/   
ValueErrorr   r   leftrightr   r   r   %test_series_invalid_param_combination   s    

 rB   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 )NzSeries are different

Series length are different
\[left\]:  3, RangeIndex\(start=0, stop=3, step=1\)
\[right\]: 4, RangeIndex\(start=0, stop=4, step=1\)r   r    r   r   r*   r,   r   r   r/   r   r   r   r-   r   r#   r$   r   r   r   !test_series_equal_length_mismatch   s
    rE   c              	   C   sN   d}t dddg}t dddg}tjt|d tj||| d W 5 Q R X d S )NzSeries are different

Series values are different \(33\.33333 %\)
\[index\]: \[0, 1, 2\]
\[left\]:  \[1, 2, 3\]
\[right\]: \[1, 2, 4\]r   r    r   r   r*   r,   rC   rD   r   r   r   )test_series_equal_numeric_values_mismatch   s
    rF   c              	   C   sV   d}t tdddg}t tdddg}tjt|d tj||| d W 5 Q R X d S )NzSeries are different

Series values are different \(66\.66667 %\)
\[index\]: \[0, 1, 2\]
\[left\]:  \['a', 'b', 'c'\]
Categories \(3, object\): \['a', 'b', 'c'\]
\[right\]: \['a', 'c', 'b'\]
Categories \(3, object\): \['a', 'b', 'c'\]r	   r
   r4   r*   r,   )r   r   r   r/   r   r   r   rD   r   r   r   -test_series_equal_categorical_values_mismatch   s
    	rG   c              	   C   sZ   d}t tjdddd}t tjdddd}tjt|d tj||| d W 5 Q R X d S )	Nznumpy array are different

numpy array values are different \(100.0 %\)
\[index\]: \[0, 1, 2\]
\[left\]:  \[1514764800000000000, 1514851200000000000, 1514937600000000000\]
\[right\]: \[1549065600000000000, 1549152000000000000, 1549238400000000000\]z
2018-01-01r   D)Zperiodsfreqz
2019-02-02r*   r,   )r   pdZ
date_ranger   r/   r   r   r   rD   r   r   r   *test_series_equal_datetime_values_mismatch   s
    rK   c              	   C   sn   d}t tddg}t tddgtdd}| r\tjt|d tj||| d W 5 Q R X nt||| d d S )NzAttributes of Series are different

Attribute "dtype" are different
\[left\]:  CategoricalDtype\(categories=\['a', 'b'\], ordered=False\)
\[right\]: CategoricalDtype\(categories=\['a', 'b', 'c'\], ordered=False\)r	   r
   r   )
categoriesr*   )check_categorical)	r   r   listr   r/   r   r   r   r   )rM   r   r#   r$   r   r   r   &test_series_equal_categorical_mismatch   s    rO   c               	   C   sd   t tjdddg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   Int64r)   zjAttributes of Series are different

Attribute "dtype" are different
\[left\]:  Int64
\[right\]: int[32|64]FZcheck_dtyper*   T)
r   rJ   arrayastypeintr   r   r   r/   r   r@   rA   r   r   r   r   1test_assert_series_equal_extension_dtype_mismatch  s    
rV   c               	   C   sb   t tddg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   intervalr)   zyAttributes of Series are different

Attribute "dtype" are different
\[left\]:  interval\[int64, right\]
\[right\]: objectFrQ   r*   T)
r   rJ   ZIntervalrS   r=   r   r   r   r/   r   rU   r   r   r   0test_assert_series_equal_interval_dtype_mismatch#  s    
rX   c               	   C   s   G dd dt } t ddg}t ddg}| ddg}tj||dd tj||dd tj||dd tj||dd tjtdd	 tj||dd W 5 Q R X tjtdd	 tj||dd W 5 Q R X d S )
Nc                   @   s   e Zd ZdS )z/test_series_equal_series_type.<locals>.MySeriesN)__name__
__module____qualname__r   r   r   r   MySeries5  s   r\   r   r    F)Zcheck_series_typeTzSeries classes are differentr*   r   r   r   r   r/   r   )r\   r#   r$   s3r   r   r   test_series_equal_series_type4  s    r_   c               	   C   s   t ddg} t ddg}t ddg}tj| |dd tj|| dd d}tjt|d tj| |dd W 5 Q R X d}tjt|d tj|| dd W 5 Q R X d S )Nr	   r
   TZcheck_exactzzSeries are different

Series values are different \(100\.0 %\)
\[index\]: \[0, 1\]
\[left\]:  \[a, b\]
\[right\]: \[b, a\]r*   zzSeries are different

Series values are different \(100\.0 %\)
\[index\]: \[0, 1\]
\[left\]:  \[b, a\]
\[right\]: \[a, b\]r]   )r#   r$   r^   r   r   r   r   &test_series_equal_exact_for_nonnumericI  s    ra   right_dtypeZInt32Zint64c                 C   s8   t dddgdd}t dddg| d}tj||dd d S )Nr   r    r   rP   r)   FrQ   )r   r   r   )rb   r@   rA   r   r   r   8test_assert_series_equal_ignore_extension_dtype_mismatche  s    rc   c               	   C   s   t dg} t dg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 )Nr   F)Zallows_duplicate_labels)Zcheck_flagsz<Flagsr*   )r   Z	set_flagsr   r   r   r/   r   r?   r   r   r   test_allows_duplicate_labelsm  s    
rd   c                 C   s<   t | g}t||  t|}t||jdd d S )NT)deep)r   r   r   copyrJ   ZIndexZassert_index_equal)Znulls_fixtureZseridxr   r   r   %test_assert_series_equal_identical_na|  s    

rh   c                  C   sp   t dddtddgg} t dddtddgg}t| |  tj| | dd t| | tj| |dd d S )Nr   g=ۊ?g߷>g	ﰴ9?g?Tr`   )r   nprR   r   r   )xyr   r   r   %test_identical_nested_series_is_equal  s$    
rl   )+Znumpyri   r   Zpandas.core.dtypes.commonr   ZpandasrJ   r   r   r   Zpandas._testingZ_testingr   r   r   r   markZparametrizer"   rN   r   r   r%   r0   Zfrom_recordsr4   r6   r:   r<   rB   rE   rF   rG   rK   rO   rV   rX   r_   ra   rc   rd   rh   rl   r   r   r   r   <module>   s   



  



	

