U
    *if)                     @   s   d dl m Z mZ d dl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mZ d dlmZ d dlm  m  mZ G dd dZdS )    )datetime	timedelta)StringION)
Categorical	DataFrame
MultiIndexNaTPeriodIndexSeries	Timestamp
date_rangeoption_contextperiod_rangec                   @   s8  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ejjdd Zdd Zdd Zejjdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zejd-d.d/ Zd0d1 Zejd2e j!e j"gejd3e#d4ge$d5ggd6d7 Z%d8d9 Z&d:d; Z'd<d= Z(d>S )?TestDataFrameReprInfoEtcc                    s   t d dd} fddt|D }t|d}|jtk sHtt| t|j	d dd d f  t|j	d dd d f  d S )	NZACDEFGHIJKLMNOP2     c                    s"   g | ]} fd dt D qS )c                    s   g | ]}t j qS  )nprandomchoice).0x)letsr   T/home/mars/bis/venv/lib/python3.8/site-packages/pandas/tests/frame/test_repr_info.py
<listcomp>"   s     zPTestDataFrameReprInfoEtc.test_repr_bytes_61_lines.<locals>.<listcomp>.<listcomp>)range)r   _r   slenr   r   r   "   s     zETestDataFrameReprInfoEtc.test_repr_bytes_61_lines.<locals>.<listcomp>ZU1<   =   )
listr   r   ZastypeZdtypesobjectallAssertionErrorrepriloc)selfZnseqswordsdfr   r   r   test_repr_bytes_61_lines   s    z1TestDataFrameReprInfoEtc.test_repr_bytes_61_linesc                 C   sD   t jddgddgd}ttjdd|d}t||}t| d S )	N)r   r   )   r+   u   Δi1names      index)	r   from_tuplesr   r   r   randntmget_objr%   )r'   Zframe_or_seriesr2   objr   r   r   test_repr_unicode_level_names+   s    z6TestDataFrameReprInfoEtc.test_repr_unicode_level_namesc                 C   sj   t dddgdddgddd	gd
ddg}t|j}d|d< ||_t| ddg|d< ||_t| d S )Nr+   r/      r0               	   )abcr?   r@   )fazboor   rB   rC   )r   	set_indexr!   r2   r%   )r'   r)   r2   r   r   r   test_assign_index_sequences2   s    "
z4TestDataFrameReprInfoEtc.test_assign_index_sequencesc                 C   s@   t dddgittdgddggd}t|}d}||ks<td S )	NXr+   r/   Z20130101r?   r@   r1   z/              X
NaT        a  1
2013-01-01 b  2)r   r   r   r%   r$   )r'   float_string_framer)   resultexpectedr   r   r   test_repr_with_mi_natA   s    $z.TestDataFrameReprInfoEtc.test_repr_with_mi_natc                 C   s8   t ddddgdd tjtg}t|}d}||ks4td S )Nr+   r/   r9   r0   Tz'      0
True  1
None  2
NaN   3
NaT   4)r   r   nanr   r%   r$   )r'   r)   rH   rI   r   r   r   test_repr_with_different_nullsG   s    z7TestDataFrameReprInfoEtc.test_repr_with_different_nullsc              	   C   sL   t jddgd ddgtddgddd	gi}t|d
}t|}d}||ksHtd S )Nr+   r/   r9   r0   r;   r<   Tr=   r>   )datazG   NaN  None  NaT  True
0    1     3    6     8
1    2     4    7     9)r   rK   r   r   r%   r$   )r'   dr)   rH   rI   r   r   r   #test_repr_with_different_nulls_colsR   s
    &
z<TestDataFrameReprInfoEtc.test_repr_with_different_nulls_colsc                 C   sP   t ddidtjidtjidtjiddidtjid}|ddg}t| d S )N)AA0006000ZnuitrQ   rP   )AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCZDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDZEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEZFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFrR   rS   )r   r   rK   rD   r%   )r'   Zdf3Zidfr   r   r   test_multiindex_na_repr\   s    z0TestDataFrameReprInfoEtc.test_multiindex_na_reprc                 C   sP   t jddgdddgd}tddd	gi|d
}t|d}|d dsLtd S )N)r?   r   foo)r@   r+   barr?   r@   rA   r-   valuer   r+   r1   
r/   za 0 foo)r   r3   r   r%   split
startswithr$   )r'   r2   r)   linesr   r   r   test_repr_name_coincidel   s     z0TestDataFrameReprInfoEtc.test_repr_name_coincidec                 C   sj   |}|}t | t | t |j t |j t }|j|d |j|d |jj|d |jj|d d S )Nbuf)r%   Tr   	to_string)r'   Z/multiindex_year_month_day_dataframe_random_dataZ multiindex_dataframe_random_dataZymdframer^   r   r   r   test_repr_to_stringv   s    

z,TestDataFrameReprInfoEtc.test_repr_to_stringc                 C   s&   t t  ttdd}t | d S )Nr   r1   )r%   r   r   arange)r'   ra   r   r   r   test_repr_empty   s    
z(TestDataFrameReprInfoEtc.test_repr_emptyc                 C   s    t  }t| |jd|d d S )NFverboser^   )r   r%   info)r'   rG   r^   r   r   r   test_repr_mixed   s    z(TestDataFrameReprInfoEtc.test_repr_mixedc                 C   sX   t tjdtddtdd}tj|jd ddf< tj|jd ddf< t	| d S )N   )rP   Br1      rP   rj   )
r   r   r   r4   r5   ZmakeStringIndexr   rK   locr%   r'   Zbiggier   r   r   test_repr_mixed_big   s     z,TestDataFrameReprInfoEtc.test_repr_mixed_bigc                 C   s   t  }t| |jd|d |jdgdjd|d |jddgdjd|d tdddgd}t| t j|d	 td
gdgdgd}dt|kstdt|kstdt|kstd S )NFre   rP   columnsrj   r   r+   r9   r]   za
	bza
	dza
	frp   r2   	za
)r   r%   rg   Zreindexr   r$   )r'   float_framer^   no_indexr)   r   r   r   	test_repr   s    z"TestDataFrameReprInfoEtc.test_reprc              	   C   s   t ddgddgg}tdd dt|ks0tW 5 Q R X tdd dt|ksVtW 5 Q R X tdd	 dt|ks|tW 5 Q R X d S )
Nr+   r/   r9   r0   zdisplay.show_dimensionsTz2 rows x 2 columnsFtruncater   r   r%   r$   r'   r)   r   r   r   test_repr_dimensions   s    z-TestDataFrameReprInfoEtc.test_repr_dimensionsc                 C   s(   t tdtdtdd}t| d S )N)ri   r0   r0   ri   rq   )r   r   Zzerosr   r%   rm   r   r   r   test_repr_big   s    z&TestDataFrameReprInfoEtc.test_repr_bigc              
   C   s   t j}t jdtdd tddgd t dgd ddgd t td dgd it	dd}t
| td	d
dd t
| tdddd t
| tdddd t
| t  |t _d S )Nignorez.*format)categorymodulerU   r+   r   rV   r1   zdisplay.precisionr9   zdisplay.column_space
   zdisplay.max_rowsdisplay.max_columnsr/   r   )warningsfiltersfilterwarningsFutureWarningr   r   todayr   r   rc   r%   fmtZ
set_optionr5   Zreset_display_options)r'   rt   Zwarn_filtersZ
unsortabler   r   r   test_repr_unsortable   s.        	z-TestDataFrameReprInfoEtc.test_repr_unsortablec                 C   sp   d}t d||gi}t|}d}|dd  |ks:tt d||gi}t|}|dd  |ksltd S )Nu   σσσσrP   z      ArX   r   )r   r%   rY   rstripr$   )r'   Zuvalr)   rH   Zex_topr   r   r   test_repr_unicode   s    z*TestDataFrameReprInfoEtc.test_repr_unicodec                 C   s   t ddgi}t| d S )NrP      א)r   strry   r   r   r    test_unicode_string_with_unicode   s    z9TestDataFrameReprInfoEtc.test_unicode_string_with_unicodec                 C   s0   t dddgdddgddd	gd
}t|j d S )Nr+   r/   r9   r0   r:   r;   r<   r=   r>   )r   u   בrA   )r   r%   rp   ry   r   r   r   test_repr_unicode_columns   s    "z2TestDataFrameReprInfoEtc.test_repr_unicode_columnsc              	   C   s8   t ddgi}d}tjt|d t| W 5 Q R X d S )NrP   abcz2^'str' object cannot be interpreted as an integer$)match)r   pytestZraises	TypeErrorbytes)r'   r)   msgr   r   r   test_str_to_bytes_raises   s    z1TestDataFrameReprInfoEtc.test_str_to_bytes_raisesc                 C   s*   t tjddtddd}t| d S )Nr   rk   ro   )r   r   r   r4   r5   Zrands_arrayr%   ry   r   r   r   test_very_wide_info_repr  s    z1TestDataFrameReprInfoEtc.test_very_wide_info_reprc              	   C   s:   t dgdd}tdd dt|ks,tW 5 Q R X d S )Nizl u  Is it possible to modify drop plot codeso that the output graph is displayed in iphone simulator, Is it possible to modify drop plot code so that the output graph is â¨displayed in iphone simulator.Now we are adding the CSV file externally. I want to Call the File through the code..)ZId	StringColr   rk   r   rx   ry   r   r   r   ,test_repr_column_name_unicode_truncation_bug  s    zETestDataFrameReprInfoEtc.test_repr_column_name_unicode_truncation_bugzignore::FutureWarningc              	   C   sZ   d}t dddd. tdddgd	d
dgg}|| ks<tW 5 Q R X | d ksVtd S )Nz\begin{tabular}{llll}
\toprule
{} &         0 &  1 &  2 \\
\midrule
0 &  $\alpha$ &  b &  c \\
1 &         1 &  2 &  3 \\
\bottomrule
\end{tabular}
zdisplay.latex.escapeFzdisplay.latex.reprTz$\alpha$r@   rA   r+   r/   r9   )r   r   Z_repr_latex_r$   )r'   rH   r)   r   r   r   test_latex_repr   s
    	z(TestDataFrameReprInfoEtc.test_latex_reprc                 C   sj   t ddddd}tdddd}t||d	}d
}t||ks@ttt|t|d	}t||ksftd S )Nz2011-01-01 09:00Hr:   z
US/Eastern)freqperiodstzz2011-01M)r   r   )dtpz                         dt        p
0 2011-01-01 09:00:00-05:00  2011-01
1 2011-01-01 10:00:00-05:00  2011-02
2 2011-01-01 11:00:00-05:00  2011-03
3 2011-01-01 12:00:00-05:00  2011-04
4 2011-01-01 13:00:00-05:00  2011-05)r   r   r   r%   r$   r   )r'   r   r   r)   expZdf2r   r   r   #test_repr_categorical_dates_periods2  s    z<TestDataFrameReprInfoEtc.test_repr_categorical_dates_periodsargzbox, expectedz0    NaT
dtype: objectz     0
0  NaTc                 C   s&   t ||dgtd}||ks"td S )Nr   )Zdtype)r%   r"   r$   )r'   r   boxrI   rH   r   r   r   test_repr_np_nat_with_objectC  s    z5TestDataFrameReprInfoEtc.test_repr_np_nat_with_objectc                 C   s"   t dtddddi}t| d S )Nyearz1/1/1700r   zA-DEC)r   r   )r   r   r%   ry   r   r   r   "test_frame_datetime64_pre1900_reprM  s    z;TestDataFrameReprInfoEtc.test_frame_datetime64_pre1900_reprc                 C   s4   t dddgdd}ttjdd|d}|  d S )	Nz2011-1z2011-2z2011-3r   )r   r9   r0   r1   )r	   r   r   r   r4   r`   )r'   r2   ra   r   r   r   %test_frame_to_string_with_periodindexR  s    z>TestDataFrameReprInfoEtc.test_frame_to_string_with_periodindexc                 C   sL   t dtddddi}t|}|jd d d df }t|}||ksHtd S )Nr   Z2019r   UTC)r   r   r:   )r   r   r%   r&   r$   )r'   r)   rI   rH   r   r   r   $test_datetime64tz_slice_non_truncateY  s
    z=TestDataFrameReprInfoEtc.test_datetime64tz_slice_non_truncateN))__name__
__module____qualname__r*   r8   rE   rJ   rL   rO   rT   r\   rb   rd   rh   r   markZslowrn   rv   rz   r{   r   r   r   r   r   r   r   r   r   r   Zparametrizer   Z
datetime64Ztimedelta64r
   r   r   r   r   r   r   r   r   r   r      sH   






r   )r   r   ior   r   numpyr   r   Zpandasr   r   r   r   r	   r
   r   r   r   r   Zpandas._testingZ_testingr5   Zpandas.io.formats.formatformatsformatr   r   r   r   r   r   <module>   s   0