a
    Pf	                     @   s   d dl Z d dlmZ d dlZd dlZd dlZd dlm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Z d dlmZ G dd dZdS )    N)StringIO)ParserError)
	DataFrameIndex
MultiIndexNaTSeries	Timestamp
date_rangeperiod_rangeread_csvto_datetime)
get_handlec                   @   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	e
jddddggdd Ze
jjdd ZdddZe
jje
jdg ddd Ze
jje
jdg de
jdg de
jd g d!e
jd"d#d$ Ze
jje
jdg d%e
jd g d!d&d' Ze
jje
jdg d(d)d* Ze
jjd+d, Ze
jjd-d. Ze
jje
jdg de
jd g d/e
jd0d1d2id3d2igd4d2id5d2igd2d2d6d2d2d7ggd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE ZdFdG ZdHdI Z dJdK Z!dLdM Z"dNdO Z#dPdQ Z$e
jdRg dSdTdU Z%e
jjdVdW Z&dXdY Z'dZd[ Z(d\d] Z)d^d_ Z*d`da Z+dbdc Z,ddde Z-e
jdfddggdhdi Z.djdk Z/dldm Z0dndo Z1dpdq Z2e
jdre3g dsg dtgdudvgg dwdxdfe3g dygg dwdzd{fe3d|g d}g g dwdzd~fe3d|g dg g dwdzdfgdd Z4dd Z5e
jde67de67dgdd Z8dd Z9dd Z:dd Z;dd Z<dd Z=dd Z>dd Z?dd Z@dd ZAdd ZBdS )TestDataFrameToCSVc                 K   s(   ddi}|j f i | t|fi |S )N	index_colr   )updater   )selfpathkwargsparams r   _/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/frame/methods/test_to_csv.pyr      s    zTestDataFrameToCSV.read_csvc              	   C   s~  t d\}tj|jd d|jdf< || |j|ddgd |j|dd |j|dd |j	d |_|| | j
|d	d
}t || |j|dd | j
|d d	d}t|jt|jd ksJ |j|dd | j
|d d	d}t |j|j tttdtjdtjddttdtjdtjddd}|| | 
|}t || W d    n1 sp0    Y  d S )NZ__tmp_to_csv_from_csv1__   ABcolumnsFheaderindexT)parse_datesr    Zindex_labelr   r!         dtype   )s1s2)tmensure_cleannpnanilocr   Zget_locto_csvr    
_with_freqr   assert_frame_equallenassert_almost_equalvaluesr   r   rangearangeint64)r   float_framedatetime_framer   reconsdmr   r   r   test_to_csv_from_csv1$   s0    



z(TestDataFrameToCSV.test_to_csv_from_csv1c           
   	   C   sV  t d4}ttjddg dg dd}|| | |}t 	|| t
g d}ttjdd|g dd}|| | j|g dd	d
}t j	||d	d tg d}|j||d | |}| }||_t 	|| d}	tjt|	d" |j|ddgd W d    n1 s(0    Y  W d    n1 sH0    Y  d S )NZ__tmp_to_csv_from_csv2__r(   r%   r%   ar@   b)xyzr    r   )r   r$   r(   rF   )r   r$   r(   r   r$   r(   Fr#   Zcheck_names)AAXYZr   z Writing 4 cols but got 2 aliasesmatchrI   rJ   )r+   r,   r   r-   randomdefault_rngstandard_normalr0   r   r2   r   from_tuplesr   copyr   pytestraises
ValueError)
r   r9   r   dfresultZmidxZcol_aliasesrsxpmsgr   r   r   test_to_csv_from_csv2J   s6    



z(TestDataFrameToCSV.test_to_csv_from_csv2c                 C   s   t d}ttjdd}ttjdd}|| |j|ddd t	||g}t
|dd}d	d
 |jD |_dd
 |jD |_t || W d    n1 s0    Y  d S )NZ__tmp_to_csv_from_csv3__r(   )r%   r$   r@   F)moder   r   r   c                 S   s   g | ]}t |qS r   int.0labelr   r   r   
<listcomp>w       z<TestDataFrameToCSV.test_to_csv_from_csv3.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   r_   ra   r   r   r   rd   x   re   )r+   r,   r   r-   rO   rP   rQ   r0   pdconcatr   r   r2   )r   r   Zdf1df2rZ   rY   r   r   r   test_to_csv_from_csv3n   s    
z(TestDataFrameToCSV.test_to_csv_from_csv3c                    s   t d}tjdd td fddtdD it fddtdD d	d
d}|| t|d	d}t	|j
|_
t	|d |d< t j||dd W d    n1 s0    Y  d S )NZ__tmp_to_csv_from_csv4__r$   )secondsZdt_datac                    s   g | ]}|  qS r   r   rb   idtr   r   rd      re   z<TestDataFrameToCSV.test_to_csv_from_csv4.<locals>.<listcomp>r%   c                    s   g | ]}|  qS r   r   rk   rm   r   r   rd      re   dt_indexnamer   r^   T)Zcheck_index_type)r+   r,   rf   	Timedeltar   r6   r   r0   r   Zto_timedeltar    r2   r   r   rW   rX   r   rm   r   test_to_csv_from_csv4{   s    
z(TestDataFrameToCSV.test_to_csv_from_csv4c                    sz   t d\}| t|ddgd  fdd}|d d< |d d< t   W d    n1 sl0    Y  d S )	NZ__tmp_to_csv_from_csv5__r   r   r#   c                    s$   t  |  jdj|  jjS )NUTC)r   rn   
tz_converttz)crX   timezone_framer   r   <lambda>   s   
z:TestDataFrameToCSV.test_to_csv_from_csv5.<locals>.<lambda>r   C)r+   r,   r0   r   r2   )r   rz   r   	converterr   ry   r   test_to_csv_from_csv5   s    
z(TestDataFrameToCSV.test_to_csv_from_csv5c                 C   s   d}t |d }tt|dftdd t|D ddtdd tdD ddd	}|j}|d
 |d g}t ,}|j	|||d t
|dd}W d    n1 s0    Y  tj|| |dd d S )Nr         @r%   c                 S   s   g | ]}d | qS zi-r   rk   r   r   r   rd      re   zBTestDataFrameToCSV.test_to_csv_cols_reordering.<locals>.<listcomp>r@   rp   c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd      re   rE   r(   r   r   	chunksizer^   FrH   )r`   r   r-   onesr   r6   r   r+   r,   r0   r   r2   )r   r   NrW   cscolsr   rs_cr   r   r   test_to_csv_cols_reordering   s    
*z.TestDataFrameToCSV.test_to_csv_cols_reorderingr   NrA   r@   c                 C   s  d}t |d }tt|dftdd t|D ddg dd	}t }|j|||d
 t	|dd}|d ur|j
jr||_
n|j
|\}}|j
||_
|D ]<}	||	 }
||	 }t|
trt|
| qtj|
|dd qn|j
|_
tj||dd W d    n1 s0    Y  d S )Nr   r   r%   c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd      re   z@TestDataFrameToCSV.test_to_csv_new_dupe_cols.<locals>.<listcomp>r@   rp   r?   rE   r   r   r^   FrH   )r`   r   r-   r   r   r6   r+   r,   r0   r   r   Z	is_uniqueZget_indexer_non_uniqueZtake
isinstancer   Zassert_series_equalr2   )r   r   r   r   rW   r   r   Zindexermissingrx   Zobj_dfZobj_rsr   r   r   test_to_csv_new_dupe_cols   s.    

z,TestDataFrameToCSV.test_to_csv_new_dupe_colsc                 C   s   ddd}d}||d }||d d}t dL}t||d}|j||d | |t}t j||d	d
 W d    n1 s0    Y  d S )Nc                 S   sz   |d u rt | d }ttdd| d}|rvtjddt||D ]}t||< qDtjdd}t|| < t||< |S )Ng?2000Z5min)freqperiodsr(   r   d   )	r`   listr
   r-   rO   rP   integersr3   r   )nZnnatsrl   r   r   r   make_dtnat_arr   s    

z<TestDataFrameToCSV.test_to_csv_dtnat.<locals>.make_dtnat_arr  r   r   z1.csvr@   rA   r   FrH   )N)r+   r,   r   r0   r   applyr   r2   )r   r   r   r)   r*   pthrW   r;   r   r   r   test_to_csv_dtnat   s    
z$TestDataFrameToCSV.test_to_csv_dtnatFc                    s  ddi}|r|d ur$t t||d< t t||d< td2}	|j|	d|d | j|	fi |W d    q1 sv0    Y  nTd|d< td2}	|j|	d|d | j|	fi |W d    n1 s0    Y  d	d
  |r|j_|rF|sFfddt|d D }
tt j	g|
 }|_	j
d d |d d f ddddddd}|rx|dkrd}tj fddj	D |d_	tj fdd|j	D |d|_	n|dkrd}tjdd j	D |d_	tjdd |j	D |d|_	n|dkrJd}tj	}tjdd |D |d_	tjt tt|j	 |d|_	n.||}tjj	|d_	tj|j	|d|_	|r|dkrd}tj fddjD |d_tj fdd|jD |d|_n|dkrd}tjdd jD |d_tjdd |jD |d|_n|dkrnd}tj}tjdd |D |d_|j }tjd d |D |d|_n.||}tjj|d_tj|j|d|_|fS )!Nr!   Fr   r   Z__tmp_to_csv_moar__utf8)encodingr   r   c                 S   s   t | ts| dS | S )Nr   )r   strdecoderB   r   r   r   _to_uni  s    

z;TestDataFrameToCSV._return_result_expected.<locals>._to_unic                    s    g | ]} j d d |f jqS )N)r/   r5   rk   )r;   r   r   rd     re   z>TestDataFrameToCSV._return_result_expected.<locals>.<listcomp>r$   rl   fO)rl   r   r   urn   pr   c                    s   g | ]} |qS r   r   ra   r   r   r   rd     re   r&   c                    s   g | ]} |qS r   r   ra   r   r   r   rd     re   rn   c                 S   s   g | ]}t |qS r   r	   ra   r   r   r   rd   "  re   c                 S   s   g | ]}t |qS r   r   ra   r   r   r   rd   %  re   r   c                 S   s   g | ]}t |qS r   r   ra   r   r   r   rd   +  re   c                    s   g | ]} |qS r   r   ra   r   r   r   rd   8  re   c                    s   g | ]} |qS r   r   ra   r   r   r   rd   ;  re   c                 S   s   g | ]}t |qS r   r   ra   r   r   r   rd   @  re   c                 S   s   g | ]}t |qS r   r   ra   r   r   r   rd   C  re   c                 S   s   g | ]}t |qS r   r   ra   r   r   r   rd   I  re   c                 S   s   g | ]}t |qS r   r   ra   r   r   r   rd   M  re   )r   r6   r+   r,   r0   r   r   r   from_arraysr    r/   r-   arrayr   mapr	   Zto_timestampget)r   rW   r   Zr_dtypeZc_dtypernlvlcnlvldupe_colr   r   Z	delta_lvlixZtype_mapZidx_listZcol_listr   )r   r;   r   _return_result_expected   s    
20
















z*TestDataFrameToCSV._return_result_expectednrows)r(   
   c   r   e   f                           c                 C   sT   t t|dftd|dttdtdd}| |ddd	\}}tj	||d
d d S )N   
2020-01-01r   abcdr&   rE   r   rn   r   FrH   )
r   r-   r   r
   r   r   objectr   r+   r2   )r   r   rW   rX   expectedr   r   r   test_to_csv_nrowsU  s    
z$TestDataFrameToCSV.test_to_csv_nrowszr_idx_type, c_idx_type))rl   rl   )r   r   )r   rn   )r   r   ncolsr$   r(   r%   r   z3ignore:PeriodDtype\[B\] is deprecated:FutureWarningc           	      C   sn   dd dd dd dd d}t t||f|| ||| |d}| |d||\}}tj||d	d
 d S )Nc                 S   s   t t| tjdS )Nr&   )r   r-   r7   r8   r   r   r   r   r{   m  re   z:TestDataFrameToCSV.test_to_csv_idx_types.<locals>.<lambda>c                 S   s   t dd tdd|  D S )Nc                 S   s   g | ]}| d t | qS )_)chrrk   r   r   r   rd   n  re   zNTestDataFrameToCSV.test_to_csv_idx_types.<locals>.<lambda>.<locals>.<listcomp>a   )r   r6   r   r   r   r   r{   n  re   c                 S   s   t d| dS )Nr   r   )r
   r   r   r   r   r{   o  re   c                 S   s   t d| ddS )Nr   D)r   r   )r   r   r   r   r   r{   p  re   )rl   r   rn   r   rE   r   FrH   )r   r-   r   r   r+   r2   )	r   r   Z
r_idx_typeZ
c_idx_typer   ZaxesrW   rX   r   r   r   r   test_to_csv_idx_typesb  s"    

z(TestDataFrameToCSV.test_to_csv_idx_types)r   b   r   r   r   r   r   r   r   r   r   r   r   r   c                 C   sh   t t||ftdd t|D ddtdd t|D ddd}| |d\}}tj||dd	 d S )
Nc                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd     re   z<TestDataFrameToCSV.test_to_csv_idx_ncols.<locals>.<listcomp>r@   rp   c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd     re   rE   r   FrH   )r   r-   r   r   r6   r   r+   r2   )r   r   r   rW   rX   r   r   r   r   test_to_csv_idx_ncols  s    z(TestDataFrameToCSV.test_to_csv_idx_ncols)r   r   r   r   r   r   c                 C   s   t t|dftdd t|D ddtdd tdD ddd}t|j}ddg|d d	< ddg|d
d < t|j}ddg|d d	< ddg|d
d < ||_||_| j|ddd\}}t	j
||dd d S )Nr%   c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd     re   z;TestDataFrameToCSV.test_to_csv_dup_cols.<locals>.<listcomp>r@   rp   c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd     re   rE   Zduper(   Zrduper   T)r   FrH   )r   r-   r   r   r6   r   r   r    r   r+   r2   )r   r   rW   r   r   rX   r   r   r   r   test_to_csv_dup_cols  s    

z'TestDataFrameToCSV.test_to_csv_dup_colsc                 C   s:   t tjdtjdd}| |d\}}tj||dd d S )Nr   r&   r   r   F)Zcheck_column_type)r   r-   r7   r8   r   r+   r2   )r   rW   rX   r   r   r   r   test_to_csv_empty  s    z$TestDataFrameToCSV.test_to_csv_emptyc                    st   d}|d d  t t dfttdtdt fddtdD d}| j	||dd	\}}t
j||d
d d S )Nr   r(   r$   abr&   c                    s   g | ]}t  qS r   r6   rb   r   rowsr   r   rd     re   z<TestDataFrameToCSV.test_to_csv_chunksize.<locals>.<listcomp>r   r    )r   FrH   )r   r-   r   r   r   r   r   r   r6   r   r+   r2   )r   r   rW   rX   r   r   r   r   test_to_csv_chunksize  s    z(TestDataFrameToCSV.test_to_csv_chunksize)r(   r%   r   zdf_params, func_paramsr_idx_nlevelsr(   r   c_idx_nlevelsr   )r   r   )r   r   c           
         s   | dr,tfddt|d D }nd }| dr\t fddt|d D }ntdd t D td}tt f||d	}| j	|d
fi |\}}	t
j||	dd d S )Nr   c                 3   s    | ]}d d t  D V  qdS )c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd     re   CTestDataFrameToCSV.test_to_csv_params.<locals>.<genexpr>.<listcomp>Nr   r   )r   r   r   	<genexpr>  s   z8TestDataFrameToCSV.test_to_csv_params.<locals>.<genexpr>r   c                 3   s    | ]}d d t  D V  qdS )c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd     re   r   Nr   r   )r   r   r   r     s   c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd     re   z9TestDataFrameToCSV.test_to_csv_params.<locals>.<listcomp>r&   rE   r   FrH   )r   r   r   r6   r   r   r   r-   r   r   r+   r2   )
r   r   Z	df_paramsZfunc_paramsr   r    r   rW   rX   r   r   )r   r   r   test_to_csv_params  s    





z%TestDataFrameToCSV.test_to_csv_paramsc                 C   s   t j|d< dd }|j||d< t H}|| | |}t|| tt 	|t 	| W d    n1 sx0    Y  d S )NGc                 S   s    t jt jgt jd dk  S )Nr(         ?)r-   infr.   rO   rP   r   r   r   r   r{     re   zETestDataFrameToCSV.test_to_csv_from_csv_w_some_infs.<locals>.<lambda>h)
r-   r.   r    r   r+   r,   r0   r   r2   isinf)r   r9   r   r   r;   r   r   r    test_to_csv_from_csv_w_some_infs  s    



z3TestDataFrameToCSV.test_to_csv_from_csv_w_some_infsc                 C   sz   t j|d< t j |d< t H}|| | |}t|| tt |t | W d    n1 sl0    Y  d S )NEF)r-   r   r+   r,   r0   r   r2   r   )r   r9   r   r;   r   r   r   test_to_csv_from_csv_w_all_infs  s    



z2TestDataFrameToCSV.test_to_csv_from_csv_w_all_infsc                 C   s   t d~}tg dg dd}|j|dd t|}t || tg ddd	|d
< |j|dd t|}t || W d    n1 s0    Y  d S )NZ__tmp_to_csv_no_index__r$   r(   r%   r   r      )c1c2Fr   )      	   r8   r&   c3)r+   r,   r   r0   r   r2   r   rs   r   r   r   test_to_csv_no_index  s    z'TestDataFrameToCSV.test_to_csv_no_indexc                 C   s>   t g dg dd}d|d< | |jg ddks:J d S )Nr@   rA   rx   )aaZbbcc)r   r$   txttest)r   r$   r   r   )r   r0   )r   rW   r   r   r   test_to_csv_with_mix_columns  s    z/TestDataFrameToCSV.test_to_csv_with_mix_columnsc                 C   s   t ddgddggddgd}t ddgddggdd	gd}td
z}|j|dd	gd | |}t|| |j|ddd	gd | |}|jdd}|d u sJ t|| W d    n1 s0    Y  d S )Nr$   r(   r%   r   r   r   r   rJ   rK   Z__tmp_to_csv_headers__r   F)r    r   T)Zinplace)r   r+   r,   r0   r   r2   Zreset_index)r   Zfrom_dfZto_dfr   r;   Zreturn_valuer   r   r   test_to_csv_headers  s    

z&TestDataFrameToCSV.test_to_csv_headersc              
   C   sl  |}|j }tjt|d tjddd}tj|ddgd}||_ t	dt}|j
|dd	 |j
|d
dgd |
| | j|ddgdd}tj||dd |j j|j jksJ ||_ |}	|	j }|tjt|tjdg}t||	_ |	j
|ddgd tjtdd$ | j|ddgdd}
W d    n1 s20    Y  tj|	|
dd |	
| | j|d d}
t|
jt|	jd ksJ |	j
|dd | j|d d}
t|
j|j ||_ W d    n1 s0    Y  t	d}d0dd}ttdtjdd tdD tddtjd d tdD td!dd"}|
| t|g d#ddgd$}t|| ttdtjd%d tdD tddd}|
| t|g d#dd$}t|| ttdtjd&d tdD tddtjd'd td(D td)dd"}|
| t|g d#g d*d$}t|| | }|j
|dd t|ddgd	}t|| |d}|j
|dd t|ddgd	}tj|jj sJ |jj|j_t|| | }|
| t|ddgdgd$}t|| |d}|
| t|ddgdgd$}t|| |d}|
| d+D ]X}d,| d-}tjt|d& t|tt|dd$ W d    n1 sx0    Y  q,d.}tjt|d" |j
|dd/gd W d    n1 s0    Y  W d    n1 s0    Y  t	d`}|	d d 
| | |}
|	d d }g |_ t|
j|j t|
dksHJ W d    n1 s^0    Y  d S )1Nr(   r&   firstsecondnamesZ__tmp_to_csv_multiindex__Fr   r   r   r   r   r$   r#   rH   timefoor"   zCould not infer formatrM   Tr^   r   c                 S   s@   | du rddg} t tjdjddddtjg d	| d
ddS )NTr   r   r(   r   r   r>   )size))bahr   )r   bar)Zbanbazr   r8   r   r'   )r   r-   rO   rP   r   r   rR   r   r   r   r   _make_frameI  s    z>TestDataFrameToCSV.test_to_csv_multiindex.<locals>._make_framer   r%   c                 S   s   g | ]}d d t dD qS )c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd   X  re   HTestDataFrameToCSV.test_to_csv_multiindex.<locals>.<listcomp>.<listcomp>r%   r   r   r   r   r   rd   X  re   z=TestDataFrameToCSV.test_to_csv_multiindex.<locals>.<listcomp>r   r   c                 S   s   g | ]}d d t dD qS )c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd   [  re   r  r   r   r   r   r   r   rd   [  re   r   r   )r   r$   r(   r%   )r   r   c                 S   s   g | ]}d d t dD qS )c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd   f  re   r  r%   r   r   r   r   r   rd   f  re   c                 S   s   g | ]}d d t dD qS )c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd   q  re   r  r%   r   r   r   r   r   rd   q  re   c                 S   s   g | ]}d d t dD qS )c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd   t  re   r  r   r   r   r   r   r   rd   t  re   r%   abcrG   )r   r   zlen of z, but only 5 lines in filez%cannot specify cols with a MultiIndexr   )N)r    r-   r7   r3   r8   Zreshaper   r   r+   r,   r0   r   r2   r   Zassert_produces_warningUserWarningr   r4   r5   r   r   r6   r   comZall_nonerT   rU   r   	TypeErrorZassert_index_equal)r   r9   r:   frameZ	old_indexZarraysZ	new_indexr   rW   Ztsframer;   r  rX   rl   r[   expr   r   r   test_to_csv_multiindex  s     
4
&
	

	



:R
z)TestDataFrameToCSV.test_to_csv_multiindexc                 C   s   t tdtddtddd}td^}|| | j|dd}|	 }|rb|j
d|_
n|j
t|_
t|| W d    n1 s0    Y  d S )	Nr  r%   r   r   r   r   z!__tmp_to_csv_interval_index__.csvr^   zstring[pyarrow_numpy])r   r   r6   rf   Zinterval_ranger+   r,   r0   r   rS   r    astyper   r2   )r   Zusing_infer_stringrW   r   rX   r   r   r   r   test_to_csv_interval_index  s    "
z-TestDataFrameToCSV.test_to_csv_interval_indexc              	   C   s   t tjddtj}tj|d< t	dl}|j
|dd t|dd2}| }|d d	d d
ksrJ W d    n1 s0    Y  W d    n1 s0    Y  d S )Nr(   )r$   r   r$   z!__tmp_to_csv_float32_nanrep__.csvi  )na_reputf-8r   ,Z999)r   r-   rO   rP   rQ   r  Zfloat32r.   r+   r,   r0   open	readlinessplit)r   rW   r   r   linesr   r   r   test_to_csv_float32_nanrep  s    
z-TestDataFrameToCSV.test_to_csv_float32_nanrepc                 C   sd   t g dg dd}td0}|| | |}t|| W d    n1 sV0    Y  d S )Nr   )z5,6z7,8z9,0r  z__tmp_to_csv_withcommas__.csvr   r+   r,   r0   r   r2   r   rW   r   rh   r   r   r   test_to_csv_withcommas  s
    

z)TestDataFrameToCSV.test_to_csv_withcommasc                 C   s~  dd }t tjddd|dd}t tjdddd|d	d}t d
|j|dd}t d|j|dd}t tdd|j|dd}tj	|j
ddddf< tj	|j
ddddf< tj|||||gdd}i }dtjfd	tjfdtjfdtffD ]"\}	}
||	D ]}|
||< qqt :}|| t|d||dd}t|| W d    n1 sp0    Y  d S )Nc                    s    fddt dD S )Nc                    s   g | ]}  |d qS )Z03dr   rk   rp   r   r   rd     re   zMTestDataFrameToCSV.test_to_csv_mixed.<locals>.create_cols.<locals>.<listcomp>r   r   rp   r   rp   r   create_cols  s    z9TestDataFrameToCSV.test_to_csv_mixed.<locals>.create_colsr(   )r   r   float64float)r'   r   r8   r`   TboolrE   r   r   20010101nsdate   2   r$   r%   )axisr   )r   r'   r!   )r   r-   rO   rP   rQ   r  r    r	   as_unitr.   r/   rf   rg   r  r8   Zbool_r   r+   r,   r0   r   r2   )r   r  df_floatdf_intdf_bool	df_objectdf_dtrW   Zdtypesr   r'   rx   filenamerY   r   r   r   test_to_csv_mixed  sJ    

z$TestDataFrameToCSV.test_to_csv_mixedc           
      C   s  t tjddttdttd dd}t :}|	| t
|dd}|j|_t|| W d    n1 sx0    Y  t tjdddd	}t tjddd
}t d|jtdd}t d|jtdd}t tdd|jtdd}tj|||||gddd}g dd |_t V}|	| t
|dd}dD ]}	t||	 ||	< qJ|j|_t|| W d    n1 s0    Y  d S )Nr(   )r   r#     r  r  r   r^   )r   r%   r&   r8   Tr%   rE   r   r   r!  r$   )r%  Zignore_indexrG   r   )z0.4z1.4z2.4)r   r-   rO   rP   rQ   r   r6   r+   r,   r0   r   r   r2   r  r    r	   r&  rf   rg   r   )
r   rW   r,  rX   r'  r(  r)  r*  r+  rl   r   r   r   test_to_csv_dups_cols  s@    

*

z(TestDataFrameToCSV.test_to_csv_dups_colsc                 C   s   t tdtdd tdD ddtg dtdd	}t B}|| t	|d
d}|j
ddid}t|| W d    n1 s0    Y  d S )Nr  c                 S   s   g | ]}d | qS r   r   rk   r   r   r   rd   1  re   z=TestDataFrameToCSV.test_to_csv_dups_cols2.<locals>.<listcomp>r   r   rp   r?   r&   rE   r   r^   za.1r@   r   )r   r-   r   r   r6   r   r+   r,   r0   r   renamer2   )r   rW   r,  rX   r   r   r   test_to_csv_dups_cols2-  s    

z)TestDataFrameToCSV.test_to_csv_dups_cols2r   )i'  iP  順 c                 C   s   t dtdi}|jd |d< |jd |d< |jd |d< t 6}|j||d	 t|d
d}t|| W d    n1 s~0    Y  d S )Nr   r2        ?r   g       @r|   g      @r   r   r   r^   )r   r6   r   r+   r,   r0   r   r2   )r   r   r   r,  rY   r   r   r   test_to_csv_chunking=  s    
z'TestDataFrameToCSV.test_to_csv_chunkingc              	   C   s   d}t tjdd|d fd d d}t `}| ,}|d| |j	|ddd W d    n1 sl0    Y  t
|d d	}W d    n1 s0    Y  t|| d S )
Nr   r(   r$   r   r   z/pandas.io.formats.csvs._DEFAULT_CHUNKSIZE_CELLSF)r   r    r   )r   r-   rO   rP   rQ   r+   r,   contextsetattrr0   r   r2   )r   Zmonkeypatchr   rW   r,  mrY   r   r   r   !test_to_csv_wide_frame_formattingI  s    

.*z4TestDataFrameToCSV.test_to_csv_wide_frame_formattingc                 C   s~   t d}| j|d d}td||jd  i}t 6}|| t|dd}tj||dd W d    n1 sp0    Y  d S )Nza,1.0
b,2.0r   tr   r^   FrH   )r   r   r   r   r+   r,   r0   r2   )r   f1rW   Znewdfr   r;   r   r   r   test_to_csv_bugY  s    

z"TestDataFrameToCSV.test_to_csv_bugc                 C   s   t dg di}t b}|j|dd t|ddd}t|| |j|ddd t|d dd}t|| W d    n1 s0    Y  d S )	Nu   c/σr   UTF-8r  r   r   r   Fr   r    r  r  r   r   r   test_to_csv_unicodee  s    
z&TestDataFrameToCSV.test_to_csv_unicodec                 C   s`   t d}tg dg dgg dddgd}|j|dd	 |d
 t|d
dd}t|| d S )N )   אZd2Zd3Zd4)Za1Za2a3Za4)rA     בu   גu   דrA  rC  r   r<  r  r   r=  )r   r   r0   seekr   r+   r2   )r   bufrW   rh   r   r   r   test_to_csv_unicode_index_colp  s    
z0TestDataFrameToCSV.test_to_csv_unicode_index_colc                 C   s6   t  }|| |d t|dd}t|| d S )Nr   r^   )r   r0   rD  r   r+   r2   )r   r9   rE  r;   r   r   r   test_to_csv_stringio~  s
    

z'TestDataFrameToCSV.test_to_csv_stringioc                 C   s   t g dg dgddgg dd}t X}|j|dd t|d	d
}t g dg dgddgg dd}t|| W d    n1 s0    Y  d S )Ng~Ϛ?g9DܜJ?g>D)?g.4i(@33333@̤Ar   r   rJ   rK   rL   rE   z%.2f)float_formatr   r^   )gQ?gq=
ףp?g=
ףp=?)gp=
ף(@rJ  rK  r  )r   rW   r,  rY   rZ   r   r   r   test_to_csv_float_format  s    
z+TestDataFrameToCSV.test_to_csv_float_formatc                 C   sF   t dddgi}|jddd dd}g d	}t|}||ksBJ d S )
Nr@   r   r3  r  c                 S   s   t j| ddS )N-)Ztrim)r-   Zformat_float_positionalr   r   r   r   r{     re   zJTestDataFrameToCSV.test_to_csv_float_format_over_decimal.<locals>.<lambda>F)decimalrM  r    )r@   z0.51)r   r0   r+   convert_rows_list_to_csv_strr   rW   rX   expected_rowsr   r   r   r   %test_to_csv_float_format_over_decimal  s    
z8TestDataFrameToCSV.test_to_csv_float_format_over_decimalc                 C   sZ   t g dg dd}t }|j|dtjdd | }g d}t|}||ksVJ d S )Nr   )r   r   r  r  Fr  )r    quotingr   )z"A","B"z1,"foo"z2,"bar"z3,"baz")r   r   r0   csvQUOTE_NONNUMERICgetvaluer+   rR  )r   rW   rE  rX   rT  r   r   r   r   !test_to_csv_unicodewriter_quoting  s    
z4TestDataFrameToCSV.test_to_csv_unicodewriter_quotingr   r  c                 C   sT   t dddgi}t }|j|tj|dd | }g d}t|}||ksPJ d S )Nr   hello	{"hello"}F)rV  r   r    )r   r[  r\  )r   r   r0   rW  
QUOTE_NONErY  r+   rR  )r   r   rW   rE  rX   rT  r   r   r   r   test_to_csv_quote_none  s    
z)TestDataFrameToCSV.test_to_csv_quote_nonec                 C   sX   t g dg ddg dd}t }|j|dd g d}t|}| |ksTJ d S )	Nr   r   r  onetwothreer   Fr"   )zA,Bzone,1,4ztwo,2,5z	three,3,6)r   r   r0   r+   rR  rY  )r   rW   rE  rT  r   r   r   r   "test_to_csv_index_no_leading_comma  s    
z5TestDataFrameToCSV.test_to_csv_index_no_leading_commac              	   C   s  t g dg ddg dd}t ^}|j|dd d}t|d	d
 }| |ksXJ W d    n1 sl0    Y  W d    n1 s0    Y  t ^}|j|dd d}t|d	d
 }| |ksJ W d    n1 s0    Y  W d    n1 s0    Y  t }|| tjd}d| d | d | d | }t|d	d
"}| |kslJ W d    n1 s0    Y  W d    n1 s0    Y  d S )Nr   r   r  r_  r   
lineterminators#   ,A,B
one,1,4
two,2,5
three,3,6
rb)r]   
s   ,A,B
one,1,4
two,2,5
three,3,6
r  s   ,A,Bs   one,1,4s   two,2,5s	   three,3,6)	r   r+   r,   r0   r  readoslinesepencode)r   rW   r   r   r   Z
os_linesepr   r   r   test_to_csv_lineterminators  s@    
L
N

z.TestDataFrameToCSV.test_to_csv_lineterminatorsc                 C   s   t tg d}t g d}t }|j|dd t }|j|dd | | ksZJ td|i}td|i}t }|| t }|| | | ksJ d S )N)r@   rA   rA   r@   r@   rx   rx   rx   Fr   r   )r   rf   ZCategoricalr   r0   rY  r   )r   r   r*   resr  rW   rh   r   r   r    test_to_csv_from_csv_categorical  s    

z3TestDataFrameToCSV.test_to_csv_from_csv_categoricalc                 C   s:   |j d d}t|tsJ tt|dd}t|| d S )N)Zpath_or_bufr   r^   )r0   r   r   r   r   r+   r2   )r   r9   Zcsv_strr;   r   r   r   test_to_csv_path_is_none  s    z+TestDataFrameToCSV.test_to_csv_path_is_nonezdf,encodingrH  rI  r   r   rL  rE   )r  defZghir   asciir   ){   u   你好u   世界gb2312)rs  u   Γειά σουu
   ΚόσμεZcp737c           
   
   C   sd  t  D}|j|||d t||d|d}t || t|d||d,}|j|j|d |jjrfJ W d    n1 sz0    Y  t|||ddd}t || t 	||:}|
 |pd}|jD ]}	|	|v sJ qW d    n1 s0    Y  t 	||&}t |t|d|d	 W d    n1 s60    Y  W d    n1 sV0    Y  d S )
N)compressionr   r   )ru  r   r   wr  )ru  r   r   r   r   r=  )r+   r,   r0   r   r2   r   handleclosedZsqueezedecompress_fileri  r   r   )
r   rW   r   ru  r,  rX   Zhandlesfhtextcolr   r   r   test_to_csv_compression  s6    *
,z*TestDataFrameToCSV.test_to_csv_compressionc           
      C   sz  t dX}|j}t||dd|d}|j|dd t|dd}|d	d
 }|jdd
 |_t || |j|dd t|dd}|dd
 }|jdd
 |_t || |j	}|j|dd t|dd}|dd
 }|j
dd
 |_
t || tdgd g d }td|i|d}	|	j|dd t|ddgdd}t ||	 W d    n1 sl0    Y  d S )NZ__tmp_to_csv_date_format__r$   r  r   %Y%m%ddate_formatr   r^   c                 S   s   t | dS Nr~  r`   strftimer   r   r   r   r{   N  re   z<TestDataFrameToCSV.test_to_csv_date_format.<locals>.<lambda>c                 S   s   t | dS r  r  r   r   r   r   r{   P  re   %Y-%m-%dc                 S   s
   |  dS Nr  r  r   r   r   r   r{   Y  re   c                 S   s
   |  dS r  r  r   r   r   r   r{   [  re   c                 S   s   t | dS r  r  r   r   r   r   r{   g  re   c                 S   s
   |  dS r  r  r   r   r   r   r{   k  re   r   r   )
2000-01-01r  r  r   )r!   r   )r+   r,   r    r   shiftr0   r   r   r2   Tr   r   )
r   r:   r   ro   r   Zdatetime_frame_intZdatetime_frame_strZdatetime_frame_columnsZ	nat_indexZ	nat_framer   r   r   test_to_csv_date_formatC  sH    z*TestDataFrameToCSV.test_to_csv_date_formattdr   Z10sc                 C   s   t d}tdddddd}|| }|d }tjtt|dd	}td
|i|d}|j	|dd t
|dd}t|jddd|_t || W d    n1 s0    Y  d S )Ncsv_date_format_with_dstz2013-10-26 23:00z2013-10-27 01:00zEurope/Londonr   Zinfer)rw   r   Z	ambiguousr8   r&   r   r   Tr   r^   utc)r+   r,   r
   r1   r-   r   r6   r3   r   r0   r   r   r    rv   r2   )r   r  r   timesrl   Z
time_rangerW   rX   r   r   r    test_to_csv_with_dst_transitions{  s$    
z3TestDataFrameToCSV.test_to_csv_with_dst_transitionsc                 C   s  t ddddd}|d }d |j_td|d|d}td	f}|j|d
d t|dd}t	|j
d
dd|_
t	|d d
dd|d< t|| W d    n1 s0    Y  |t td	0}|| t|}t|| W d    n1 s0    Y  d S )Nz
2015-01-01z
2015-12-31r   zEurope/Paris)r   rw   r$   )r5   idxr   r  Tr   r^   r  r  zdatetime64[ns, Europe/Paris])r
   r1   _dataZ_freqr   r+   r,   r0   r   r   r    rv   r  r2   r   Z	to_picklerf   Zread_pickle)r   r  rW   r   rX   r   r   r   ,test_to_csv_with_dst_transitions_with_pickle  s&    
*


z?TestDataFrameToCSV.test_to_csv_with_dst_transitions_with_picklec           	      C   sj  t ddgddgdtjgddgd}g d	}t|}| }||ksJJ |jd d
}||ksbJ g d	}t|}|jtjd
}||ksJ g d}t|}|jtjd
}||ksJ g d}t|}|jtj	d
}||ksJ d}t
jtj|d |jtjd
 W d    n1 s 0    Y  t
jtj|d  |jtjd d W d    n1 sb0    Y  g d}t|}|jtjdd}||ksJ g d}t|}|jtjdd}||ksJ ddg}t|}tt|}t }|j|ddd | |ksJ t ddgddgddgd}|ddg}g d }t|}|jtjd
|ksfJ d S )!NTFr3  g	@*   r@   zb,c)Zc_boolZc_floatZc_intZc_string),c_bool,c_float,c_int,c_string0,True,1.0,42.0,az1,False,3.2,,"b,c")rV  )("","c_bool","c_float","c_int","c_string"z"0","True","1.0","42.0","a"z"1","False","3.2","","b,c")r  z0,True,1.0,42.0,"a"z1,False,3.2,"","b,c"z%need to escape, but no escapechar setrM   )rV  
escapechar)r  r  z1,False,3.2,,b!,c!)z,c_bool,c_ffloat,c_int,c_stringr  z1,False,3.2,,bf,cr   za,b,cz1,"test 
",3r  r>  r$   r(   r%   r   r   r   r   rA   )z"a","b","c"z"1","3","5"z"2","4","6")r   r-   r.   r+   rR  r0   rW  QUOTE_MINIMAL	QUOTE_ALLrX  rT   rU   Errorr]  r   r   rY  Z	set_index)	r   rW   rT  r   rX   r[   Z	text_rowsr{  rE  r   r   r   test_to_csv_quoting  sb    	



.0



z&TestDataFrameToCSV.test_to_csv_quotingc                 C   s   g d}t j|dd}tg d|d}| }g d}t|}||ksLJ d}|j|d}g d	}t|}||kszJ d
tdg}t j|dd}tg d|d}| }g d}t|}||ksJ d S )N)
1990-01-01r  
3005-01-01r   )r   r   r   ),01990-01-01,4z2000-01-01,53005-01-01,6z%m-%d-%Yr  )r  z01-01-1990,4z01-01-2000,5z01-01-3005,6r  r  )r  r  z,5r  )rf   ZPeriodIndexr   r0   r+   rR  r   )r   datesr    rW   rX   rT  r   r  r   r   r   test_period_index_date_overflow  s&    



z2TestDataFrameToCSV.test_period_index_date_overflowc                 C   s^   t g d}tg dg dg}||_g d}|j|d}g d}t|}||ksZJ d S )N))r@   r$   )r@   r(   )rA   r$   )rA   r(   r   )r   r   r   r   )r@   rA   rx   dr   )z,a,b,c,dz	0,1,2,3,4z	1,5,6,7,8)r   rR   r   r   r0   r+   rR  )r   r   rW   r   rX   rT  r   r   r   r   test_multi_index_header-  s    
z*TestDataFrameToCSV.test_multi_index_headerc                 C   sN   t g d}tg dg|d}|jddgd}d}|jdd}t|| d S )	N)r$   )r(   r%   r   r   r  r  z,1,3
0,1,3
rh  re  )r   r   Zreindexr0   r+   r4   )r   r    rW   r   rX   r   r   r   $test_to_csv_single_level_multi_index:  s    z7TestDataFrameToCSV.test_to_csv_single_level_multi_indexc              	   C   s   t dddgi}g d}t|}tdZ}|j|dd tj|dd	}| d
}W d    n1 sn0    Y  W d    n1 s0    Y  ||ksJ d S )Nr@   r$   r(   )r@   rQ  2z__test_gz_lineend.csv.gzFr   gzip)ru  r  )r   r+   rR  r,   r0   ry  ri  r   )r   rW   rT  r   r   r   rX   r   r   r   test_gz_lineendC  s    
Jz"TestDataFrameToCSV.test_gz_lineendc                 C   s<   t dtdddi}t }|| | }d|v s8J d S )Nr@   z1/1/2000r   r   r  )r   r
   r   r0   rY  )r   r
  rE  rX   r   r   r   test_to_csv_numpy_16_bugO  s
    
z+TestDataFrameToCSV.test_to_csv_numpy_16_bugc                 C   s6   t d d gjd dddddd}d}||ks2J d S )NFr@  )r   r    r  rd  rh  z""
""
)r   r0   replace)r   rX   r   r   r   r   test_to_csv_na_quotingX  s    z)TestDataFrameToCSV.test_to_csv_na_quotingc                 C   sb   t ddtjgd}|d d|d< |d d|d< | }g d}t|}||ks^J d S )NrB   r$   r   rA   ZInt16category)z,a,bz0,x,1z1,x,)r   rf   ZNAr  r0   r+   rR  rS  r   r   r   test_to_csv_categorical_and_eac  s    
z1TestDataFrameToCSV.test_to_csv_categorical_and_eac                 C   s^   t dtjtdtdddgi}|d d|d< | }ddg}t|}||ksZJ d S )	Nr@   r   z
2020-01-02Zboth)rx  r  z,az.0,"[2020-01-01 00:00:00, 2020-01-02 00:00:00]")r   rf   ZIntervalr	   r  r0   r+   rR  rS  r   r   r   $test_to_csv_categorical_and_intervalm  s    
z7TestDataFrameToCSV.test_to_csv_categorical_and_interval)NNNNF)C__name__
__module____qualname__r   r=   r\   ri   rt   r~   r   rT   markZparametrizer   Zslowr   r   r   filterwarningsr   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r-  r/  r1  r4  r8  r;  r?  rF  rG  rN  rU  rZ  r^  rc  rm  ro  rp  r   r}  r  rf   rr   r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r      s   &$
$
     
i	
	

 	0)



&		
!8
b		
r   )rW  ior   rj  numpyr-   rT   Zpandas.errorsr   Zpandasrf   r   r   r   r   r   r	   r
   r   r   r   Zpandas._testingZ_testingr+   Zpandas.core.commoncorecommonr  Zpandas.io.commonr   r   r   r   r   r   <module>   s   0