3
Êb_8  ã               @   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mZ d dljZG dd„ dƒZG dd„ dƒZdS )é    )ÚdatetimeÚ	timedeltaN)	ÚCategoricalÚ	DataFrameÚIndexÚ
MultiIndexÚSeriesÚ
date_rangeÚoption_contextÚperiod_rangeÚtimedelta_rangec               @   st   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d„ Zdd„ Zdd„ ZdS )ÚTestSeriesReprc             C   s    t ddddgdddggdddd	d	d
d
dddg
dd	d
dd	d	d
dd	d
g
gddgd�}ttt|ƒƒ|dd�}ddddddddddddg}dj|ƒ}t|ƒ|ksœt‚d S )NÚfooÚbarÚbazZquxZoneZtwoZthreer   é   é   é   ÚfirstÚsecond)ZlevelsÚcodesÚnamesZ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   r   ÚrangeÚlenÚjoinÚreprÚAssertionError)Úselfr   ÚsÚexpected© r#   ú?/tmp/pip-build-jkwsxyiy/pandas/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‚t tdƒƒ}d|_dt|ƒks\t‚d |_dt|ƒksrt‚t tdd	ƒdtd
�}dt|ƒks–t‚d S )Nr   r   r   Útestz
Name: testzName:iè  Z20010101Z20020101)r   r   Údtype)r   r   r   r   r   r	   Úobject)r    r!   r#   r#   r$   Útest_name_printing.   s    z!TestSeriesRepr.test_name_printingc       
      C   sÊ  t |ƒ t |ƒ t |jtƒƒ t |ƒ t ttjdƒtjdƒd�ƒ t ttjdƒtjddd%d�d�ƒ t ttd�ƒ tj	|dd…< t |ƒ |jd	ƒ}d |d d d
…< t
|ƒ xd+D ]}||_t
|ƒ q®W ttjdƒtjdƒd,d�}t
|ƒ ttjjdƒdd�}t
|ƒ}d|k�st‚ttjjdƒdd�}t
|ƒ}d|k�s:t‚tdgddgd�}dt
|ƒk�s^t‚d t
|ƒk�spt‚d!t
|ƒk�s‚t‚tg tjdd"�}	t
|	ƒd#k�s¤t‚tg tjd d"�}	t
|	ƒd$k�sÆt‚d S )-Niè  )r   r   r   )Ústep)r'   é   é   ÚOr   Ú ç333333ó?r   õ   Î±Î²Î³Ú7loooooooooooooooooooooooooooooooooooooooooooooooooooongr   r   çffffff@õ   Î±õ   Î²õ   Î³)r   r   éd   )r   zName: 0ié  za
	bza
	dza
	f)r   r   ú	úza
)r'   r   z#Series([], Name: foo, dtype: int64)zSeries([], dtype: int64)éÿÿÿÿ©r   r   r   ©r   r   ©r   r   r2   ©r3   r4   r5   ©r3   r   )r.   r   r/   r   r0   r1   r:   r;   r<   r=   r>   )r   r   r   )ÚstrZastypeÚintr   ÚtmÚrandnÚnpÚaranger(   ÚNaNr   r   Úrandomr   Úint64)
r    Zdatetime_seriesZstring_seriesZobject_seriesZotsr   ZbiggieÚserZrep_strr!   r#   r#   r$   Ú	test_reprD   sV    "
          zTestSeriesRepr.test_reprc             C   s    t dgd ƒ}d|_t|ƒ d S )Nu   ×�iè  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ƒ }|jdks4t‚d S )Nc             S   s   g | ]}t tjjd d ƒƒ‘qS )r   )r   rC   rF   rB   )Ú.0Úir#   r#   r$   ú
<listcomp>‹   s    z7TestSeriesRepr.test_repr_bool_fails.<locals>.<listcomp>r+   r.   )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jdƒd�}t|ƒ d|_t|ƒ d S )Nr   r   r   )r   õ   ×�)rQ   )rQ   rQ   )r   rC   rG   r   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|jƒ tkƒs8t‚d S )	Né   r+   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 jdd ƒ� tttdƒƒƒ W d Q R X d S )NZmax_rowsié  )Úpdr
   r?   r   r   )r    r#   r#   r$   Útest_repr_max_rows§   s    z!TestSeriesRepr.test_repr_max_rowsc             C   s   t dgdd�}t|ƒ d S )Nu   ×�u   ×‘)r   )r   r?   )r    rW   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 d Q R X d S )NÚabc)r   z2^'str' object cannot be interpreted as an integer$)Úmatch)r   ÚpytestZraisesÚ	TypeErrorÚbytes)r    rW   Ú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jt|ƒƒ|ƒ}t|ƒ t	j
dƒ}t|ƒjƒ d	 jdƒs\t‚|jtjjdt|ƒd dƒ }t|ƒjƒ d
  d S )Nc             S   s    g | ]}t d ddƒt|ƒ ‘qS )iÐ  r   )r   r   )rL   rM   r#   r#   r$   rN   ¹   s    zDTestSeriesRepr.test_timeseries_repr_object_dtype.<locals>.<listcomp>iè  )r'   r   zFreq:r   i�  r9   r9   )r   r   r(   r   rC   rF   rB   r   r   rA   ZmakeTimeSeriesÚ
splitlinesÚ
startswithr   ZilocÚrandint)r    r   ÚtsZts2r#   r#   r$   Ú!test_timeseries_repr_object_dtype·   s    
z0TestSeriesRepr.test_timeseries_repr_object_dtypec             C   sP   d}t ddddƒ�$ tdddgƒ}||jƒ ks2t‚W d Q R X |jƒ 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   rC   Únanr   r   r   )r    rM   r!   Úexpr#   r#   r$   Ú!test_index_repr_in_frame_with_nanÕ   s    z0TestSeriesRepr.test_index_repr_in_frame_with_nanN)Ú__name__Ú
__module__Ú__qualname__r%   r)   rI   rK   rP   rR   rX   rZ   r[   rb   rg   rk   rn   r#   r#   r#   r$   r      s   A		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                sP   G dd„ dƒ‰ t j‡ fdd„tdƒD ƒƒ}t j|ƒ}|jƒ }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   Ústate)r    r#   r#   r$   rU   æ   s    zJTestCategoricalRepr.test_categorical_repr_unicode.<locals>.County.__repr__N)ro   rp   rq   r   rt   r?   rU   r#   r#   r#   r$   ÚCountyâ   s   ru   c                s   g | ]
}ˆ ƒ ‘qS r#   r#   )rL   Ú_)ru   r#   r$   rN   é   s    zETestCategoricalRepr.test_categorical_repr_unicode.<locals>.<listcomp>é=   )rY   r   r   r   Z	to_seriesr   r?   )r    ÚcatÚidxrH   r#   )ru   r$   Útest_categorical_repr_unicodeß   s    
z1TestCategoricalRepr.test_categorical_repr_unicodec             C   sœ   t tddddgƒƒ}d}||jƒ ks(t‚t tddgd	 ƒƒ}d}tddƒ� |t|ƒks\t‚W d Q R X tdƒ}t tddg|dd�ƒ}d}||jƒ ks˜t‚d S )Nr   r   r   é   z0    1
1    2
2    3
3    4
z3dtype: category
Categories (4, int64): [1, 2, 3, 4]rJ   rh   é   z0     a
1     b
z     ..
z48    a
49    b
z:Length: 50, dtype: category
Categories (2, object): [a, b]zdisplay.max_rowsr+   ÚabcdefghijklmnopqrstuvwxyzT)Ú
categoriesÚorderedz0    a
1    b
zJdtype: category
Categories (26, object): [a < b < c < d ... w < x < y < z]zO0    1
1    2
2    3
3    4
dtype: category
Categories (4, int64): [1, 2, 3, 4]z0     a
1     b
     ..
z(0     a
1     b
     ..
48    a
49    b
zb0     a
1     b
     ..
48    a
49    b
Length: 50, dtype: category
Categories (2, object): [a, b]zX0    a
1    b
dtype: category
Categories (26, object): [a < b < c < d ... w < x < y < z])r   r   Ú__str__r   r
   r   Úlist)r    rJ   rm   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jdƒƒƒ}d}t|ƒ|ksLt‚d S )Nr   r   r   zE0    1
1    2
2    3
dtype: category
Categories (3, int64): [1, 2, 3]é
   z‹0    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   rC   rD   )r    r!   rm   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j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ƒ   z�0    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   rC   rD   )r    r!   rm   r#   r#   r$   Ú$test_categorical_series_repr_ordered%  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 )	Nz2011-01-01 09:00ÚHr+   )ÚfreqÚ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]z
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    ry   r!   rm   r#   r#   r$   Ú%test_categorical_series_repr_datetime?  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 )Nz2011-01-01 09:00r†   r+   )r‡   rˆ   T)r   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]z
US/Eastern)r‡   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   )r    ry   r!   rm   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 )	Nz2011-01-01 09:00r†   r+   )r‡   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]z2011-01ÚMz™0    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    ry   r!   rm   r#   r#   r$   Ú#test_categorical_series_repr_periodw  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 )Nz2011-01-01 09:00r†   r+   )r‡   rˆ   T)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]z2011-01rŒ   z�0    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    ry   r!   rm   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 )Nz1 daysr+   )rˆ   z�0   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]z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    ry   r!   rm   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 )
Nz1 daysr+   )rˆ   T)r   z”0   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]z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    ry   r!   rm   r#   r#   r$   Ú.test_categorical_series_repr_timedelta_orderedË  s    zBTestCategoricalRepr.test_categorical_series_repr_timedelta_orderedN)ro   rp   rq   rz   r‚   r„   r…   rŠ   r‹   r�   rŽ   r�   r�   r#   r#   r#   r$   rr   Þ   s    rr   )r   r   ZnumpyrC   r^   ZpandasrY   r   r   r   r   r   r	   r
   r   r   Zpandas._testingZ_testingrA   r   rr   r#   r#   r#   r$   Ú<module>   s   ,
 J