U
    f/e~;                     @   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m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                   @   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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|}t||kstd S )NfoobarbazZquxZoneZtwoZthreer            firstsecond)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&   A/tmp/pip-unpacked-wheel-tiezk1ph/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std S )Nr   r   r   testz
Name: testzName:  Z20010101Z20020101)r   r   dtype)r	   r   r!   r"   r   r
   objectr#   r$   r&   r&   r'   test_name_printing1   s    z!TestSeriesRepr.test_name_printingc           
      C   s  t | t | t |t t | t ttjdtdd t ttjdtjddddd t ttd tj	|dd< t | |d	}d |d d d
< t
| dD ]}||_t
| qttjdtddd}t
| ttjddd}t
|}d|kstttjddd}t
|}d|ks<ttdgddgd}dt
|ks`tdt
|ksrtdt
|ksttg tjdd}	t
|	dksttg tjd d}	t
|	dkstd S )Nr*   r   r   )stepr+         Or   ) r   g333333?r   u   αβγZ7loooooooooooooooooooooooooooooooooooooooooooooooooooongr   r   r   )r   r   )r   r   gffffff@)   αu   βu   γ)r8   r   r7   r   d   r   zName: 0  za
	bza
	dza
	f)r   r   	za
r   )r+   r   z#Series([], Name: foo, dtype: int64)zSeries([], dtype: int64))strastypeintr	   nprandomrandnaranger,   NaNr!   r   r"   int64)
r#   Zdatetime_seriesZstring_seriesZobject_seriesZotsr   ZbiggieserZrep_strr$   r&   r&   r'   	test_reprG   sF    $


  zTestSeriesRepr.test_reprc                 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   rA   rB   rC   .0ir&   r&   r'   
<listcomp>   s     z7TestSeriesRepr.test_repr_bool_fails.<locals>.<listcomp>r3   r6   )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   r   r:   )rI   rI   )r	   rA   rF   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   r3   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 )NZmax_rowsr;   )r   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 )NrI   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 5 Q R X d S )Nabcr:   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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   rL   r&   r&   r'   rO      s     zDTestSeriesRepr.test_timeseries_repr_object_dtype.<locals>.<listcomp>r*   r2   r0   zFreq:r   r   i  )r   r   r,   r	   rA   rB   rC   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_dtypec              	   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   rA   nanr	   r!   r"   )r#   rN   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#   rngrh   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*   rc   zM8[ns]r2   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	   pdZNaTvaluer!   r"   )r#   Zseriesrl   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	   r?   r,   r!   r"   )r#   rG   r%   r&   r&   r'   test_float_repr   s    zTestSeriesRepr.test_float_reprN)__name__
__module____qualname__r(   r.   rH   rK   rQ   rR   rX   rZ   r[   rb   ri   rm   rp   rt   rw   rx   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                    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   staterY   r&   r&   r'   rU     s    zJTestCategoricalRepr.test_categorical_repr_unicode.<locals>.County.__repr__N)ry   rz   r{   r   r~   r>   rU   r&   r&   r&   r'   County   s   r   c                    s   g | ]
}  qS r&   r&   )rM   _r   r&   r'   rO     s     zETestCategoricalRepr.test_categorical_repr_unicode.<locals>.<listcomp>=   )r   r   r   Z	to_seriesr!   r>   )r#   catidxrG   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      zO0    1
1    2
2    3
3    4
dtype: category
Categories (4, int64): [1, 2, 3, 4]rJ   rj      zf0     a
1     b
     ..
48    a
49    b
Length: 50, dtype: category
Categories (2, object): ['a', 'b']zdisplay.max_rowsr3   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#   rJ   ro   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"   rA   rD   r#   r$   ro   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_orderedB  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Hr3   rq   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rq   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$   ro   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 )Nr   r   r3   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_orderedx  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   r3   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   r3   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 daysr3   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   r3   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)ry   rz   r{   r   r   r   r   r   r   r   r   r   r   r&   r&   r&   r'   r|      s    r|   )r   r   ZnumpyrA   r^   Zpandasru   r   r   r   r   r	   r
   r   r   r   Zpandas._testingZ_testingrd   r   r|   r&   r&   r&   r'   <module>   s   , d