U
    W7b=                     @   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                   @   sZ  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dddddddddd d!g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/d0ggd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Zd?d@ ZdAdB ZejdCdDdE ZdFdG ZdHdI ZdJdK Z dLdM Z!dNdO Z"d/S )PTestSeriesReprc                 C   sT   |}t tt||dd}ddddddd	d
ddddg}d|}t||ksPtd S )NZsthindexnamez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AssertionError)selfZ%lexsorted_two_level_string_multiindexr   serexpected r   A/tmp/pip-unpacked-wheel-rhjceu4d/pandas/tests/series/test_repr.pytest_multilevel_name_print   s"    
z)TestSeriesRepr.test_multilevel_name_printc                 C   s>   t dddg}d|_dt|ks$td |_dt|ks:td S )Nr         test
Name: testName:)r   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|ks"td |_dt|ks8td S )N  r   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|ks$td S )NZ20010101Z20020101r   )r   r   dtyper    )r   r	   objectr   r   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| d d S )Nr%   r   )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|ks(td S )Nr   r   zName: 0)r   r.   r/   r0   r   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|ks"tdt|ks2tdt|ksBtd S )Nza
	bza
	dza
	f)r   r   	za
)r   r   r   )r   r   r   r   r   test_newline   s    zTestSeriesRepr.test_newlinezname, expectedz#Series([], Name: foo, dtype: int64)NzSeries([], dtype: int64)c                 C   s$   t g tj|d}t||ks td S )N)r'   r   )r   r.   int64r   r   )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title1)r   r   r   )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s4td S )Nc                 S   s   g | ]}t tjd d qS )r   )r   r.   r/   r0   .0ir   r   r   
<listcomp>   s     z7TestSeriesRepr.test_repr_bool_fails.<locals>.<listcomp>r6   rA   )r   r   r   Z
readouterrerrr   )r   Zcapsysr#   Zcapturedr   r   r   test_repr_bool_fails   s    z#TestSeriesRepr.test_repr_bool_failsc                 C   s2   t dddgtdd}t| d|_t| d S )Nr   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   s<   ddddg}ddddg}t ||d}t| tks8td S )	N   r6   r[   u   σu   τu   υu   φr,   )r   type__repr__r-   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 5 Q R X 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   ra   r   r   r    test_unicode_string_with_unicode   s    z/TestSeriesRepr.test_unicode_string_with_unicodec              	   C   s8   t dgdd}d}tjt|d t| W 5 Q R X d S )NabcrK   z2^'str' object cannot be interpreted as an integer$)match)r   pytestZraises	TypeErrorbytes)r   ra   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\t|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      s     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
startswithr   Zilocrandint)r   r   tsZts2r   r   r   !test_timeseries_repr_object_dtype   s     
z0TestSeriesRepr.test_timeseries_repr_object_dtypezignore::FutureWarningc              	   C   sP   d}t dddd$ tdddg}|| ks2tW 5 Q R X | d ksLtd S )	Nz\begin{tabular}{ll}
\toprule
{} &         0 \\
\midrule
0 &  $\alpha$ \\
1 &         b \\
2 &         c \\
\bottomrule
\end{tabular}
zdisplay.latex.escapeFzdisplay.latex.reprTz$\alpha$bc)r
   r   Z_repr_latex_r   )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s2td S )Nr   r   r,   z1.0    1
NaN    2
dtype: int64)r   r.   nanr   r   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   rngrr   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s0td S )Nr   r%   rm   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   )r   Zseriesrv   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$td S )Ng      ?z0    1.0
dtype: object)r   r8   r(   r   r   )r   r   r   r   r   r   test_float_repr   s    zTestSeriesRepr.test_float_reprc                 C   s:   t ddddgdd tjtjg}t|}d}||ks6td S )Nr   r   r[      Tz4True    1
None    2
NaN     3
NaT     4
dtype: int64)r   r.   rx   r   r   r   r   )r   r   rv   r   r   r   r   test_different_null_objects  s    z*TestSeriesRepr.test_different_null_objects)#__name__
__module____qualname__r   r$   r&   r)   rh   markZparametrizer2   r5   r<   r>   r@   rF   rG   rL   rO   rQ   rT   rZ   r\   rb   rd   re   rl   rs   filterwarningsrw   rz   r~   r   r   r   r   r   r   r   r      sh   





		

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   r_     s    zJTestCategoricalRepr.test_categorical_repr_unicode.<locals>.County.__repr__N)r   r   r   r   r   r-   r_   r   r   r   r   County  s   r   c                    s   g | ]
}  qS r   r   )rV   _r   r   r   rX     s     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ddddg}d}|| ks(tt tddgd }d	}td
d |t|ks\tW 5 Q R X td}t tddg|dd}d}|| kstd S )Nr   r   r[   r   zO0    1
1    2
2    3
3    4
dtype: category
Categories (4, int64): [1, 2, 3, 4]rS   rt      zf0     a
1     b
     ..
48    a
49    b
Length: 50, dtype: category
Categories (2, object): ['a', 'b']rc   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
   r   list)r   rS   ry   Zlevsr   r   r   test_categorical_repr  s    z)TestCategoricalRepr.test_categorical_reprc                 C   sP   t tdddg}d}t||ks&tt ttd}d}t||ksLtd S )Nr   r   r[   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   r.   r1   r   r#   ry   r   r   r   test_categorical_series_repr:  s    z0TestCategoricalRepr.test_categorical_series_reprc                 C   sX   t tdddgdd}d}t||ks*tt ttddd}d}t||ksTtd S )	Nr   r   r[   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.tt ddddd}tt|}d}t||ks^t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#   ry   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s2tt ddddd	}tt|dd}d
}t||ksft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.tt dddd}tt|}d}t||ks\t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   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s2tt dd	dd}tt|dd}d
}t||ksdt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,tt ddd}tt|}d}t||ksXt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   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s0tt ddd}tt|dd}d	}t||ks`t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   Znumpyr.   rh   Zpandasr   r   r   r   r   r	   r
   r   r   Zpandas._testingZ_testingrn   r   r   r   r   r   r   <module>   s   (
 w