o
    ҷh@?                     @   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                   @   s<  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d:d; Zd<d= Zd>d? Zd@dA ZdBdC Z dDdE Z!d&S )FTestSeriesReprc                 C   s@   |}t tt||dd}g d}d|}t||ksJ d S )N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)self%lexsorted_two_level_string_multiindexr   serexpected r   P/var/www/html/venv/lib/python3.10/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sJ d S )N)r         test
Name: testName:r   r   r   r   sr   r   r   test_small_name_printing,   
   z'TestSeriesRepr.test_small_name_printingc                 C   s<   t td}d|_dt|v sJ d |_dt|vsJ d S )N  r    r!   r"   )r   r   r   r   r$   r   r   r   test_big_name_printing6   r'   z%TestSeriesRepr.test_big_name_printingc                 C   s(   t tdddtd}dt|v sJ d S )N20010101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   s0   t ttjddtjdg|R  d d S )Nr   r(   r   )strr   nprandomdefault_rngstandard_normal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,   )r2   r   r-   r   r   r   r   test_empty_objectM   s   z TestSeriesRepr.test_empty_objectc                 C   s0   t | t |t tj|dd< t | d S )N      )r2   astypeintr3   nan)r   string_seriesr   r   r   test_stringQ   s   zTestSeriesRepr.test_stringc                 C   s   t | d S N)r2   )r   object_seriesr   r   r   test_objectY   s   zTestSeriesRepr.test_objectc                 C   s,   t | |d}d |d d d< t| d S )NOr   )r2   r>   r   )r   datetime_seriesotsr   r   r   test_datetime\   s   
zTestSeriesRepr.test_datetimer   ) r   g333333?foou   αβγ7loooooooooooooooooooooooooooooooooooooooooooooooooooongrK   barbaz)r   r   )rK   r   gffffff@)   αu   βu   γ)rP   rN   c                 C   s   ||_ t| d S rC   )r   r   )r   r   rA   r   r   r   test_various_namesc   s   z!TestSeriesRepr.test_various_namesc                 C   s.   t tjddtddd}t| d S )Nr   r(   rM   r   )r   r3   r4   r5   r6   r7   r   )r   biggier   r   r   test_tuple_namex   s   zTestSeriesRepr.test_tuple_nameargd     c                 C   s2   t tjd|dd}t|}d|v sJ d S )Nr   r   r   zName: 0)r   r3   r4   r5   r6   r   )r   rT   r   rep_strr   r   r   test_tidy_repr_name_0   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sJ dt|vs!J 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, expectedrK   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   r3   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(   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sJ d S )Nc                 S   s"   g | ]}t tjd dqS )r   )r   r   )r   r3   r4   r5   r6   .0ir   r   r   
<listcomp>   s    z7TestSeriesRepr.test_repr_bool_fails.<locals>.<listcomp>r<   rJ   )r   r   r   
readouterrerr)r   capsysr%   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      rm   rW   )r_   r_   )r   r3   r]   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sJ d S )N)   r<   rm   r<   )u   σu   τu   υu   φr1   )r   type__repr__r2   )r   data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    d S 1 sw   Y  d S )Ndisplay.max_rowsrV   )r
   r2   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 )Nr_   u   בrW   )r   r2   )r   rt   r   r   r    test_unicode_string_with_unicode   s   z/TestSeriesRepr.test_unicode_string_with_unicodec                 C   sN   t dgdd}d}tjt|d t| W d    d S 1 s w   Y  d S )NabcrW   z2^'str' object cannot be interpreted as an integer$)match)r   pytestraises	TypeErrorbytes)r   rt   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dt||}t	| t
d}t	| d ds1J |jtjddt|d	 d
 }t	| d  d S )Nc                 S   s    g | ]}t d ddt| qS )  r   r   rc   r   r   r   rf      s     zDTestSeriesRepr.test_timeseries_repr_object_dtype.<locals>.<listcomp>r(   r9   r   r0   zFreq:r   r   i  )r   r   r-   r   r3   r4   r5   r6   r   r   tmmakeTimeSeries
splitlines
startswithilocintegers)r   r   tsts2r   r   r   !test_timeseries_repr_object_dtype   s   
$z0TestSeriesRepr.test_timeseries_repr_object_dtypec                 C   sl   t d d}tdd dd tg d}|| ksJ W d    n1 s'w   Y  | d u s4J d S )Njinja2zj\begin{tabular}{ll}
\toprule
 & 0 \\
\midrule
0 & $\alpha$ \\
1 & b \\
2 & c \\
\bottomrule
\end{tabular}
zstyler.format.escapezstyler.render.reprlatex)z$\alpha$bc)r{   importorskipr
   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sJ d S )Nr   r   r1   z1.0    1
NaN    2
dtype: int64)r   r3   r@   r   r   )r   re   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   r1   )r	   formatr   r   )r   rngr   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sJ d S )Nr   r(   r   zM8[ns]r9   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   seriesr   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   r>   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sJ d S )Nr   r   rm      Tz4True    1
None    2
NaN     3
NaT     4
dtype: int64)r   r3   r@   r   r   r   )r   r   r   r   r   r   r   test_different_null_objects  s   z*TestSeriesRepr.test_different_null_objects)"__name__
__module____qualname__r   r&   r)   r.   r{   markparametrizer8   r;   rB   rE   rI   rQ   rS   rY   r\   r^   rb   rk   rn   ru   rw   rx   r   r   r   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defddZdS )zATestCategoricalRepr.test_categorical_repr_unicode.<locals>.Countyu   San SebastiánPRreturnc                 S   s   | j d | j S )Nz, )r   stater:   r   r   r   rq   #  s   zJTestCategoricalRepr.test_categorical_repr_unicode.<locals>.County.__repr__N)r   r   r   r   r   r2   rq   r   r   r   r   County  s    r   c                    s   g | ]}  qS r   r   )rd   _r   r   r   rf   &  s    zETestCategoricalRepr.test_categorical_repr_unicode.<locals>.<listcomp>=   )r   r   r   	to_seriesr   r2   )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s,J W d    n1 s6w   Y  td	}t tddg|d
d}d}|| ksTJ d S )Nr   zO0    1
1    2
2    3
3    4
dtype: category
Categories (4, int64): [1, 2, 3, 4]ra   r      zf0     a
1     b
     ..
48    a
49    b
Length: 50, dtype: category
Categories (2, object): ['a', 'b']rv   r<   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   ra   r   levsr   r   r   test_categorical_repr-  s   z)TestCategoricalRepr.test_categorical_reprc                 C   s\   t tg d}d}t||ksJ t ttd}dtt d}t||ks,J d S )Nrl   zE0    1
1    2
2    3
dtype: category
Categories (3, int64): [1, 2, 3]
   f0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
dtype: category
Categories (10, z ): [0, 1, 2, 3, ..., 6, 7, 8, 9]r   r   r   r3   r7   r,   r?   r   r%   r   r   r   r   test_categorical_series_reprI  s   z0TestCategoricalRepr.test_categorical_series_reprc                 C   sd   t tg ddd}d}t||ksJ t ttddd}dtt d}t||ks0J d S )Nrl   Tr   zG0    1
1    2
2    3
dtype: category
Categories (3, int64): [1 < 2 < 3]r   r   z$): [0 < 1 < 2 < 3 ... 6 < 7 < 8 < 9]r   r   r   r   r   $test_categorical_series_repr_orderedc  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Hr<   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_datetime}  s   	
z9TestCategoricalRepr.test_categorical_series_repr_datetimec                 C   sj   t dddd}tt|dd}d}t||ksJ t ddddd	}tt|dd}d
}t||ks3J d S )Nr   r   r<   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   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]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sJ t dd	dd}tt|dd}d
}t||ks2J d S )Nr   r   r<   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s,J d S )N1 daysr<   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sJ t ddd}tt|dd}d	}t||ks0J d S )
Nr   r<   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   numpyr3   r{   pandasr   r   r   r   r   r	   r
   r   r   pandas._testing_testingr   r   r   r   r   r   r   <module>   s    (
  