o
    5c                     @   sL  d dl mZm Z mZ d dlmZ d dlmZ d dlZd dlZd dl	Z
d dlZd dlm  mZ d dlZd dlmZmZmZmZ d dlmZ d dlmZmZmZmZmZmZ ej dd Z!ej d	d
 Z"ej#$dej%de&de&dgdej%de&de&dgdej%de&de&dgdej%de&de&dgdej%de&ddgG dd dZ'ej#$dej%dde&de&dgdej%dde&de&dgdej%dde&de&dgdej%dde&de&dgdej%dde&ddgej#(d
G dd dZ)G dd dZ*e&de&dG dd dZ+dS )    )datedatetime	timedelta)partial)BytesION)	DataFrameIndex
MultiIndexoption_context)	ExcelFileExcelWriter_OpenpyxlWriter_XlsxWriter_XlwtWriterregister_writerc                 c   s8    t | }|V  W d   dS 1 sw   Y  dS )z9
    Fixture to open file for use in each test case.
    N)tmensure_clean)ext	file_path r   X/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/tests/io/excel/test_writers.pypath#   s   "r   c                 c   sJ    d| d d}t||  dV  W d   dS 1 sw   Y  dS )aM  
    Fixture to set engine for use in each test case.

    Rather than requiring `engine=...` to be provided explicitly as an
    argument in each test, this fixture sets a global option to dictate
    which engine should be used to write Excel files. After executing
    the test it rolls back said change to the global option.
    z	io.excel..z.writerN)stripr
   )enginer   option_namer   r   r   
set_engine,   s
   
"r   r   .xlsxopenpyxlxlrdmarksz.xlsm.xlsxlwt
xlsxwriter.odsodfc                	   @   s  e Zd Zejddeejgd fdedejgd ifgdd Z	ejddedgejgd  fdeejgd fgd	d
 Z
dd Zdd Zdd Zejdddgejdddgejdddgejdddgdd Zdd Zdd ZdS )TestRoundTripzheader,expectedN   r   z
Unnamed: 0   c                 C   s   d}t g dg dg dg dg}t|}|j||ddd tj||dg|d	}W d    n1 s5w   Y  t|| d S )
N	no_header    d   r,         r,   r)   i,  r,   r(   i  Findexheaderr   
sheet_nameusecolsr6   r   r   r   to_excelpd
read_excelassert_frame_equalselfr   r6   expectedfilenamedfr   resultr   r   r   !test_read_one_empty_col_no_headerH   s    
z/TestRoundTrip.test_read_one_empty_col_no_headerc                 C   s   d}t g dg dg dg dg}t|}|j|dddd tj||d	g|d
}W d    n1 s5w   Y  t|| d S )Nwith_headerr+   r/   r2   r3   FTr4   r   r7   r:   r?   r   r   r   #test_read_one_empty_col_with_headerY   s    
z1TestRoundTrip.test_read_one_empty_col_with_headerc              	   C   s  t ddgddgddggddgd	}t|i}t|}|j|d
ddd |j|ddd W d    n1 s7w   Y  ddg|_t|}tj|d
d ddgd}tj|dd ddgd}W d    n1 sfw   Y  t	|| t	|| W d    d S 1 sw   Y  d S )Nr-   foor0   barr)   bazabcolumnsData_no_headF)r6   r5   Data_with_headr5   AB)r8   r6   names)r8   	index_colrT   )
r   r   r   r   r;   rN   r   r<   r=   r>   )r@   r   refdfpthwriterreaderxlsdf_no_headxlsdf_with_headr   r   r   "test_set_column_names_in_parameteri   s*   "


"z0TestRoundTrip.test_set_column_names_in_parameterc           
   	      s   dd  g d} fdd|D }t t||}t|C}t|}| D ]
\}}||| q'W d    n1 s<w   Y  tj||dd}|D ]}	t	||	 ||	  qKW d    d S 1 scw   Y  d S )Nc                 S   s"   g dg d}}t ||| gdS )N)      !   r-   r0   r)   rM   )r   )col_sheet_namedir   r   r   tdf   s   zDTestRoundTrip.test_creating_and_reading_multiple_sheets.<locals>.tdf)AAABBBCCCc                    s   g | ]} |qS r   r   ).0srd   r   r   
<listcomp>       zKTestRoundTrip.test_creating_and_reading_multiple_sheets.<locals>.<listcomp>r   r8   rU   )
dictzipr   r   r   itemsr;   r<   r=   r>   )
r@   r   sheetsdfsrW   ew	sheetnamerC   dfs_returnedri   r   rj   r   )test_creating_and_reading_multiple_sheets   s   
"z7TestRoundTrip.test_creating_and_reading_multiple_sheetsc                 C   s  t |w}tddiddiddiddid}tddiddiddiddid}|| tj|ddgdd}t || tddiddiddiddid}tddiddiddiddid	}|| tj|ddgdd}t || W d    d S 1 sw   Y  d S )
Nr   r-   r)      )OnexTwoXr|   Y)Zeror,   )rx   r{   r~   )r   zUnnamed: 4_level_1)r6   rU   ))Begr,   Middlerz   Tailr}   r   r   ))r   zUnnamed: 1_level_1r   r   r   r   r   r   r;   r<   r=   r>   )r@   r   r   rC   rA   actualr   r   r   &test_read_excel_multiindex_empty_level   sH   	
		
	"z4TestRoundTrip.test_read_excel_multiindex_empty_levelc_idx_namesTFr_idx_namesc_idx_levelsr-   r_idx_levelsc              	   C   sX  t |}|dkr|r|dkr|rtjjdd}|j| |p$|dk}	t dd||||}
|
| t	j
|tt|tt|d}t j|
||	d tj|
jdd d f< |
| t	j
|tt|tt|d}t j|
||	d tj|
jd	d d f< |
| t	j
|tt|tt|d}t j|
||	d W d    d S 1 sw   Y  d S )
Nr-   r)   z?Column index name cannot be serialized unless it's a MultiIndex)reason   )rU   r6   )check_namesr   )r   r   pytestmarkxfailnode
add_markermakeCustomDataframer;   r<   r=   listranger>   npnaniloc)r@   r   r   r   r   r   requestrW   r   r   rC   actr   r   r   test_excel_multindex_roundtrip   sL   








"z,TestRoundTrip.test_excel_multindex_roundtripc                 C   s   t g dtjdddd}| }|d jd|d< t|>}|| tj	|dd	}t
|| tj	|dgdd
}t
|| dd }tj	|dg|dd}t
|| W d    d S 1 sbw   Y  d S )Nr`   z
2012-01-01r)   )periods)coldate_stringsr   %m/%d/%Yr   rU   )parse_datesrU   c                 S   s   t | dS )Nr   )r   strptimerz   r   r   r   <lambda>  s    z;TestRoundTrip.test_read_excel_parse_dates.<locals>.<lambda>)r   date_parserrU   )r   r<   
date_rangecopydtstrftimer   r   r;   r=   r>   )r@   r   rC   df2rW   resr   r   r   r   test_read_excel_parse_dates   s"   

"z)TestRoundTrip.test_read_excel_parse_datesc                 C   s   t tdtjtddddg}ttd|d}t|}|	| tj
|ddgd}W d    n1 s8w   Y  ttdt tdg d	g}t|| d S )
Nr(   z
2020-01-016M)startr   freqrQ   r   r-   r   )z(2020-01-31, 2020-07-31]z(2020-07-31, 2021-01-31]z(2021-01-31, 2021-07-31]z(2021-07-31, 2022-01-31])r	   from_arraysr   r<   interval_range	Timestampr   r   r   r;   r=   r>   )r@   r   midxrC   rW   rD   rA   r   r   r   "test_multiindex_interval_datetimes  s*   
z0TestRoundTrip.test_multiindex_interval_datetimes)__name__
__module____qualname__r   r   parametrizer   r   r   rE   rG   r\   rv   r   r   r   r   r   r   r   r   r'   ;   s*    *
,
/1r'   z
engine,extc                   @   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ejejejejgdd Ze
jdejejejgdd Ze
jdejejg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&d0d1 Z'd2d3 Z(d4d5 Z)d6d7 Z*d8d9 Z+d:d; Z,d<d= Z-e
jd>d?d@ge
jdAg dBe
jdCg dBdDdE Z.dFdG Z/dHdI Z0dJdK Z1e
jdLdMdNgdOdP Z2dQdR Z3dSdT Z4dUdV Z5dWdX Z6dYdZ Z7d[d\ Z8d]d^ Z9d_d` Z:dadb Z;dcdd Z<dedf Z=dgdh Z>didj Z?e
jdkdle@gdmdn ZAdodp ZBdqdr ZCdsdt ZDdudv ZEe
jdwg dxdydz ZFe
jGd{e
jd|d}d~g dffgdd ZHdd ZIdlS )TestExcelWriterc           	      C   s   d}d}t j|dfd}t jd|fd}t|}t|}d}tjt|d || W d    n1 s5w   Y  tjt|d || W d    d S 1 sRw   Y  d S )Ni  i@  r-   )shapezsheet is too largematch)r   zerosr   r   raises
ValueErrorr;   )	r@   r   breaking_row_countbreaking_col_countrow_arrcol_arrrow_dfcol_dfmsgr   r   r   test_excel_sheet_sizeO  s   "z%TestExcelWriter.test_excel_sheet_sizec                 C   s   t tjdd}|| t|}tj|ddd}W d    n1 s%w   Y  t	|| d}t
jt|d t|d W d    d S 1 sKw   Y  d S )N
   r0   r   rm   zWorksheet named '0' not foundr   0)r   r   randomrandnr;   r   r<   r=   r   r>   r   r   r   )r@   r   gtxlrC   r   r   r   r   test_excel_sheet_by_name_raisea  s   

"z.TestExcelWriter.test_excel_sheet_by_name_raisec                 C   s   t |!}||d | }|jd d d |_||d W d    n1 s(w   Y  t|%}tj|ddd}tj|ddd}t|| t|| W d    d S 1 sYw   Y  d S )NData1r   Data2r   rm   )	r   r;   r   rN   r   r<   r=   r   r>   )r@   framer   rX   frame2rY   found_df	found_df2r   r   r   !test_excel_writer_context_managern  s   

"z1TestExcelWriter.test_excel_writer_context_managerc                 C   s  |  }tj|d d d< ||d |j|dddgd |j|ddd |j|ddd ||d tj|dd	d
}t|| |j|ddd tj|dd d
}|j|_t|| |j|ddd tj|dd	dgd}t|| |j|ddd tj|dd	dgd}t|| |j|ddd tj|dd	ddgd}t|| ||d tj|d	d}t|| ||d tj|d	d}t|| |d }|| tj|d	d}t|	 | d S )NrR   r   test1rS   rM   Fr6   rQ   r   rm   NA)na_rep)r8   rU   	na_values88X   g      V@Sheet1r   r   )
r   r   r   r;   r<   r=   r   r>   r5   to_frame)r@   r   r   reconsri   r   r   r   test_roundtrip|  sD   
zTestExcelWriter.test_roundtripc                 C   sd   |  }d|d< ||d t|}tj|ddd}W d    n1 s%w   Y  t|| d S )NrI   rH   r   r   rm   )r   r;   r   r<   r=   r   r>   )r@   r   r   mixed_framerY   r   r   r   r   
test_mixed  s   
zTestExcelWriter.test_mixedc                 C   st   |}t jt|jd d}||_||d t|}t j|ddd}W d    n1 s-w   Y  t	|| d S )Nr   r   r   rm   )
r<   DatetimeIndexr   asarrayr5   r;   r   r=   r   r>   )r@   tsframer   rC   r5   rY   r   r   r   r   test_ts_frame  s   
zTestExcelWriter.test_ts_framec                 C   s^   |  }tj|d d d< ||d |j|dddgd |j|ddd |j|ddd d S )	NrR   r   r   rS   rM   Fr   rQ   )r   r   r   r;   )r@   r   r   r   r   r   test_basics_with_nan  s   z$TestExcelWriter.test_basics_with_nannp_typec           	      C   s  t tjjdddd|d}||d t|}tj|ddd}W d    n1 s*w   Y  |tj	}t
|| tj|ddd}t
|| |t}|jt|_|jt|_t
jtd	d
 tj|dddd}W d    n1 sww   Y  t
|| d S )Nr   )r   r0   sizedtyper   r   rm   convert_float is deprecatedr   F)r8   convert_floatrU   )r   r   r   randintr;   r   r<   r=   astypeint64r   r>   floatrN   r5   assert_produces_warningFutureWarning)	r@   r   r   rC   rY   r   	int_framerecons2float_framer   r   r   test_int_types  s(   

zTestExcelWriter.test_int_typesc                 C   sn   t tjd|d}||d t|}tj|ddd|}W d    n1 s*w   Y  t	
|| d S )Nr   r   r   r   rm   )r   r   r   random_sampler;   r   r<   r=   r   r   r>   r@   r   r   rC   rY   r   r   r   r   test_float_types  s   
z TestExcelWriter.test_float_typesc                 C   sj   t g d|d}||d t|}tj|ddd|}W d    n1 s(w   Y  t|| d S )N)r-   r   TFr   r   r   rm   )r   r;   r   r<   r=   r   r   r>   r   r   r   r   test_bool_types  s   
zTestExcelWriter.test_bool_typesc                 C   sp   t dtjfddtj fg}||d t|}tj|ddd}W d    n1 s+w   Y  t|| d S )Nr-   )r0   r)   r   r   r   rm   )	r   r   infr;   r   r<   r=   r   r>   )r@   r   rC   rY   r   r   r   r   test_inf_roundtrip   s   
z"TestExcelWriter.test_inf_roundtripc                 C   sP  t jt|jd d}||_| }tj|d d d< ||d |j|dddgd |j|ddd |j|ddd	 t|}||d ||d
 W d    n1 sVw   Y  t	|$}t j
|ddd}t|| t j
|d
dd}t|| W d    n1 sw   Y  dt|jksJ d|jd ksJ d
|jd ksJ d S )Nr   rR   r   r   rS   rM   Fr   rQ   test2r   rm   r0   r-   )r<   r   r   r   r5   r   r   r;   r   r   r=   r   r>   lensheet_names)r@   r   r   r   r5   rX   rY   r   r   r   r   test_sheets	  s*   

zTestExcelWriter.test_sheetsc                 C   s   |  }tj|d d d< ||d |j|dddgd |j|ddd |j|ddd tg d	}|j|d|d t|}tj|dd
d}W d    n1 sRw   Y  |  }||_t	
|| d S )NrR   r   r   rS   rM   Fr   rQ   )AAr}   r   Zr   rm   )r   r   r   r;   r   r   r<   r=   rN   r   r>   )r@   r   r   col_aliasesrY   rsxpr   r   r   test_colaliases$  s   
zTestExcelWriter.test_colaliasesc                 C   sl  |  }tj|d d d< ||d |j|dddgd |j|ddd |j|ddd ttjd	d
dk}|j|ddg|d t|}tj	|ddd
tj}W d    n1 s]w   Y  dg|j_|jj|jjksqJ ttjd	d
dk}|j|dg d|d t|}tj	|ddd
tj}W d    n1 sw   Y  dg|j_|jj|jjksJ ttjd	d
dk}|j|dd|d t|}tj	|ddd
tj}W d    n1 sw   Y  dg|j_t||
t |j|dg dd|d |  }|ddg}t|}tj	|dddgd}W d    n	1 s)w   Y  t|| d S )NrR   r   r   rS   rM   Fr   rQ   r   r0   r   test)index_labelmerge_cellsrm   )r  dummydummy2)rR   rS   CD)rN   r5   r  r-   )r   r   r   r;   r   r   r   r   r<   r=   r   r   r5   rT   r   r>   bool	set_index)r@   r  r   r   rC   rY   r   r   r   r   test_roundtrip_indexlabels6  sf   






z*TestExcelWriter.test_roundtrip_indexlabelsc                 C   s   t tjdd}d|j_|j||d t|}tj	||j
d dd}W d    n1 s.w   Y  t|| |jjdksAJ d S )Nr   r(   rH   r  r   rm   )r   r   r   r   r5   namer;   r   r<   r=   r  r   r>   )r@   r  r   rC   xfrD   r   r   r   test_excel_roundtrip_indexnameo  s   
z.TestExcelWriter.test_excel_roundtrip_indexnamec                 C   s   t jt|jd d}||_| }dd |jD |_|j|d|d t|}t j|ddd}W d    n1 s:w   Y  t	
|| d S )Nr   c                 S   s   g | ]}|  qS r   )r   )rh   rz   r   r   r   rk     rl   zATestExcelWriter.test_excel_roundtrip_datetime.<locals>.<listcomp>r   r  r   rm   )r<   r   r   r   r5   r   r;   r   r=   r   r>   )r@   r  r   r   r5   tsfrY   r   r   r   r   test_excel_roundtrip_datetime{  s   
z-TestExcelWriter.test_excel_roundtrip_datetimec              
   C   s  t tdddtdddgtddd	d
ddtddddddggddgddgd}t tdddtdddgtddd	d
ddtddddddggddgddgd}t|w}t|}||d W d    n1 siw   Y  t|ddd}||d W d    n1 sw   Y  t|}tj	|ddd}	W d    n1 sw   Y  t|}
tj	|
ddd}W d    n1 sw   Y  W d    n1 sw   Y  t
|	| t
|| d S )Ni  r-      i  	      i  r         r_   r(   r0         DATEDATETIMEr}   r   r5   rN   r   z
DD.MM.YYYYzDD.MM.YYYY HH-MM-SS)date_formatdatetime_formatr   rm   )r   r   r   r   r   r   r;   r   r<   r=   r>   )r@   r   r   rC   df_expected	filename2writer1writer2reader1rs1reader2rs2r   r   r   test_excel_date_datetime_format  sH   ""	


z/TestExcelWriter.test_excel_date_datetime_formatc                 C   s   t tjjddddtjd}| }t|d d|d< t|d dt	|d< |
|d t|}tj|ddd	}W d    n1 sFw   Y  t|| d S )
Nr   r      r-   r   r   r   newr   rm   )r   r   r   r   r   r   r<   cutr   strr;   r   r=   r   r>   r@   r   rC   rA   rY   r   r   r   r    test_to_excel_interval_no_labels  s   
z0TestExcelWriter.test_to_excel_interval_no_labelsc                 C   s   t tjjddddtjd}| }tj|d dg dd}||d	< tt	||d	< |
|d
 t|}tj|d
dd}W d    n1 sHw   Y  t|| d S )Nr   r   r4  r   r   r   )
rR   rS   r  r  EFGHIJ)labelsr6  r   rm   )r   r   r   r   r   r   r<   r7  Seriesr   r;   r   r=   r   r>   )r@   r   rC   rA   	intervalsrY   r   r   r   r   test_to_excel_interval_labels  s   
z-TestExcelWriter.test_to_excel_interval_labelsc                 C   s   t tjjdddddgtjd}| }|d dd |d	< |d d
d |d	< ||d t|}t	j
|ddd}W d    n1 sGw   Y  t|| d S )Nr   r   r4  r   rR   )rN   r   c                 S   s
   t | dS )Nseconds)r   r   r   r   r   r     s   
 z9TestExcelWriter.test_to_excel_timedelta.<locals>.<lambda>r6  c                 S   s   t | d d S )NrE  iQ )r   total_secondsr   r   r   r   r     s    r   r   rm   )r   r   r   r   r   r   applyr;   r   r<   r=   r   r>   r9  r   r   r   test_to_excel_timedelta  s   
z'TestExcelWriter.test_to_excel_timedeltac                 C   sl   |j ddd }||d t|}tj|ddd}W d    n1 s&w   Y  t||d d S )NMperiod)kindsht1r   rm   )	resamplemeanr;   r   r<   r=   r   r>   	to_period)r@   r   r   r  rY   r  r   r   r   test_to_excel_periodindex  s   
z)TestExcelWriter.test_to_excel_periodindexc                 C   s   t t|jd dd}tj|ddgd}||_|j|ddd |j|dd	d
gd |j|d|d t|}t	j
|dddgd}W d    n1 sMw   Y  t|| d S )Nr0   r   firstsecondrT   r   Fr   rR   rS   rM   r  r   r-   rm   )r   aranger  r5   reshaper	   r   r;   r   r<   r=   r   r>   )r@   r  r   r   arrays	new_indexrY   rC   r   r   r   test_to_excel_multiindex  s   
z(TestExcelWriter.test_to_excel_multiindexc                 C   s^   t g dg dtjdd}|ddg}|j||d tj|dd	gd
}t	|| d S )N)Nr0   r)   )r   r5     r)   rR   rS   r  rR   rS   r  r   r-   r   )
r   r   r   sampler  r;   r<   r=   r   r>   )r@   r  r   rC   df1r   r   r   "test_to_excel_multiindex_nan_label  s
    z2TestExcelWriter.test_to_excel_multiindex_nan_labelc                 C   s   t t|jd dd}tj|ddgd}||_tg d}||_ddg}|s,d}|j	|d	|d
 t
|}tj|d	|ddgd}	W d    n1 sNw   Y  |sh|jjdddd}
dd t|
 D |_t||	 d S )Nr0   r   rR  rS  rT  ))(   r-   )r_  r0   )2   r-   )r`  r0   r   r-   r   r  r8   r6   rU   F)sparsifyadjoinrT   c                 S   s   g | ]
}d  tt|qS )r   )joinmapr8  )rh   qr   r   r   rk   !  s    zATestExcelWriter.test_to_excel_multiindex_cols.<locals>.<listcomp>)r   rU  r  r5   rV  r	   r   from_tuplesrN   r;   r   r<   r=   formatro   r   r>   )r@   r  r   r   rW  rX  new_cols_indexr6   rY   rC   fmr   r   r   test_to_excel_multiindex_cols  s$   
z-TestExcelWriter.test_to_excel_multiindex_colsc                 C   s   |j tt|j g}t||_ ddg|j _|j|d|d t|}t	j
|dddgd}W d    n1 s8w   Y  t|| |j jdksKJ d S )	NtimerH   r   r  r   r-   rm   )rl  rH   )r5   r   rU  r  r	   r   rT   r;   r   r<   r=   r   r>   )r@   r  r   r   rX  rY   r   r   r   r   test_to_excel_multiindex_dates$  s   
z.TestExcelWriter.test_to_excel_multiindex_datesc                 C   s   t ddgddgddgd}| }tdd	g}||_|j|d
dd t|}tj|d
d}W d    n1 s:w   Y  t	
|| d S )Nr   r5  rZ  r_  r`  <   )rK   rL   c)F   P   )Z   r.   r   FrQ   r8   )r   r   r	   rg  r5   r;   r   r<   r=   r   r>   )r@   r   frame1r   multi_indexrY   frame3r   r   r   'test_to_excel_multiindex_no_write_index1  s   
z7TestExcelWriter.test_to_excel_multiindex_no_write_indexc                 C   s   t g g dd}t g tjg ddgddgd}||d t|}tj|dd	}W d    n1 s3w   Y  tj||d
d
d d S )N)r   r-   r0   rM   r   r-   rT  r0   r(  r   rs  F)check_index_typecheck_dtype)	r   r	   rg  r;   r   r<   r=   r   r>   )r@   r   rA   rC   rY   rD   r   r   r   test_to_excel_empty_multiindexF  s   

z.TestExcelWriter.test_to_excel_empty_multiindexc                 C   s   t g dg dgddgg dd}|j|ddd	 t|}tj|dd
d}W d    n1 s0w   Y  t g dg dgddgg dd}t|| d S )Ng~Ϛ?g9DܜJ?g>D)?g.4i(@33333@̤ArR   rS   r}   r   r
  r(  r   %.2ffloat_formatr   rm   gQ?gq=
ףp?g=
ףp=?gp=
ף(@r}  r~  )r   r;   r   r<   r=   r   r>   )r@   r   rC   rY   rD   rA   r   r   r   test_to_excel_float_formatS  s   
z*TestExcelWriter.test_to_excel_float_formatc                 C   s   t g dg dgddgg dd}td| }|j|dd	 tj|dd
d}t|| W d    d S 1 s9w   Y  d S )N)u   ƒu   Ɠu   Ɣ)u   ƕu   Ɩu   Ɨu   AƒrS   )u   XƓr   r
  r(  z__tmp_to_excel_float_format__.	TestSheetrs  r   rm   r:   )r@   r   rC   rB   rD   r   r   r   test_to_excel_output_encodinge  s   "z-TestExcelWriter.test_to_excel_output_encodingc              	   C   s  t d| _}zzt|d}W n ty   td Y nw W |  n|  w tg dg dgddgg dd	}|j|d
dd t	|}t
j|d
dd}W d    n1 sZw   Y  W d    n1 siw   Y  tg dg dgddgg dd	}t || d S )Nu   ƒu.wbz$No unicode file names on this systemr{  r|  rR   rS   r  r(  r   r  r  r   rm   r  r  )r   r   openUnicodeEncodeErrorr   skipcloser   r;   r   r<   r=   r>   )r@   r   rB   frC   rY   rD   rA   r   r   r   test_to_excel_unicode_filenamer  s2   
z.TestExcelWriter.test_to_excel_unicode_filenameuse_headersTFr_idx_nlevelsr`   c_idx_nlevelsc                    s<  d fdd	}|rdnd }|t dg||}|jdksJ |jd tjus(J d}	d}
tj|	|
||d	}|d
kr\d}tjt	|d |||dd W d    d S 1 sUw   Y  d S |||}|ro|j|	|
| fksnJ n|j|	d
 |
| fks|J t
t|jD ]}t
t|jD ]}|j||f tjusJ qqd S )NTr   c                    sT   | j | |d t}tj||jd |dW  d    S 1 s#w   Y  d S )N)r6   r  r5   r   r8   r6   )r;   r   r<   r=   r  )datar6   
parser_hdrr5   r  r  r   r   r   	roundtrip  s   
$z;TestExcelWriter.test_excel_010_hemstring.<locals>.roundtrip)r-   r0   )r   r   r   r)   )r  r  r-   z_Writing to Excel with MultiIndex columns and no index \('index'=False\) is not yet implemented.r   FrQ   )Tr   T)r   r   r   r   r   r   r   r   r   NotImplementedErrorr   r  r5   rN   )r@   r  r  r  r  r   r  parser_headerr   nrowsncolsrC   r   rro  r   r  r   test_excel_010_hemstring  s2   	"
z(TestExcelWriter.test_excel_010_hemstringc              	   C   s  t g dg dg dgg dd}||d t g dg dg dgg dd}tj|ddd}t|| tjtdd	 tj|ddd
d}W d    n1 sQw   Y  t|| t g dg dgg dd}||d tj|ddd}t g dg dgg dd}t|| |j|dddd tj|dd d}t g dg dg}t|| d}tjtdd	1 tj	t
|d	 tj|dd dd W d    n1 sw   Y  W d    d S W d    d S 1 sw   Y  d S )Nr`   )rR   rS   rS   rM   r   )rR   rS   B.1r   rm   z,the 'mangle_dupe_cols' keyword is deprecatedr   T)r8   rU   mangle_dupe_cols)r-   r0   r)   r(   )r      rw      )rR   rS   rR   rS   )rR   rS   A.1r  Fr4   r  z3Setting mangle_dupe_cols=False is not supported yet)r8   r6   r  )r   r;   r<   r=   r   r>   r   r   r   r   r   )r@   r   rC   rA   rD   r   r   r   r   test_duplicated_columns  sL   ""z'TestExcelWriter.test_duplicated_columnsc                 C   sf   t g dg dd}|j|dddgd tj|ddd	}t|d |d  t|d |d  d S )
Nr-   r-   r-   r0   r0   r0   rR   rS   r   rS   rR   rM   r   r  )r   r;   r<   r=   r   assert_series_equal)r@   r   write_frame
read_framer   r   r   test_swapped_columns  s
   z$TestExcelWriter.test_swapped_columnsc                 C   s   t g dg dd}tjtdd |j|dddgd	 W d    n1 s'w   Y  tjtd
d |j|dddgd	 W d    d S 1 sIw   Y  d S )Nr  r  r  zNot all names specifiedr   r   rS   r  rM   z.'passes columns are not ALL present dataframe'r  )r   r   r   KeyErrorr;   )r@   r   r  r   r   r   test_invalid_columns  s   "z$TestExcelWriter.test_invalid_columnsz#to_excel_index,read_excel_index_col)Tr   )FNc                 C   s^   t g dg dg dd}|j|dddg|d |ddg }tj|d|d	}t|| d S )
Nr  r  )r)   r)   r)   r[  col_subset_bugrR   rS   rN   r5   rm   r   r;   r<   r=   r   r>   )r@   r   to_excel_indexread_excel_index_colr  rA   r  r   r   r   test_write_subset_columns  s   	z)TestExcelWriter.test_write_subset_columnsc                 C   sr   t g dg dd}||d tj|ddd}d |jd< d |jd< d |jd	< tj|dd
dd}t|| d S )Nonez#oner  twor  z#twor  test_cr   rm   )r-   r   r-   r-   )r0   r-   #r8   commentrU   )r   r;   r<   r=   r   r   r>   r@   r   rC   result1result2r   r   r   test_comment_arg  s   


z TestExcelWriter.test_comment_argc                 C   sP   t g dg dd}||d tj|dd}tj|dd d}t|| d S )Nr  r  r  r  rs  )r8   r  r  r  r   r   r   test_comment_default0  s
   z$TestExcelWriter.test_comment_defaultc                 C   sZ   t g dg dd}||d t g dg dd}tj|dddd	}t|| d S )
Nr  r  r  r  )r  Nr  )r  NNr  r   r  r  r@   r   rC   rA   rD   r   r   r   test_comment_used=  s
   z!TestExcelWriter.test_comment_usedc                 C   sT   t ddgddgd}|j|dd t dgd	gd}tj|d
d}t|| d S )N1z#223)rK   rL   FrQ   r-   r0   r  )r  r  r  r   r   r   test_comment_empty_lineK  s
   z'TestExcelWriter.test_comment_empty_linec                 C   s   t ddddddt ddddddt ddddd	d
t ddddddt ddddddt ddddddt ddddddt ddddddt ddddddt ddddddt ddddddg}td|i}||d tj|ddd }t|d |d  d S )!Ni  r-   r%  r0   r)   -   8   r(      1   r  *   rw   9   #   r   )   r$  r]            5      %   r      r5  4   rR   r   r  )r   r   r;   r<   r=   r   r  )r@   r   	datetimesr  r  r   r   r   test_datetimesW  s    zTestExcelWriter.test_datetimesc              	   C   s   t  ?}ttjdd}t||d}|| W d    n1 s#w   Y  |d tj	|dd}t
|| W d    d S 1 sEw   Y  d S )Nr   r0   r   r   r   )r   r   r   r   r   r   r;   seekr<   r=   r   r>   )r@   r   biorC   rX   	reread_dfr   r   r   test_bytes_iom  s   
"zTestExcelWriter.test_bytes_ioc                 C   sz   t dddgdddgg dg dd	}||d
 tj|d
ddd}| }|jt|_|j	d|_t
|| d S )NrK   rL   ro  er0   )rb   r  )r-   r0   g      @)applebananacherry)mixednumericr8  r   r   ra  r   )r   r;   r<   r=   r   r  rH  r8  r  r   r   r>   r@   r   rC   readrA   r   r   r   test_write_lists_dictz  s   z%TestExcelWriter.test_write_lists_dictc                 C   sF   t ddgddgd}||d tj|ddd}|}t|| d S )	Nr-   r0   r)   r(   )renderr  r   r   r   r  r  r   r   r   test_render_as_column_name  s
   z*TestExcelWriter.test_render_as_column_namec                 C   sV   t ddggddgd}|ddd}|| tj|dgdgd	d
}t|| d S )NrH   rI   col1col2rM   TF)rH   rI   r   )true_valuesfalse_valuesrU   )r   replacer;   r<   r=   r   r>   )r@   r   rC   rA   r  r   r   r   !test_true_and_false_value_options  s   
z1TestExcelWriter.test_true_and_false_value_optionsc                 C   sJ   t ddgddggddgd}|j|dd	d
 tj|dd}t|| d S )Nr-   r0   r)   r(   r  r  rM   r   r  )freeze_panesr   r   r  )r@   r   rA   rD   r   r   r   test_freeze_panes  s   z!TestExcelWriter.test_freeze_panesc                 C   J   t  }t|j|d}ttjdd}t j||d| d}t || d S Nr  r   r   rH   )r   )r   makeDataFramer   r;   r<   r=   round_trip_pathlibr>   r@   r   r   rC   rX   rY   rD   r   r   r   test_path_path_lib  
   z"TestExcelWriter.test_path_path_libc                 C   r  r  )r   r  r   r;   r<   r=   round_trip_localpathr>   r  r   r   r   test_path_local_path  r  z$TestExcelWriter.test_path_local_pathc                 C   s   t tdtdftdtdfg}ttd|d}|| tj	t
dd tj|dd	gdd
d}W d    n1 sBw   Y  |jjdd |jd D dd |jd	 D gdd	gd|_|jtj|_t|| d S )N20182018Q12018Q2)r0   r0   rM   r   r   r   r-   F)r6   rU   r   c                 S   s   g | ]}t |qS r   )r8  )rh   rc   r   r   r   rk     rl   zCTestExcelWriter.test_merged_cell_custom_objects.<locals>.<listcomp>)level)r	   rg  r<   Periodr   r   onesr;   r   r   r   r=   rN   
set_levelslevelsr5   r   float64r>   )r@   r   mirA   rD   r   r   r   test_merged_cell_custom_objects  s(   
&z/TestExcelWriter.test_merged_cell_custom_objectsr   Nc                 C   s   |}t jd|d}t|g|d}tjtdd || W d    n1 s'w   Y  | }t|g|d}tjtdd || W d    d S 1 sOw   Y  d S )N2019)tzr   zExcel does not supportr   )r<   r   r   r   r   r   r;   to_pydatetime)r@   r   tz_aware_fixturer   r  r  rC   r   r   r    test_raise_when_saving_timezones  s   "z0TestExcelWriter.test_raise_when_saving_timezonesc                 C   s`   t ddgddgd}|j|g ddd t|}t g d	g d
gg dd}t|| d S )Nr   r-   r   r]   r  )rR   rS   rR   Fr  )r   r   r   )r-   r]   r-   )rR   rS   r  rM   r  )r@   r   rC   rD   rA   r   r   r   'test_excel_duplicate_columns_with_names  s
   
z7TestExcelWriter.test_excel_duplicate_columns_with_namesc              	   C   s   d}t |1}tjtt|d t|dd W d    n1 s#w   Y  W d    d S W d    d S 1 s;w   Y  d S )Nz7if_sheet_exists is only valid in append mode (mode='a')r   r  )if_sheet_exists)r   r   r   r   r   reescaper   )r@   r   r   r  r   r   r   test_if_sheet_exists_raises  s   "z+TestExcelWriter.test_if_sheet_exists_raisesc              	   C   s   t |3}t||d}t | W d    n1 sw   Y  t|}t }t || W d    d S 1 s;w   Y  d S Nr  )r   r   r   r   r;   r<   r=   r>   )r@   r   r   r   rX   rD   rA   r   r   r   test_excel_writer_empty_frame  s   
"z-TestExcelWriter.test_excel_writer_empty_framec                 C   s\   t |}t j||d t|}t }t || W d    d S 1 s'w   Y  d S r  r   )r@   r   r   r   rD   rA   r   r   r   test_to_excel_empty_frame  s   
"z)TestExcelWriter.test_to_excel_empty_frameattr)	cur_sheethandlesr   c              
   C   s   t |L}t|/}| d}t jt|d t|| W d    n1 s'w   Y  t | W d    n1 s<w   Y  W d    d S W d    d S 1 sTw   Y  d S Nz is not part of the public APIr   )r   r   r   r   r   getattrr   r;   )r@   r   r   r  r   rX   r   r   r   r   test_deprecated_attr  s   

"z$TestExcelWriter.test_deprecated_attrz-ignore:Calling close():UserWarning:xlsxwriterz
attr, args)saver   write_cellsr  c              
   C   s   t |N}t|1}| d}t | t jt|d t|||  W d    n1 s/w   Y  W d    n1 s>w   Y  W d    d S W d    d S 1 sVw   Y  d S r  )r   r   r   r   r;   r   r   r  )r@   r   r   r  argsr   rX   r   r   r   r   test_deprecated_method
  s   

"z&TestExcelWriter.test_deprecated_methodc              
   C   s   t |J}t|-}d}t | |j}t jt|d ||_W d    n1 s+w   Y  W d    n1 s:w   Y  W d    d S W d    d S 1 sRw   Y  d S )Nz:Setting the `book` attribute is not part of the public APIr   )r   r   r   r   r;   bookr   r   )r@   r   r   r   rX   r   r  r   r   r   test_deprecated_book_setter  s   
"z+TestExcelWriter.test_deprecated_book_setter)Jr   r   r   r   r   r   r   r   r   r   r   r   r   r   int8int16int32r   r   float16float32r  r  bool8bool_r  r  r  r  r  r  r  r3  r:  rD  rI  rQ  rY  r^  rk  rm  rw  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  objectr  r	  r  r  r  r  filterwarningsr  r  r   r   r   r   r   5  s    1	


	9,	4/


		



r   c                   @   s   e Zd Zejdejede	ddeje
de	ddejede	ddgdd	 Zd
d Zdd Zejdejde	ddejde	ddejde	ddgdd ZdS )TestExcelWriterEngineTestsz	klass,extr   r$   r    r   r"   r#   c              	   C   s   t |=}t| }|dkrtdrt|tsJ nt||s#J W d    n1 s-w   Y  W d    d S W d    d S 1 sEw   Y  d S )Nr   r$   )r   r   r   tdsafe_import
isinstancer   )r@   klassr   r   rX   r   r   r   test_ExcelWriter_dispatch%  s   	
"z4TestExcelWriterEngineTests.test_ExcelWriter_dispatchc                 C   s<   t jtdd td W d    d S 1 sw   Y  d S )Nz	No enginer   nothing)r   r   r   r   r@   r   r   r    test_ExcelWriter_dispatch_raises6  s   
"z;TestExcelWriterEngineTests.test_ExcelWriter_dispatch_raisesc              
   C   s  G dd dt }t| tddI d}t|.}t |}t||s&J W d    n1 s0w   Y  tdd}|| W d    n1 sJw   Y  |  W d    n1 s]w   Y  td}|j|dd W d    n1 syw   Y  |  d S )	Nc                   @   sP   e Zd ZdZdZdZdZdZdd Zdd Z	dd	 Z
ed
d Zedd ZdS )zCTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClassF)xlsxxlsr  c                 S   s   d S )Nr   r-  r   r   r   r  B  s   zHTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.bookc                 S      dt | _d S NT)typecalled_saver-  r   r   r   _saveE     zITestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass._savec                 _   r1  r2  )r3  called_write_cells)r@   r  kwargsr   r   r   _write_cellsH  r6  zPTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass._write_cellsc                 S   r1  r2  )r3  called_sheetsr-  r   r   r   rq   K  s   zJTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.sheetsc                 S   s.   | j sJ | js
J | jrJ d| _ d| _d S )NF)r4  r7  r:  )clsr   r   r   assert_called_and_resetO  s
   



z[TestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.assert_called_and_resetN)r   r   r   r4  r7  r:  _supported_extensions_enginer  r5  r9  propertyrq   classmethodr<  r   r   r   r   
DummyClass;  s    
rA  zio.excel.xlsx.writerr  zsomething.xlsxr-   zsomething.xlsr  )	r   r   r
   r   r   r)  r   r;   r<  )r@   rA  r   filepathrX   rC   r   r   r   test_register_writer:  s"   

	z/TestExcelWriterEngineTests.test_register_writerr   r%   r&   c              	   C   s   t d}tjt|d* tdddidd W d    n1 s!w   Y  W d    d S W d    d S 1 s9w   Y  d S )Nz*Cannot use both engine_kwargs and **kwargsr   r,   rK   r-   r0   )engine_kwargsrL   )r  r  r   r   r   r   )r@   r   r   r   r   r   $test_engine_kwargs_and_kwargs_raisesf  s   

"z?TestExcelWriterEngineTests.test_engine_kwargs_and_kwargs_raisesN)r   r   r   r   r   r   paramr   r'  
skip_if_nor   r   r+  r.  rC  rE  r   r   r   r   r&  $  s&    
	,r&  c                   @   s   e Zd Zdd Zdd ZdS )
TestFSPathc              	   C   s   t d5}tdddgi}|| t|}t|}W d    n1 s'w   Y  ||ks2J W d    d S 1 s=w   Y  d S )Nfoo.xlsxrR   r-   r0   )r   r   r   r;   r   osfspath)r@   r   rC   r   rD   r   r   r   test_excelfile_fspathy  s   

"z TestFSPath.test_excelfile_fspathc              	   C   s~   t d0}t|}t|t|ksJ W d    n1 s w   Y  W d    d S W d    d S 1 s8w   Y  d S )NrI  )r   r   r   rJ  rK  r8  )r@   r   rX   r   r   r   test_excelwriter_fspath  s   
"z"TestFSPath.test_excelwriter_fspathN)r   r   r   rL  rM  r   r   r   r   rH  v  s    rH  ),r   r   r   	functoolsr   ior   rJ  r  numpyr   r   pandas.util._test_decoratorsutil_test_decoratorsr'  pandasr<   r   r   r	   r
   pandas._testing_testingr   pandas.io.excelr   r   r   r   r   r   fixturer   r   r   r   rF  rG  r'   usefixturesr   r&  rH  r   r   r   r   <module>   s     


 o
       ]R