o
    d                     @   s4  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 d dl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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dgej$)dG dd dZ*G dd dZ+e'de'dG dd dZ,ej$%de - dd  Z.dS )!    )datedatetime	timedelta)partial)BytesION)	DataFrameIndex
MultiIndexoption_context)	ExcelFileExcelWriter_OpenpyxlWriter_XlsxWriterregister_writer)_writersc                 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   g/var/www/html/visualizacion-main/env/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
xlsxwriterz.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usecolsr3   r   r   r   to_excelpd
read_excelassert_frame_equalselfr   r3   expectedfilenamedfr   resultr   r   r   !test_read_one_empty_col_no_headerG   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,   r/   r0   FTr1   r   r4   r7   r<   r   r   r   #test_read_one_empty_col_with_headerX   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*   foor-   barr&   bazabcolumnsData_no_headF)r3   r2   Data_with_headr2   AB)r5   r3   names)r5   	index_colrQ   )
r   r   r   r   r8   rK   r   r9   r:   r;   )r=   r   refdfpthwriterreaderxlsdf_no_headxlsdf_with_headr   r   r   "test_set_column_names_in_parameterh   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*   r-   r&   rJ   )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ra   r   r   
<listcomp>       zKTestRoundTrip.test_creating_and_reading_multiple_sheets.<locals>.<listcomp>r   r5   rR   )
dictzipr   r   r   itemsr8   r9   r:   r;   )
r=   r   sheetsdfsrT   ew	sheetnamer@   dfs_returnedrf   r   rg   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ry   Y)Zeror)   )ru   rx   r{   )r}   zUnnamed: 4_level_1r3   rR   ))Begr)   Middlerw   Tailrz   r   r|   ))r   zUnnamed: 1_level_1r   r   r   r   r   r   r8   r9   r:   r;   )r=   r   r   r@   r>   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   )rR   r3   )check_namesr   )r   r   pytestmarkxfailnode
add_markermakeCustomDataframer8   r9   r:   listranger;   npnaniloc)r=   r   r   r   r   r   requestrT   r   r   r@   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|e}|| tj	|dd	}t
|| tj	|dgdd
}t
|| dd }tjtdd tj	|dg|dd}W d    n1 scw   Y  t
|| tj	|dgddd}t
|| W d    d S 1 sw   Y  d S )Nr]   z
2012-01-01r&   )periods)coldate_stringsr   %m/%d/%Yr   rR   )parse_datesrR   c                 S   s   t | dS )Nr   )r   strptimerw   r   r   r   <lambda>  s    z;TestRoundTrip.test_read_excel_parse_dates.<locals>.<lambda>zuse 'date_format' insteadmatch)r   date_parserrR   )r   date_formatrR   )r   r9   
date_rangecopydtstrftimer   r   r8   r:   r;   assert_produces_warningFutureWarning)r=   r   r@   df2rT   resr   r   r   r   test_read_excel_parse_dates   s8   
	
"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   freqrN   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   r9   interval_range	Timestampr   r   r   r8   r:   r;   )r=   r   midxr@   rT   rA   r>   r   r   r   "test_multiindex_interval_datetimes  s*   
z0TestRoundTrip.test_multiindex_interval_datetimes)__name__
__module____qualname__r   r   parametrizer   r   r   rB   rD   rY   rs   r   r   r   r   r   r   r   r   r$   ;   s*    *
,
/1!r$   z
engine,extc                   @   sF  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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 Z.dJdK Z/e
jdLdMdNgdOdP Z0dQdR Z1dSdT Z2dUdV Z3dWdX Z4dYdZ Z5d[d\ Z6d]d^ Z7d_d` Z8dadb Z9dcdd Z:dedf Z;dgdh Z<didj Z=e
jdkdle>gdmdn Z?dodp Z@dqdr ZAdsdt ZBdudv ZCdlS )w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 larger   )r   zerosr   r   raises
ValueErrorr8   )	r=   r   breaking_row_countbreaking_col_countrow_arrcol_arrrow_dfcol_dfmsgr   r   r   test_excel_sheet_sizeU  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
   r-   r   rj   zWorksheet named '0' not foundr   0)r   r   randomrandnr8   r   r9   r:   r   r;   r   r   r   )r=   r   gtxlr@   r   r   r   r   test_excel_sheet_by_name_raisef  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   rj   )	r   r8   r   rK   r   r9   r:   r   r;   )r=   framer   rU   frame2rV   found_df	found_df2r   r   r   !test_excel_writer_context_managers  s   

"z1TestExcelWriter.test_excel_writer_context_managerc                 C   s  |  }tj|jd d|jdf< ||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 )Nr   rO   test1rP   rJ   Fr3   rN   r   rj   NA)na_rep)r5   rR   	na_values88X   g      V@Sheet1r   r   )r   r   r   r   rK   get_locr8   r9   r:   r   r;   r2   to_frame)r=   r   r   reconsrf   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 )NrF   rE   r   r   rj   )r   r8   r   r9   r:   r   r;   )r=   r   r   mixed_framerV   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   rj   )
r9   DatetimeIndexr   asarrayr2   r8   r   r:   r   r;   )r=   tsframer   r@   r2   rV   r   r   r   r   test_ts_frame  s   
zTestExcelWriter.test_ts_framec                 C   sh   |  }tj|jd d|jdf< ||d |j|dddgd |j|ddd |j|ddd d S )	Nr   rO   r   rP   rJ   Fr   rN   )r   r   r   r   rK   r   r8   )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
|| d S )	Nr   )r   r-   sizedtyper   r   rj   )r   r   r   randintr8   r   r9   r:   astypeint64r   r;   )r=   r   r   r@   rV   r   	int_framerecons2r   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   rj   )r   r   r   random_sampler8   r   r9   r:   r   r   r;   )r=   r   r   r@   rV   r   r   r   r   test_float_types  s   
z TestExcelWriter.test_float_typesc                 C   sn   t g dtjd}||d t|}tj|dddtj}W d    n1 s*w   Y  t	|| d S )N)r*   r   TFr   r   r   rj   )
r   r   bool_r8   r   r9   r:   r   r   r;   r=   r   r@   rV   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*   )r-   r&   r   r   r   rj   )	r   r   infr8   r   r9   r:   r   r;   r   r   r   r   test_inf_roundtrip  s   
z"TestExcelWriter.test_inf_roundtripc                 C   sZ  t jt|jd d}||_| }tj|jd d|j	df< |
|d |j
|dddgd |j
|ddd |j
|ddd	 t|}|
|d |
|d
 W d    n1 s[w   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   r   rO   r   rP   rJ   Fr   rN   test2r   rj   r-   r*   )r9   r   r   r   r2   r   r   r   rK   r   r8   r   r   r:   r   r;   lensheet_names)r=   r   r   r   r2   rU   rV   r   r   r   r   test_sheets  s*   

zTestExcelWriter.test_sheetsc                 C   s   |  }tj|jd d|jdf< ||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 sWw   Y  |  }||_t|| d S )Nr   rO   r   rP   rJ   Fr   rN   )AArz   r|   Zr   rj   )r   r   r   r   rK   r   r8   r   r   r9   r:   r   r;   )r=   r   r   col_aliasesrV   rsxpr   r   r   test_colaliases  s   
zTestExcelWriter.test_colaliasesc                 C   sv  |  }tj|jd d|jdf< ||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 sbw   Y  dg|j_|jj|jjksvJ 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 )Nr   rO   r   rP   rJ   Fr   rN   r   r-   r   test)index_labelmerge_cellsrj   )r  dummydummy2)rO   rP   CD)rK   r2   r  r*   )r   r   r   r   rK   r   r8   r   r   r   r   r9   r:   r   r   r2   rQ   r   r;   bool	set_index)r=   r  r   r   r@   rV   r   r   r   r   test_roundtrip_indexlabels-  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%   rE   r  r   rj   )r   r   r   r   r2   namer8   r   r9   r:   r  r   r;   )r=   r  r   r@   xfrA   r   r   r   test_excel_roundtrip_indexnamef  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   )re   rw   r   r   r   rh   {  ri   zATestExcelWriter.test_excel_roundtrip_datetime.<locals>.<listcomp>r   r  r   rj   )r9   r   r   r   r2   r   r8   r   r:   r   r;   )r=   r  r   r   r2   tsfrV   r   r   r   r   test_excel_roundtrip_datetimer  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%   r-         DATEDATETIMErz   r|   r2   rK   r   z
DD.MM.YYYYzDD.MM.YYYY HH-MM-SS)r   datetime_formatr   rj   )r   r   r   r   r   r   r8   r   r9   r:   r;   )r=   r   r   r@   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   rj   )r   r   r   r   r   r   r9   cutr   strr8   r   r:   r   r;   r=   r   r@   r>   rV   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   r0  r   r   r   )
rO   rP   r  r  EFGHIJ)labelsr2  r   rj   )r   r   r   r   r   r   r9   r3  Seriesr   r8   r   r:   r   r;   )r=   r   r@   r>   	intervalsrV   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   r0  r   rO   )rK   r   c                 S   s
   t | dS )Nseconds)r   r   r   r   r   r     s   
 z9TestExcelWriter.test_to_excel_timedelta.<locals>.<lambda>r2  c                 S   s   t | d d S )NrA  iQ )r   total_secondsr   r   r   r   r     s    r   r   rj   )r   r   r   r   r   r   applyr8   r   r9   r:   r   r;   r5  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   rj   )	resamplemeanr8   r   r9   r:   r   r;   	to_period)r=   r   r   r
  rV   r	  r   r   r   test_to_excel_periodindex  s   
z)TestExcelWriter.test_to_excel_periodindexc                 C   s   t jt|jd 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 sPw   Y  t|| d S )Nr-   r   r   firstsecondrQ   r   Fr   rO   rP   rJ   r  r   r*   rj   )r   aranger  r2   r   reshaper	   r   r8   r   r9   r:   r   r;   )r=   r  r   r   arrays	new_indexrV   r@   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)Nr-   r&   )r   r1     r&   rO   rP   r  rO   rP   r  r   r*   r   )
r   r   r   sampler  r8   r9   r:   r   r;   )r=   r  r   r@   df1r   r   r   "test_to_excel_multiindex_nan_label  s
    z2TestExcelWriter.test_to_excel_multiindex_nan_labelc                 C   s   t jt|jd 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 sQw   Y  |sk|j	jdddd}
dd t|
 D |_	t||	 d S )Nr-   r   r   rN  rO  rP  ))(   r*   )r[  r-   )2   r*   )r\  r-   r   r*   r   r  r5   r3   rR   F)sparsifyadjoinrQ   c                 S   s   g | ]
}d  tt|qS )r   )joinmapr4  )re   qr   r   r   rh     s    zATestExcelWriter.test_to_excel_multiindex_cols.<locals>.<listcomp>)r   rQ  r  r2   r   rR  r	   r   from_tuplesrK   r8   r   r9   r:   formatrl   r   r;   )r=   r  r   r   rS  rT  new_cols_indexr3   rV   r@   fmr   r   r   test_to_excel_multiindex_cols  s$   "
z-TestExcelWriter.test_to_excel_multiindex_colsc                 C   s   |j tjt|j tjdg}t||_ ddg|j _|j|d|d t	|}t
j|dddgd}W d    n1 s;w   Y  t|| |j jd	ksNJ d S )
Nr   timerE   r   r  r   r*   rj   )rh  rE   )r2   r   rQ  r  r   r	   r   rQ   r8   r   r9   r:   r   r;   )r=   r  r   r   rT  rV   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   r1  rV  r[  r\  <   )rH   rI   c)F   P   )Z   r+   r   FrN   r5   )r   r   r	   rc  r2   r8   r   r9   r:   r   r;   )r=   r   frame1r   multi_indexrV   frame3r   r   r   'test_to_excel_multiindex_no_write_index(  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*   r-   rJ   r   r*   rP  r-   r%  r   ro  F)check_index_typecheck_dtype)	r   r	   rc  r8   r   r9   r:   r   r;   )r=   r   r>   r@   rV   rA   r   r   r   test_to_excel_empty_multiindex=  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@̤ArO   rP   rz   r|   r  r%  r   %.2ffloat_formatr   rj   gQ?gq=
ףp?g=
ףp=?gp=
ף(@ry  rz  )r   r8   r   r9   r:   r   r;   )r=   r   r@   rV   rA   r>   r   r   r   test_to_excel_float_formatJ  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ƒrP   )u   XƓr|   r  r%  z__tmp_to_excel_float_format__.	TestSheetro  r   rj   r7   )r=   r   r@   r?   rA   r   r   r   test_to_excel_output_encoding\  s   "z-TestExcelWriter.test_to_excel_output_encodingc              	   C   s  t d| c}zt|d W d    n1 sw   Y  W n ty-   td Y 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 s^w   Y  W d    n1 smw   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 systemrw  rx  rO   rP   r{  r%  r   r|  r}  r   rj   r  r  )r   r   openUnicodeEncodeErrorr   skipr   r8   r   r9   r:   r;   )r=   r   r?   r@   rV   rA   r>   r   r   r   test_to_excel_unicode_filenamei  s4   
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)r3   r  r2   r   r5   r3   )r8   r   r9   r:   r  )datar3   
parser_hdrr2   r  r  r   r   r   	roundtrip  s   
$z;TestExcelWriter.test_excel_010_hemstring.<locals>.roundtrip)r*   r-   )r   r   r   r&   )r  r  r*   z_Writing to Excel with MultiIndex columns and no index \('index'=False\) is not yet implemented.r   FrN   )Tr   T)r   r   r   r   r   r   r   r   r   NotImplementedErrorr   r  r2   rK   )r=   r  r  r  r  r   r  parser_headerr   nrowsncolsr@   r   rrk  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 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 S )Nr]   )rO   rP   rP   rJ   r   )rO   rP   B.1r   rj   )r*   r-   r&   r%   )r      rt      )rO   rP   rO   rP   )rO   rP   A.1r  Fr1   r  r   r8   r9   r:   r   r;   r=   r   r@   r>   rA   r   r   r   test_duplicated_columns  s$   "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*   r-   r-   r-   rO   rP   r   rP   rO   rJ   r   r  )r   r8   r9   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   rP   r  rJ   z.'passes columns are not ALL present dataframe'r  )r   r   r   KeyErrorr8   )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&   rW  col_subset_bugrO   rP   rK   r2   rj   r  )r=   r   to_excel_indexread_excel_index_colr  r>   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   rj   )r*   r   r*   r*   )r-   r*   #r5   commentrR   )r   r8   r9   r:   r   r   r;   r=   r   r@   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  ro  )r5   r  r  r  r   r   r   test_comment_default  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   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)rH   rI   FrN   r*   r-   r  )r  r  r  r   r   r   test_comment_empty_line/  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"  r-   r&   -   8   r%      1   r  *   rt   9   #   r  )   r!  rZ            5      %   r      r1  4   rO   r   r  )r   r   r8   r9   r:   r   r  )r=   r   	datetimesr  r  r   r   r   test_datetimes;  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   r-   r   r   r   )r   r   r   r   r   r   r8   seekr9   r:   r   r;   )r=   r   bior@   rU   	reread_dfr   r   r   test_bytes_ioQ  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 )NrH   rI   rk  er-   )r_   f)r*   r-   g      @)applebananacherry)mixednumericr4  r   r   r]  r   )r   r8   r9   r:   r   r  rD  r4  r  r   r   r;   r=   r   r@   readr>   r   r   r   test_write_lists_dict^  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*   r-   r&   r%   )renderr  r   r   r   r  r  r   r   r   test_render_as_column_namep  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 )NrE   rF   col1col2rJ   TF)rE   rF   r   )true_valuesfalse_valuesrR   )r   replacer8   r9   r:   r   r;   )r=   r   r@   r>   r  r   r   r   !test_true_and_false_value_optionsx  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*   r-   r&   r%   r  r  rJ   r   r  )freeze_panesr   r   r  )r=   r   r>   rA   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   rE   )r   )r   makeDataFramer   r8   r9   r:   round_trip_pathlibr;   r=   r   r   r@   rU   rV   rA   r   r   r   test_path_path_lib  
   z"TestExcelWriter.test_path_path_libc                 C   r  r  )r   r  r   r8   r9   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jddd|d}|| tj|dd	gdd
}|j	j
dd |jd D dd |jd	 D gdd	gd|_	t|| d S )N20182018Q12018Q2)r-   r-   r   r   rJ   r   r*   r~   c                 S   s   g | ]}t |qS r   )r4  )re   r`   r   r   r   rh     ri   zCTestExcelWriter.test_merged_cell_custom_objects.<locals>.<listcomp>)level)r	   rc  r9   Periodr   r   onesr8   r:   rK   
set_levelslevelsr   r;   )r=   r   mir>   rA   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   )r9   r   r   r   r   r   r8   to_pydatetime)r=   r   tz_aware_fixturer   r  r  r@   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   rZ   r  )rO   rP   rO   Fr  )r   r   r   )r*   rZ   r*   )rO   rP   r  rJ   r  )r=   r   r@   rA   r>   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   r8   r9   r:   r;   )r=   r   r   r   rU   rA   r>   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   rA   r>   r   r   r   test_to_excel_empty_frame  s   
"z)TestExcelWriter.test_to_excel_empty_frame)Dr   r   r   r   r   r   r   r   r   r   r   r   r   r   int8int16int32r   r   float16float32float64r   r   r  r  r  r  r  r  r/  r6  r@  rE  rM  rU  rZ  rg  ri  rs  rv  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   r   r   r   r   >  s    1	

	9,	4


		r   c                
   @   sZ   e Zd Zej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dS )TestExcelWriterEngineTestsz	klass,extr   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   rU   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_raises  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   book  s   zHTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.bookc                 S      dt | _d S NT)typecalled_saver  r   r   r   _save     zITestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass._savec                 _   r  r  )r  called_write_cells)r=   argskwargsr   r   r   _write_cells  r"  zPTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass._write_cellsc                 S   r  r  )r  called_sheetsr  r   r   r   rn     s   zJTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.sheetsc                 S   s.   | j sJ | js
J | jrJ d| _ d| _d S )NF)r   r#  r'  )clsr   r   r   assert_called_and_reset  s
   



z[TestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.assert_called_and_resetN)r   r   r   r   r#  r'  _supported_extensions_enginer  r!  r&  propertyrn   classmethodr)  r   r   r   r   
DummyClass  s    
r.  zio.excel.xlsx.writerr  zsomething.xlsxr*   zsomething.xlsr  )	r   r   r
   r   r   r  r   r8   r)  )r=   r.  r   filepathrU   r@   r   r   r   test_register_writer  s"   

	z/TestExcelWriterEngineTests.test_register_writerN)r   r   r   r   r   r   paramr   r  
skip_if_nor   r  r  r0  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.xlsxrO   r*   r-   )r   r   r   r8   r   osfspath)r=   r   r@   r   rA   r   r   r   test_excelfile_fspath#  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 )Nr4  )r   r   r   r5  r6  r4  )r=   r   rU   r   r   r   test_excelwriter_fspath+  s   
"z"TestFSPath.test_excelwriter_fspathN)r   r   r   r7  r8  r   r   r   r   r3     s    r3  r  c                 C   s6   dd t tD }dd t | D }||rJ d S )Nc                 S      h | ]	}| d s|qS _
startswithre   r  r   r   r   	<setcomp>4      z%test_subclass_attr.<locals>.<setcomp>c                 S   r9  r:  r<  r>  r   r   r   r?  5  r@  )dirr   symmetric_difference)r  
attrs_baseattrs_klassr   r   r   test_subclass_attr1  s   rE  )/r   r   r   	functoolsr   ior   r5  r  numpyr   r   pandas.util._test_decoratorsutil_test_decoratorsr  pandasr9   r   r   r	   r
   pandas._testing_testingr   pandas.io.excelr   r   r   r   r   pandas.io.excel._utilr   fixturer   r   r   r   r1  r2  r$   usefixturesr   r  r3  valuesrE  r   r   r   r   <module>   s    

 y
       B