a
    j=ic=                     @   s|   d dl m Z mZ d dlZ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mZ d dlmZ G dd dZG dd dZdS )    datetime	timedeltaN)Categorical	DataFrameIndexSeries
date_rangeoption_contextperiod_rangetimedelta_rangec                   @   sH  e Z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dd Zdd Zdd Zej	dg ddd Zdd Zej	dddgdd  Zd!d" Zej	d#d$d%gd&d'ggd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zejd:d;d< Zd=d> Zd?d@ ZdAdB Z dCdD Z!dEdF Z"d&S )GTestSeriesReprc                 C   s@   |}t tt||dd}g d}d|}t||ks<J d S )NZsthindexname)zfirst  secondzfoo    one       0z       two       1z       three     2zbar    one       3z       two       4zbaz    two       5z       three     6zqux    one       7z       two       8z       three     9zName: sth, dtype: int64
)r   rangelenjoinrepr)selfZ%lexsorted_two_level_string_multiindexr   serexpected r   n/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/pandas/tests/series/test_repr.pytest_multilevel_name_print   s
    
z)TestSeriesRepr.test_multilevel_name_printc                 C   s<   t g d}d|_dt|v s"J d |_dt|vs8J d S )N)r         test
Name: testName:r   r   r   r   sr   r   r   test_small_name_printing,   s
    z'TestSeriesRepr.test_small_name_printingc                 C   s<   t td}d|_dt|v s"J d |_dt|vs8J d S )N  r   r   r    )r   r   r   r   r"   r   r   r   test_big_name_printing6   s
    z%TestSeriesRepr.test_big_name_printingc                 C   s(   t tdddtd}dt|v s$J d S )NZ20010101Z20020101r   )r   r   dtyper   )r   r	   objectr   r"   r   r   r   test_empty_name_printing@   s    z'TestSeriesRepr.test_empty_name_printingargsr   )r   c                 C   s*   t ttjdtjdg|R  d d S )Nr%   r   )strr   nprandomrandnarange)r   r*   r   r   r   test_float_rangeD   s    zTestSeriesRepr.test_float_rangec                 C   s   t ttd d S )Nr'   )r-   r   r(   r   r   r   r   test_empty_objectH   s    z TestSeriesRepr.test_empty_objectc                 C   s0   t | t |t tj|dd< t | d S )N      )r-   astypeintr.   NaN)r   string_seriesr   r   r   test_stringL   s    zTestSeriesRepr.test_stringc                 C   s   t | d S N)r-   )r   Zobject_seriesr   r   r   test_objectT   s    zTestSeriesRepr.test_objectc                 C   s,   t | |d}d |d d d< t| d S )NOr   )r-   r8   r   )r   Zdatetime_seriesZotsr   r   r   test_datetimeW   s    
zTestSeriesRepr.test_datetimer   ) r   g333333?foou   αβγZ7loooooooooooooooooooooooooooooooooooooooooooooooooooongrB   barZbaz)r   r   )rB   r   gffffff@)   αu   βu   γ)rE   rD   c                 C   s   ||_ t| d S r=   )r   r   )r   r   r;   r   r   r   test_various_names^   s    z!TestSeriesRepr.test_various_namesc                 C   s(   t tjdtddd}t| d S )Nr%   rC   r   )r   r.   r/   r0   r1   r   )r   Zbiggier   r   r   test_tuple_names   s    zTestSeriesRepr.test_tuple_nameargd     c                 C   s,   t tj|dd}t|}d|v s(J d S )Nr   r   zName: 0)r   r.   r/   r0   r   )r   rH   r   Zrep_strr   r   r   test_tidy_repr_name_0y   s    z$TestSeriesRepr.test_tidy_repr_name_0c                 C   sF   t dgddgd}dt|vs"J dt|vs2J dt|vsBJ d S )Nza
	bza
	dza
	f)r   r   	za
)r   r   )r   r   r   r   r   test_newline   s    zTestSeriesRepr.test_newlinezname, expectedrB   z#Series([], Name: foo, dtype: int64)NzSeries([], dtype: int64)c                 C   s$   t g tj|d}t||ks J d S )N)r'   r   )r   r.   int64r   )r   r   r   r#   r   r   r   test_empty_int64   s    	zTestSeriesRepr.test_empty_int64c                 C   s    t dgd }d|_t| d S )N   אr%   Ztitle1r!   )r   ar   r   r   test_tidy_repr   s    zTestSeriesRepr.test_tidy_reprc                 C   s8   t dd tdD }t| | }|jdks4J d S )Nc                 S   s   g | ]}t tjd d qS )r   )r   r.   r/   r0   .0ir   r   r   
<listcomp>       z7TestSeriesRepr.test_repr_bool_fails.<locals>.<listcomp>r6   rA   )r   r   r   Z
readouterrerr)r   Zcapsysr#   Zcapturedr   r   r   test_repr_bool_fails   s    z#TestSeriesRepr.test_repr_bool_failsc                 C   s0   t g dtdd}t| d|_t| d S )Nr   r      r]   rK   )rR   rR   )r   r.   rP   r   r   r"   r   r   r   !test_repr_name_iterable_indexable   s    z0TestSeriesRepr.test_repr_name_iterable_indexablec                 C   s4   g d}g d}t ||d}t| tks0J d S )N)   r6   r]   r6   )u   σu   τu   υu   φr,   )r   type__repr__r-   )r   dataZindex1dfr   r   r   test_repr_should_return_str   s    z*TestSeriesRepr.test_repr_should_return_strc                 C   s>   t dd   tttd W d    n1 s00    Y  d S )Ndisplay.max_rowsrJ   )r
   r-   r   r   r4   r   r   r   test_repr_max_rows   s    z!TestSeriesRepr.test_repr_max_rowsc                 C   s   t dgdd}t| d S )NrR   u   בrK   )r   r-   )r   rc   r   r   r    test_unicode_string_with_unicode   s    z/TestSeriesRepr.test_unicode_string_with_unicodec                 C   sL   t dgdd}d}tjt|d t| W d    n1 s>0    Y  d S )NabcrK   z2^'str' object cannot be interpreted as an integer$)match)r   pytestZraises	TypeErrorbytes)r   rc   msgr   r   r   test_str_to_bytes_raises   s    z'TestSeriesRepr.test_str_to_bytes_raisesc                 C   s   t dd tdD td}ttjt||}t| t	
d}t| d ds\J |jtjdt|d d	 }t| d  d S )
Nc                 S   s    g | ]}t d ddt| qS )  r   r   rU   r   r   r   rX      rY   zDTestSeriesRepr.test_timeseries_repr_object_dtype.<locals>.<listcomp>r%   r3   r+   zFreq:r   r   i  )r   r   r(   r   r.   r/   r0   r   r   tmZmakeTimeSeries
splitlines
startswithZilocrandint)r   r   tsZts2r   r   r   !test_timeseries_repr_object_dtype   s    
z0TestSeriesRepr.test_timeseries_repr_object_dtypezignore::FutureWarningc                 C   sb   d}t dddd, tg d}|| ks0J W d    n1 sD0    Y  | d u s^J d S )Nz\begin{tabular}{ll}
\toprule
{} &         0 \\
\midrule
0 &  $\alpha$ \\
1 &         b \\
2 &         c \\
\bottomrule
\end{tabular}
zdisplay.latex.escapeFzdisplay.latex.reprT)z$\alpha$bc)r
   r   _repr_latex_)r   resultr#   r   r   r   test_latex_repr   s
    
.zTestSeriesRepr.test_latex_reprc                 C   s6   t dtjg}tddg|d}d}t||ks2J d S )Nr   r   r,   z1.0    1
NaN    2
dtype: int64)r   r.   nanr   r   )r   rW   r#   expr   r   r   !test_index_repr_in_frame_with_nan   s    z0TestSeriesRepr.test_index_repr_in_frame_with_nanc                 C   s.   t dddd}|  td|d}t| d S )Nz1/1/1850z1/1/1950zA-DEC)freqr   r,   )r	   formatr   r   )r   rngrt   r   r   r   test_format_pre_1900_dates   s    z)TestSeriesRepr.test_format_pre_1900_datesc                 C   s4   t dddtjjgdd}t|}d}||ks0J d S )Nr   r%   ro   zM8[ns]r3   z0   1970-01-01 00:00:00.000000
1   1970-01-01 00:00:00.000001
2   1970-01-01 00:00:00.000002
3                          NaT
dtype: datetime64[ns])r   pdNaTvaluer   )r   Zseriesry   r   r   r   r   test_series_repr_nat   s
    z#TestSeriesRepr.test_series_repr_natc                 C   s(   t dgt}d}t||ks$J d S )Ng      ?z0    1.0
dtype: object)r   r8   r(   r   )r   r   r   r   r   r   test_float_repr   s    zTestSeriesRepr.test_float_reprc                 C   s6   t g ddd tjtjg}t|}d}||ks2J d S )Nr   r   r]      Tz4True    1
None    2
NaN     3
NaT     4
dtype: int64)r   r.   r{   r   r   r   )r   r   ry   r   r   r   r   test_different_null_objects  s    z*TestSeriesRepr.test_different_null_objects)#__name__
__module____qualname__r   r$   r&   r)   rj   markZparametrizer2   r5   r<   r>   r@   rF   rG   rL   rO   rQ   rT   r[   r^   rd   rf   rg   rn   ru   filterwarningsrz   r}   r   r   r   r   r   r   r   r   r      sR   





		

r   c                   @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )TestCategoricalReprc                    sL   G dd d t  fddtdD }t|}| }t| t| d S )Nc                   @   s"   e Zd ZdZdZedddZdS )zATestCategoricalRepr.test_categorical_repr_unicode.<locals>.Countyu   San SebastiánZPR)returnc                 S   s   | j d | j S )Nz, )r   stater4   r   r   r   ra     s    zJTestCategoricalRepr.test_categorical_repr_unicode.<locals>.County.__repr__N)r   r   r   r   r   r-   ra   r   r   r   r   County  s   r   c                    s   g | ]
}  qS r   r   )rV   _r   r   r   rX     rY   zETestCategoricalRepr.test_categorical_repr_unicode.<locals>.<listcomp>=   )r   r   r   Z	to_seriesr   r-   )r   catidxr   r   r   r   test_categorical_repr_unicode  s    z1TestCategoricalRepr.test_categorical_repr_unicodec                 C   s   t tg d}d}|| ks$J t tddgd }d}tdd  |t|ksXJ W d    n1 sl0    Y  td	}t tddg|d
d}d}|| ksJ d S )Nr   zO0    1
1    2
2    3
3    4
dtype: category
Categories (4, int64): [1, 2, 3, 4]rS   rv      zf0     a
1     b
     ..
48    a
49    b
Length: 50, dtype: category
Categories (2, object): ['a', 'b']re   r6   abcdefghijklmnopqrstuvwxyzT)
categoriesorderedzh0    a
1    b
dtype: category
Categories (26, object): ['a' < 'b' < 'c' < 'd' ... 'w' < 'x' < 'y' < 'z'])r   r   __str__r
   r   list)r   rS   r|   Zlevsr   r   r   test_categorical_repr  s    .z)TestCategoricalRepr.test_categorical_reprc                 C   sN   t tg d}d}t||ks$J t ttd}d}t||ksJJ d S )Nr\   zE0    1
1    2
2    3
dtype: category
Categories (3, int64): [1, 2, 3]
   z0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
dtype: category
Categories (10, int64): [0, 1, 2, 3, ..., 6, 7, 8, 9]r   r   r   r.   r1   r   r#   r|   r   r   r   test_categorical_series_repr:  s    z0TestCategoricalRepr.test_categorical_series_reprc                 C   sV   t tg ddd}d}t||ks(J t ttddd}d}t||ksRJ d S )Nr\   Tr   zG0    1
1    2
2    3
dtype: category
Categories (3, int64): [1 < 2 < 3]r   z0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
dtype: category
Categories (10, int64): [0 < 1 < 2 < 3 ... 6 < 7 < 8 < 9]r   r   r   r   r   $test_categorical_series_repr_orderedT  s    z8TestCategoricalRepr.test_categorical_series_repr_orderedc                 C   sb   t dddd}tt|}d}t||ks.J t ddddd}tt|}d}t||ks^J d S )	N2011-01-01 09:00Hr6   r~   periodsa2  0   2011-01-01 09:00:00
1   2011-01-01 10:00:00
2   2011-01-01 11:00:00
3   2011-01-01 12:00:00
4   2011-01-01 13:00:00
dtype: category
Categories (5, datetime64[ns]): [2011-01-01 09:00:00, 2011-01-01 10:00:00, 2011-01-01 11:00:00,
                                 2011-01-01 12:00:00, 2011-01-01 13:00:00]
US/Easternr~   r   tza  0   2011-01-01 09:00:00-05:00
1   2011-01-01 10:00:00-05:00
2   2011-01-01 11:00:00-05:00
3   2011-01-01 12:00:00-05:00
4   2011-01-01 13:00:00-05:00
dtype: category
Categories (5, datetime64[ns, US/Eastern]): [2011-01-01 09:00:00-05:00, 2011-01-01 10:00:00-05:00,
                                             2011-01-01 11:00:00-05:00, 2011-01-01 12:00:00-05:00,
                                             2011-01-01 13:00:00-05:00]r	   r   r   r   r   r   r#   r|   r   r   r   %test_categorical_series_repr_datetimen  s    	
z9TestCategoricalRepr.test_categorical_series_repr_datetimec                 C   sj   t dddd}tt|dd}d}t||ks2J t ddddd	}tt|dd}d
}t||ksfJ d S )Nr   r   r6   r   Tr   a6  0   2011-01-01 09:00:00
1   2011-01-01 10:00:00
2   2011-01-01 11:00:00
3   2011-01-01 12:00:00
4   2011-01-01 13:00:00
dtype: category
Categories (5, datetime64[ns]): [2011-01-01 09:00:00 < 2011-01-01 10:00:00 < 2011-01-01 11:00:00 <
                                 2011-01-01 12:00:00 < 2011-01-01 13:00:00]r   r   a  0   2011-01-01 09:00:00-05:00
1   2011-01-01 10:00:00-05:00
2   2011-01-01 11:00:00-05:00
3   2011-01-01 12:00:00-05:00
4   2011-01-01 13:00:00-05:00
dtype: category
Categories (5, datetime64[ns, US/Eastern]): [2011-01-01 09:00:00-05:00 < 2011-01-01 10:00:00-05:00 <
                                             2011-01-01 11:00:00-05:00 < 2011-01-01 12:00:00-05:00 <
                                             2011-01-01 13:00:00-05:00]r   r   r   r   r   -test_categorical_series_repr_datetime_ordered  s    	
zATestCategoricalRepr.test_categorical_series_repr_datetime_orderedc                 C   s`   t dddd}tt|}d}t||ks.J t dddd}tt|}d}t||ks\J d S )	Nr   r   r6   r   a  0    2011-01-01 09:00
1    2011-01-01 10:00
2    2011-01-01 11:00
3    2011-01-01 12:00
4    2011-01-01 13:00
dtype: category
Categories (5, period[H]): [2011-01-01 09:00, 2011-01-01 10:00, 2011-01-01 11:00, 2011-01-01 12:00,
                            2011-01-01 13:00]2011-01Mz0    2011-01
1    2011-02
2    2011-03
3    2011-04
4    2011-05
dtype: category
Categories (5, period[M]): [2011-01, 2011-02, 2011-03, 2011-04, 2011-05]r   r   r   r   r   r   r   r   #test_categorical_series_repr_period  s    	z7TestCategoricalRepr.test_categorical_series_repr_periodc                 C   sh   t dddd}tt|dd}d}t||ks2J t dd	dd}tt|dd}d
}t||ksdJ d S )Nr   r   r6   r   Tr   a  0    2011-01-01 09:00
1    2011-01-01 10:00
2    2011-01-01 11:00
3    2011-01-01 12:00
4    2011-01-01 13:00
dtype: category
Categories (5, period[H]): [2011-01-01 09:00 < 2011-01-01 10:00 < 2011-01-01 11:00 < 2011-01-01 12:00 <
                            2011-01-01 13:00]r   r   z0    2011-01
1    2011-02
2    2011-03
3    2011-04
4    2011-05
dtype: category
Categories (5, period[M]): [2011-01 < 2011-02 < 2011-03 < 2011-04 < 2011-05]r   r   r   r   r   +test_categorical_series_repr_period_ordered  s    	z?TestCategoricalRepr.test_categorical_series_repr_period_orderedc                 C   s\   t ddd}tt|}d}t||ks,J t ddd}tt|}d}t||ksXJ d S )N1 daysr6   r   z0   1 days
1   2 days
2   3 days
3   4 days
4   5 days
dtype: category
Categories (5, timedelta64[ns]): [1 days, 2 days, 3 days, 4 days, 5 days]1 hoursr   a  0   0 days 01:00:00
1   1 days 01:00:00
2   2 days 01:00:00
3   3 days 01:00:00
4   4 days 01:00:00
5   5 days 01:00:00
6   6 days 01:00:00
7   7 days 01:00:00
8   8 days 01:00:00
9   9 days 01:00:00
dtype: category
Categories (10, timedelta64[ns]): [0 days 01:00:00, 1 days 01:00:00, 2 days 01:00:00,
                                   3 days 01:00:00, ..., 6 days 01:00:00, 7 days 01:00:00,
                                   8 days 01:00:00, 9 days 01:00:00]r   r   r   r   r   r   r   r   &test_categorical_series_repr_timedelta  s    z:TestCategoricalRepr.test_categorical_series_repr_timedeltac                 C   sd   t ddd}tt|dd}d}t||ks0J t ddd}tt|dd}d	}t||ks`J d S )
Nr   r6   r   Tr   z0   1 days
1   2 days
2   3 days
3   4 days
4   5 days
dtype: category
Categories (5, timedelta64[ns]): [1 days < 2 days < 3 days < 4 days < 5 days]r   r   a  0   0 days 01:00:00
1   1 days 01:00:00
2   2 days 01:00:00
3   3 days 01:00:00
4   4 days 01:00:00
5   5 days 01:00:00
6   6 days 01:00:00
7   7 days 01:00:00
8   8 days 01:00:00
9   9 days 01:00:00
dtype: category
Categories (10, timedelta64[ns]): [0 days 01:00:00 < 1 days 01:00:00 < 2 days 01:00:00 <
                                   3 days 01:00:00 ... 6 days 01:00:00 < 7 days 01:00:00 <
                                   8 days 01:00:00 < 9 days 01:00:00]r   r   r   r   r   .test_categorical_series_repr_timedelta_ordered  s    zBTestCategoricalRepr.test_categorical_series_repr_timedelta_orderedN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s    r   )r   r   numpyr.   rj   Zpandasr   r   r   r   r   r	   r
   r   r   Zpandas._testingZ_testingrp   r   r   r   r   r   r   <module>   s   (
 w