3
Udg                 @   s@  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jjZd dlZd dlmZmZmZmZmZ d dlj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#j$de
j%dej&dej&dgde
j%dej&dej&dgde
j%dej&dej&dgde
j%dej&dej&dgde
j%dej&ddgG dd dZ'e
j#j$de
j%ddej&dej&dgde
j%ddej&dej&dgde
j%ddej&dej&dgde
j%ddej&dej&dgde
j%ddej&ddge
j#j(d
G dd dZ)G dd dZ*ej&dej&dG dd dZ+dS )    )datedatetime	timedelta)partial)BytesION)	DataFrameIndex
MultiIndex
get_option
set_option)	ExcelFileExcelWriter_OpenpyxlWriter_XlsxWriter_XlwtWriterregister_writerc          	   c   s    t j| }|V  W dQ R X dS )z9
    Fixture to open file for use in each test case.
    N)tmensure_clean)ext	file_path r   V/var/www/html/virt/lib64/python3.6/site-packages/pandas/tests/io/excel/test_writers.pypath   s    r   c             c   s8   d|j d d}t|}t||  dV  t|| 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
   r   )enginer   Zoption_nameZprev_enginer   r   r   
set_engine"   s
    

r   r   z.xlsxopenpyxlxlrd)marksz.xlsmz.xlsxlwt
xlsxwriterz.odsodfc               @   s  e Zd Zejjddeejgd fdedejgd ifgdd Z	ej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jdddgejjdddgejjdddgej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   sz   d}t jdddgdddgdddgdd	d
gg}tj|,}|j||ddd t j||dg|d}W d Q R X tj|| d S )NZ	no_header    d         r%   i,  r$   i  F)indexheaderr   )
sheet_nameusecolsr,   )pdr   r   r   to_excel
read_excelassert_frame_equal)selfr   r,   expectedfilenamedfr   resultr   r   r   !test_read_one_empty_col_no_header@   s    *z/TestRoundTrip.test_read_one_empty_col_no_headerc             C   sz   d}t jdddgdddgdddgdd	d
gg}tj|,}|j|dddd t j||dg|d}W d Q R X tj|| d S )NZwith_headerr&   r'   r(   r)   r*   r%   i,  r$   i  FT)r+   r,   r   )r-   r.   r,   )r/   r   r   r   r0   r1   r2   )r3   r   r,   r4   r5   r6   r   r7   r   r   r   #test_read_one_empty_col_with_headerQ   s    *z1TestRoundTrip.test_read_one_empty_col_with_headerc             C   s   t jddgddgddggddgd	}tj|}t|(}|j|d
ddd |j|ddd W d Q R X ddg|_t|2}t j|d
d ddgd}t j|dd ddgd}W d Q R X tj	|| tj	|| W d Q R X d S )Nr'   foor)   barr%   Zbazab)columnsZData_no_headF)r,   r+   ZData_with_head)r+   AB)r-   r,   names)r-   	index_colrA   )
r/   r   r   r   r   r0   r>   r   r1   r2   )r3   r   ZrefdfpthwriterreaderZxlsdf_no_headZxlsdf_with_headr   r   r   "test_set_column_names_in_parametera   s     $


z0TestRoundTrip.test_set_column_names_in_parameterc       
         s   dd  dddg} fdd|D }t t||}tj|n}t|(}x |j D ]\}}|j|| qRW W d Q R X tj||dd	}x |D ]}	tj	||	 ||	  qW W d Q R X d S )
Nc             S   s&   dddgdddg }}t ||| gdS )N      !   r'   r)   r%   )r>   )r   )Zcol_sheet_namedir   r   r   tdf   s    zDTestRoundTrip.test_creating_and_reading_multiple_sheets.<locals>.tdfZAAAZBBBZCCCc                s   g | ]} |qS r   r   ).0s)rL   r   r   
<listcomp>   s    zKTestRoundTrip.test_creating_and_reading_multiple_sheets.<locals>.<listcomp>r   )r-   rB   )
dictzipr   r   r   itemsr0   r/   r1   r2   )
r3   r   ZsheetsdfsrC   ewZ	sheetnamer6   Zdfs_returnedrN   r   )rL   r   )test_creating_and_reading_multiple_sheets{   s    


z7TestRoundTrip.test_creating_and_reading_multiple_sheetsc             C   s  t j| }tdddidddiddd	idddii}tdddidddiddd	idddii}|j| tj|ddgdd}t j|| tjdddidddidddiddd	ii}tjdddidddid ddid!dd	ii}|j| tj|ddgdd}t j|| W d Q R X d S )"NOnexr   r'   TwoXr%   Y   Zeror&   Unnamed: 4_level_1)r,   rB   BegMiddleTailUnnamed: 1_level_1)rV   rW   )rX   rY   )rX   rZ   )r\   r&   )rV   rW   )rX   rY   )rX   rZ   )r\   r]   )r^   r&   )r_   rW   )r`   rY   )r`   rZ   )r^   ra   )r_   rW   )r`   rY   )r`   rZ   )r   r   r   r0   r/   r1   r2   )r3   r   r   r6   r4   actualr   r   r   &test_read_excel_multiindex_empty_level   s6    

z4TestRoundTrip.test_read_excel_multiindex_empty_levelc_idx_namesTFr_idx_namesc_idx_levelsr'   r_idx_levelsc       
      C   s(  t j|}|dkr$|r$tjd |p.|dk}t jdd||||}|j| tj|tt	|tt	|d}	t j
||	|d tj|jdd d f< |j| tj|tt	|tt	|d}	t j
||	|d tj|jdd d f< |j| tj|tt	|tt	|d}	t j
||	|d W d Q R X d S )Nr'   z?Column index name cannot be serialized unless it's a MultiIndex   )rB   r,   )check_namesr   )r   r   pytestskipmakeCustomDataframer0   r/   r1   listranger2   npnaniloc)
r3   r   rd   re   rf   rg   rC   ri   r6   Zactr   r   r   test_excel_multindex_roundtrip   s6    





z,TestRoundTrip.test_excel_multindex_roundtripc             C   s   t dddgtjdddd}|j }|d jjd|d< tj|p}|j| tj	|d	d
}tj
|| tj	|dgd	d}tj
|| dd }tj	|dg|d	d}tj
|| W d Q R X d S )Nr'   r)   r%   z
2012-01-01)periods)coldate_stringsrv   z%m/%d/%Yr   )rB   )parse_datesrB   c             S   s   t j| dS )Nz%m/%d/%Y)r   strptime)rW   r   r   r   <lambda>  s    z;TestRoundTrip.test_read_excel_parse_dates.<locals>.<lambda>)rw   date_parserrB   )r   r/   Z
date_rangecopydtstrftimer   r   r0   r1   r2   )r3   r   r6   Zdf2rC   resrz   r   r   r   test_read_excel_parse_dates   s    
z)TestRoundTrip.test_read_excel_parse_datesc             C   s   t jjtdt jt jddddg}t jtd|d}tj|"}|j	| t j
|ddgd}W d Q R X t jtdt jjtdd	d
ddgg}tj|| d S )Nr$   z
2020-01-01Z6M)startrt   freq)r+   r   r'   )rB   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/   r	   from_arraysro   Zinterval_range	Timestampr   r   r   r0   r1   r2   )r3   r   Zmidxr6   rC   r7   r4   r   r   r   "test_multiindex_interval_datetimes
  s"    
z0TestRoundTrip.test_multiindex_interval_datetimes)__name__
__module____qualname__rk   markparametrizer   rp   rq   r8   r9   rF   rU   rc   rs   r   r   r   r   r   r   r#   3   s   68/ .r#   z
engine,extc               @   s8  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	e
jjdejejejejgdd Ze
jjdejejejgdd Ze
j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,e
jjd<d=d>ge
jjd?d@dAdBge
jjdCd@dAdBgdDdE Z-dFdG Z.dHdI Z/dJdK Z0e
jjdLdndogdOdP Z1dQdR Z2dSdT Z3dUdV Z4dWdX Z5dYdZ Z6d[d\ Z7d]d^ Z8d_d` Z9dadb Z:dcdd Z;dedf Z<dgdh Z=didj Z>e
jjdkdNe?gdldm Z@dNS )pTestExcelWriterc       	      C   s   d	}d}t j|dfd}t jd|fd}tj|}tj|}d}tjt|d |j| W d Q R X tjt|d |j| W d Q R X d S )Nr)      r'      )shapezsheet is too large)matchi   i  i @  i@  )rp   Zzerosr/   r   rk   raises
ValueErrorr0   )	r3   r   Zbreaking_row_countZbreaking_col_countZrow_arrZcol_arrZrow_dfZcol_dfmsgr   r   r   test_excel_sheet_sizeC  s    

z%TestExcelWriter.test_excel_sheet_sizec             C   s   t tjjdd}|j| t|}tj|ddd}tj	|| |dkrtd}t
jt|d tj|d W d Q R X n6dd l}d	}t
j|j|d tj|dd
 W d Q R X d S )N
   r)   r   )r-   rB   r"   zsheet 0 not found)r   0zNo sheet named <'0'>)r-   )r   rp   randomrandnr0   r   r/   r1   r   r2   rk   r   r   r   Z	XLRDError)r3   r   r   gtxlr6   r   r   r   r   r   test_excel_sheet_by_name_raiseU  s    
z.TestExcelWriter.test_excel_sheet_by_name_raisec             C   s   t |8}|j|d |j }|jd d d |_|j|d W d Q R X t|>}tj|ddd}tj|ddd}tj|| tj|| W d Q R X d S )NZData1r'   ZData2r   )r-   rB   rj   )	r   r0   r{   r>   r   r/   r1   r   r2   )r3   framer   rD   frame2rE   Zfound_dfZ	found_df2r   r   r   !test_excel_writer_context_manageri  s    

z1TestExcelWriter.test_excel_writer_context_managerc             C   s  |j  }tj|d d d< |j|d |j|dddgd |j|ddd |j|ddd |j|d tj|dd	d
}tj|| |j|ddd tj|dd d
}|j|_tj|| |j|ddd tj|dd	dgd}tj|| |j|ddd tj|dd	dgd}tj|| |j|ddd tj|dd	ddgd}tj|| |j|d tj|d	d}tj|| |j|d tj|d	d}tj|| |d }|j| tj|d	d}tj|j	 | d S )Nr?   rh   test1r@   )r>   F)r,   )r+   r   )r-   rB   ZNA)Zna_rep)r-   rB   Z	na_valuesZ88X   g      V@Sheet1)rB   r   )
r{   rp   rq   r0   r/   r1   r   r2   r+   Zto_frame)r3   r   r   reconsrN   r   r   r   test_roundtripw  sB    
zTestExcelWriter.test_roundtripc             C   sD   |j  }d|d< |j|d t|}tj|ddd}tj|| d S )Nr;   r:   r   r   )r-   rB   )r{   r0   r   r/   r1   r   r2   )r3   r   r   Zmixed_framerE   r   r   r   r   
test_mixed  s    zTestExcelWriter.test_mixedc             C   sT   |}t jtj|jd d}||_|j|d t|}t j|ddd}tj	|| d S )N)r   r   r   )r-   rB   )
r/   DatetimeIndexrp   asarrayr+   r0   r   r1   r   r2   )r3   tsframer   r6   r+   rE   r   r   r   r   test_ts_frame  s    zTestExcelWriter.test_ts_framec             C   s^   |j  }tj|d d d< |j|d |j|dddgd |j|ddd |j|ddd d S )	Nr?   rh   r   r@   )r>   F)r,   )r+   )r{   rp   rq   r0   )r3   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}|j|d t|}tj|ddd}|jtj	}t
j|| tj|ddd}t
j|| |jt}tj|dddd	}t
j||ddd
 d S )Nr   r)   )size)dtyper   r   )r-   rB   F)r-   convert_floatrB   )Zcheck_index_typeZcheck_column_typei)r   r)   )r   rp   r   randintr0   r   r/   r1   astypeint64r   r2   float)	r3   r   r   r6   rE   r   Z	int_frameZrecons2Zfloat_framer   r   r   test_int_types  s    
zTestExcelWriter.test_int_typesc             C   sN   t tjjd|d}|j|d t|}tj|dddj|}t	j
|| d S )Nr   )r   r   r   )r-   rB   )r   rp   r   Zrandom_sampler0   r   r/   r1   r   r   r2   )r3   r   r   r6   rE   r   r   r   r   test_float_types  s
    z TestExcelWriter.test_float_typesc             C   sN   t ddddg|d}|j|d t|}tj|dddj|}tj|| d S )Nr'   r   TF)r   r   )r-   rB   )r   r0   r   r/   r1   r   r   r2   )r3   r   r   r6   rE   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}|j|d t|}tj|ddd}tj|| d S )	Nr'   r)   r%   rh   r   r   )r-   rB   )r)   r%   )	r   rp   infr0   r   r/   r1   r   r2   )r3   r   r6   rE   r   r   r   r   test_inf_roundtrip  s
    z"TestExcelWriter.test_inf_roundtripc             C   s  t jtj|jd d}||_|j }tj|d d d< |j|d |j|dddgd |j|ddd |j|ddd	 t|}|j|d |j|d
 |j	  t
|}t j|ddd}tj|| t j|d
dd}tj|| dt|jkstd|jd kstd
|jd kstd S )N)r   r?   rh   r   r@   )r>   F)r,   )r+   Ztest2r   )r-   rB   r)   r'   )r/   r   rp   r   r+   r{   rq   r0   r   saver   r1   r   r2   lensheet_namesAssertionError)r3   r   r   r   r+   rD   rE   r   r   r   r   test_sheets  s(    zTestExcelWriter.test_sheetsc             C   s   |j  }tj|d d d< |j|d |j|dddgd |j|ddd |j|ddd td	d
ddg}|j|d|d t|}tj|ddd}|j  }||_t	j
|| d S )Nr?   rh   r   r@   )r>   F)r,   )r+   ZAArY   rZ   Zr   )r-   rB   )r{   rp   rq   r0   r   r   r/   r1   r>   r   r2   )r3   r   r   Zcol_aliasesrE   rsxpr   r   r   test_colaliases  s    zTestExcelWriter.test_colaliasesc             C   s  |j  }tj|d d d< |j|d |j|dddgd |j|ddd |j|ddd ttjjd	d
dk}|j|ddg|d t|}tj	|dddj
tj}dg|j_|jj|jjkstttjjd	d
dk}|j|ddddg|d t|}tj	|dddj
tj}dg|j_|jj|jjks0tttjjd	d
dk}|j|dd|d t|}tj	|dddj
tj}dg|j_tj||j
t |j|dddddgd|d |j  }|jddg}t|}tj	|dddgd}tj|| d S )Nr?   rh   r   r@   )r>   F)r,   )r+   r   r)   r   test)Zindex_labelmerge_cells)r-   rB   dummyZdummy2CD)r>   r+   r   r'   )r{   rp   rq   r0   r   r   r   r   r/   r1   r   r   r+   rA   r   r   r2   bool	set_index)r3   r   r   r   r6   rE   r   r   r   r   test_roundtrip_indexlabels,  sN    



z*TestExcelWriter.test_roundtrip_indexlabelsc             C   sf   t tjjdd}d|j_|j||d t|}tj	||j
d dd}tj|| |jjdksbtd S )Nr   r$   r:   )r   r   )r-   rB   )r   rp   r   r   r+   namer0   r   r/   r1   r   r   r2   r   )r3   r   r   r6   xfr7   r   r   r   test_excel_roundtrip_indexname_  s    z.TestExcelWriter.test_excel_roundtrip_indexnamec             C   sn   t jtj|jd d}||_|j }dd |jD |_|j|d|d t|}t j|ddd}t	j
|| d S )N)r   c             S   s   g | ]}|j  qS r   )r   )rM   rW   r   r   r   rO   t  s    zATestExcelWriter.test_excel_roundtrip_datetime.<locals>.<listcomp>r   )r   r   )r-   rB   )r/   r   rp   r   r+   r{   r0   r   r1   r   r2   )r3   r   r   r   r+   ZtsfrE   r   r   r   r   test_excel_roundtrip_datetimek  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j|}t|}t|ddd}|j|d |j|d |j  |j  t|}	t|}
t	j
|	ddd}t	j
|
ddd}tj|| tj|| W d Q R X d S )Ni  r'      i  	      i  rh         rI   r$   r)         ZDATEZDATETIMErY   rZ   )r+   r>   z
DD.MM.YYYYzDD.MM.YYYY HH-MM-SS)Zdate_formatZdatetime_formatr   r   )r-   rB   )r   r   r   r   r   r   r0   closer   r/   r1   r2   )r3   r   r   r   r6   Zdf_expected	filename2Zwriter1Zwriter2Zreader1Zreader2Zrs1Zrs2r   r   r   test_excel_date_datetime_format|  s4    $$z/TestExcelWriter.test_excel_date_datetime_formatc             C   s   t tjjd
dddtjd}|j }tj|d d|d< tj|d djt	|d< |j
|d t|}tj|ddd	}tj|| d S )Nr   r   r'   )r   )r   r   newr   )r-   rB   i)r   r'   )r   rp   r   r   r   r{   r/   cutr   strr0   r   r1   r   r2   )r3   r   r6   r4   rE   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}|j }tj|d dddd	d
ddddddg
d}||d< tjt	||d< |j
|d t|}tj|ddd}tj|| d S )Nr   r   r'   )r   )r   r   r?   r@   r   r   EFGHIJ)labelsr   r   )r-   rB   i)r   r'   )r   rp   r   r   r   r{   r/   r   ZSeriesrn   r0   r   r1   r   r2   )r3   r   r6   r4   Z	intervalsrE   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}|j }|d jdd |d	< |d jd
d |d	< |j|d t|}t	j
|ddd}tj|| d S )Nr   r   r'   )r   r?   )r>   r   c             S   s
   t | dS )N)seconds)r   )rW   r   r   r   ry     s    z9TestExcelWriter.test_to_excel_timedelta.<locals>.<lambda>r   c             S   s   t | dj td S )N)r   iQ )r   total_secondsr   )rW   r   r   r   ry     s    r   r   )r-   rB   i)r   r'   )r   rp   r   r   r   r{   applyr0   r   r/   r1   r   r2   )r3   r   r6   r4   rE   r   r   r   r   test_to_excel_timedelta  s    z'TestExcelWriter.test_to_excel_timedeltac             C   sL   |j dddj }|j|d t|}tj|ddd}tj||jd d S )NMZperiod)kindZsht1r   )r-   rB   )	ZresampleZmeanr0   r   r/   r1   r   r2   Z	to_period)r3   r   r   r   rE   r   r   r   r   test_to_excel_periodindex  s
    z)TestExcelWriter.test_to_excel_periodindexc             C   s   t jt|jd j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}tj|| d S )Nr)   r'   firstsecond)rA   r   F)r,   r?   r@   )r>   )r   r   )r-   rB   rj   )rp   aranger   r+   reshaper	   r   r0   r   r/   r1   r   r2   )r3   r   r   r   arrays	new_indexrE   r6   r   r   r   test_to_excel_multiindex  s    z(TestExcelWriter.test_to_excel_multiindexc             C   sd   t jd ddgdddgtjjdd}|jddg}|j||d	 t j|d
dgd}tj	|| d S )Nr)   r%   r   r      )r?   r@   r   r?   r@   )r   r   r'   )rB   )
r/   r   rp   r   sampler   r0   r1   r   r2   )r3   r   r   r6   Zdf1r   r   r   "test_to_excel_multiindex_nan_label  s    "z2TestExcelWriter.test_to_excel_multiindex_nan_labelc             C   s   t jt|jd jdd}tj|ddgd}||_tjddddg}||_ddg}|s\d}|j	|d	|d
 t
|}tj|d	|ddgd}	|s|jjdddd}
dd t|
 D |_tj||	 d S )Nr)   r'   r   r   )rA   (   2   r   r   )r   )r-   r,   rB   F)ZsparsifyZadjoinrA   c             S   s   g | ]}d j tt|qS )r   )joinmapr   )rM   qr   r   r   rO     s    zATestExcelWriter.test_to_excel_multiindex_cols.<locals>.<listcomp>rj   )r   r'   )r   r)   )r   r'   )r   r)   )rp   r   r   r+   r   r	   r   from_tuplesr>   r0   r   r/   r1   formatrQ   r   r2   )r3   r   r   r   r   r   Znew_cols_indexr,   rE   r6   Zfmr   r   r   test_to_excel_multiindex_cols  s    z-TestExcelWriter.test_to_excel_multiindex_colsc             C   sz   |j tjt|j g}tj||_ ddg|j _|j|d|d t|}t	j
|dddgd}tj|| |j jdksvtd S )	Ntimer:   r   )r   r   r'   )r-   rB   )r   r:   )r+   rp   r   r   r	   r   rA   r0   r   r/   r1   r   r2   r   )r3   r   r   r   r   rE   r   r   r   r   test_to_excel_multiindex_dates  s    z.TestExcelWriter.test_to_excel_multiindex_datesc             C   sn   t ddgddgddgd}|j }tjddg}||_|j|ddd t|}tj|dd}t	j
|| d S )Nr   r   r   r   r   <   )r<   r=   cF   P   Z   r(   r   F)r+   )r-   )r   r   )r   r(   )r   r{   r	   r   r+   r0   r   r/   r1   r   r2   )r3   r   Zframe1r   Zmulti_indexrE   Zframe3r   r   r   'test_to_excel_multiindex_no_write_index'  s    z7TestExcelWriter.test_to_excel_multiindex_no_write_indexc             C   s   t dddgdddggddgd	d
dgd}|j|ddd t|}tj|ddd}t dddgdddggddgd	d
dgd}tj|| d S )Ng~Ϛ?g9DܜJ?g>D)?g.4i(@g33333@g̤Ar?   r@   rY   rZ   r   )r+   r>   r   z%.2f)float_formatr   )r-   rB   gQ?gq=
ףp?g=
ףp=?gp=
ף(@)r   r0   r   r/   r1   r   r2   )r3   r   r6   rE   r7   r4   r   r   r   test_to_excel_float_format<  s    z*TestExcelWriter.test_to_excel_float_formatc             C   sr   t dddgdddggddgd	d
dgd}tjd| 2}|j|ddd tj|ddd}tj|| W d Q R X d S )Nu   ƒu   Ɠu   Ɣu   ƕu   Ɩu   Ɨu   Aƒr@   u   XƓrZ   r   )r+   r>   z__tmp_to_excel_float_format__.Z	TestSheetutf8)r-   encodingr   )r-   rB   )r   r   r   r0   r/   r1   r2   )r3   r   r6   r5   r7   r   r   r   test_to_excel_output_encodingN  s    z-TestExcelWriter.test_to_excel_output_encodingc       	      C   s   t jd| }yt|d}W n tk
r<   tjd Y n
X |j  tdddgddd	ggd
dgdddgd}|j|ddd t	|}t
j|ddd}tdddgddd	ggd
dgdddgd}t j|| W d Q R X d S )Nu   ƒu.wbz$No unicode file names on this systemg~Ϛ?g9DܜJ?g>D)?g.4i(@g33333@g̤Ar?   r@   rY   rZ   r   )r+   r>   r   z%.2f)r  r   )r-   rB   gQ?gq=
ףp?g=
ףp=?gp=
ף(@)r   r   openUnicodeEncodeErrorrk   rl   r   r   r0   r   r/   r1   r2   )	r3   r   r   r5   fr6   rE   r7   r4   r   r   r   test_to_excel_unicode_filename[  s$    z.TestExcelWriter.test_to_excel_unicode_filenameuse_headersTFr_idx_nlevelsr'   r)   r%   c_idx_nlevelsc                s0  d fdd	}|rdnd }|t dg||}|jdks<t|jd tjk	sPtd}	d}
tj|	|
||d	}|dkrd
}tj	t
|d |||dd W d Q R X n|||}|r|j|	|
| fkstn|j|	d |
| fkstxJtt|jD ]8}x2tt|jD ] }|j||f tjk	stqW qW d S )NTr   c                s0   | j | |d t}tj||jd |dS )N)r,   r   r+   r   )r-   r,   )r0   r   r/   r1   r   )datar,   Z
parser_hdrr+   r   )r   r   r   r   	roundtrip  s    z;TestExcelWriter.test_excel_010_hemstring.<locals>.roundtripr'   r)   rh   r%   )r  r  z_Writing to Excel with MultiIndex columns and no index \('index'=False\) is not yet implemented.)r   F)r+   )Tr   T)r'   r)   )r   r   )r   r   r   rr   rp   rq   r   rm   rk   r   NotImplementedErrorro   r   r+   r>   )r3   r   r  r  r  r   r  Zparser_headerr~   ZnrowsZncolsr6   r   rr   r   )r   r   r   test_excel_010_hemstring  s(    
z(TestExcelWriter.test_excel_010_hemstringc             C   s  t dddgdddgdddggdddgd}|j|d t dddgdddgdddggdddgd}tj|dd	d
}tj|| tj|dd	dd}tj|| t ddddgddddggddddgd}|j|d tj|dd	d
}t ddddgddddggddddgd}tj|| |j|dddd tj|dd d}t ddddgddddgg}tj|| d}tjt|d tj|dd dd W d Q R X d S )Nr'   r)   r%   r?   r@   )r>   r   zB.1r   )r-   rB   T)r-   rB   mangle_dupe_colsr$   rh      r[      zA.1F)r+   r,   )r-   r,   z3Setting mangle_dupe_cols=False is not supported yet)r   )r-   r,   r  )	r   r0   r/   r1   r   r2   rk   r   r   )r3   r   r6   r4   r7   r   r   r   r   test_duplicated_columns  s,    *((&z'TestExcelWriter.test_duplicated_columnsc             C   sj   t dddgdddgd}|j|dddgd tj|ddd	}tj|d |d  tj|d |d  d S )
Nr'   r)   )r?   r@   r   r@   r?   )r>   r   )r-   r,   )r   r0   r/   r1   r   assert_series_equal)r3   r   write_frame
read_framer   r   r   test_swapped_columns6  s
    z$TestExcelWriter.test_swapped_columnsc             C   sz   t dddgdddgd}tjtdd |j|dddgd	 W d Q R X tjtd
d |j|dddgd	 W d Q R X d S )Nr'   r)   )r?   r@   zNot all names specified)r   r   r@   r   )r>   z.'passes columns are not ALL present dataframe'r   )r   rk   r   KeyErrorr0   )r3   r   r  r   r   r   test_invalid_columns@  s    z$TestExcelWriter.test_invalid_columnsz#to_excel_index,read_excel_index_colr   Nc             C   sd   t dddgdddgdddgd}|j|dddg|d |ddg }tj|d|d	}tj|| d S )
Nr'   r)   r%   )r?   r@   r   Zcol_subset_bugr?   r@   )r>   r+   )r-   rB   )r   r0   r/   r1   r   r2   )r3   r   Zto_excel_indexZread_excel_index_colr  r4   r  r   r   r   test_write_subset_columnsL  s    	"z)TestExcelWriter.test_write_subset_columnsc             C   sv   t dddgdddgd}|j|d tj|ddd}d |jd< d |jd< d |jd< tj|dddd}tj|| d S )Nonez#onetwoz#two)r?   r@   test_cr   )r-   rB   r'   r)   #)r-   commentrB   )r'   r   )r'   r'   )r)   r'   )r   r0   r/   r1   rr   r   r2   )r3   r   r6   result1result2r   r   r   test_comment_arga  s    


z TestExcelWriter.test_comment_argc             C   sT   t dddgdddgd}|j|d tj|dd}tj|dd d}tj|| d S )	Nr  z#oner  z#two)r?   r@   r   )r-   )r-   r"  )r   r0   r/   r1   r   r2   )r3   r   r6   r#  r$  r   r   r   test_comment_defaultt  s
    z$TestExcelWriter.test_comment_defaultc             C   sb   t dddgdddgd}|j|d t dd dgdd d gd}tj|dddd	}tj|| d S )
Nr  z#oner  z#two)r?   r@   r   r!  r   )r-   r"  rB   )r   r0   r/   r1   r   r2   )r3   r   r6   r4   r7   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j|| d S )N1z#223)r<   r=   F)r+   r'   r)   r!  )r"  )r   r0   r/   r1   r   r2   )r3   r   r6   r4   r7   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}|j|d tj|ddd }tj|d |d  d S )!Ni  r'   r   r)   r%   -   8   r$      1   r  *   r[   9   #   r   )   r   rG         r   5      %   r      r   4   r?   r   )r-   r,   )r   r   r0   r/   r1   r   r  )r3   r   Z	datetimesr  r  r   r   r   test_datetimes  s    zTestExcelWriter.test_datetimesc             C   s^   t  }ttjjdd}t||d}|j| |j  |jd t	j
|dd}tj|| d S )Nr   r)   )r   r   )rB   )r   r   rp   r   r   r   r0   r   seekr/   r1   r   r2   )r3   r   Zbior6   rD   Z	reread_dfr   r   r   test_bytes_io  s    

zTestExcelWriter.test_bytes_ioc             C   s~   t dddgdddgdddgd	d
dgd}|j|d tj|dddd}|j }|jjt|_|jj	d|_t
j|| d S )Nr<   r=   r   er)   )rJ   r	  r'   g      @ZappleZbananaZcherry)mixednumericr   r   r   )r-   r,   rB   r   )r   r0   r/   r1   r{   r?  r   r   r@  r   r   r2   )r3   r   r6   readr4   r   r   r   test_write_lists_dict  s    z%TestExcelWriter.test_write_lists_dictc             C   sF   t ddgddgd}|j|d tj|ddd}|}tj|| d S )	Nr'   r)   r%   r$   )renderr  r   r   )rB   )r   r0   r/   r1   r   r2   )r3   r   r6   rA  r4   r   r   r   test_render_as_column_name  s
    z*TestExcelWriter.test_render_as_column_namec             C   sX   t jddggddgd}|jddd}|j| t j|dgdgd	d
}tj|| d S )Nr:   r;   col1col2)r>   TF)r:   r;   r   )Ztrue_valuesZfalse_valuesrB   )r/   r   replacer0   r1   r   r2   )r3   r   r6   r4   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j|| d S )Nr'   r)   r%   r$   rE  rF  )r>   r   )Zfreeze_panesr   )rB   )r'   r'   )r   r0   r/   r1   r   r2   )r3   r   r4   r7   r   r   r   test_freeze_panes  s    z!TestExcelWriter.test_freeze_panesc             C   sJ   t j }t|j|d}ttjdd}t j||d| d}t j|| d S )N)r   r   )rB   r:   )r   )r   makeDataFramer   r0   r/   r1   Zround_trip_pathlibr2   )r3   r   r   r6   rD   rE   r7   r   r   r   test_path_path_lib  s
    z"TestExcelWriter.test_path_path_libc             C   sJ   t j }t|j|d}ttjdd}t j||d| d}t j|| d S )N)r   r   )rB   r:   )r   )r   rJ  r   r0   r/   r1   Zround_trip_localpathr2   )r3   r   r   r6   rD   rE   r7   r   r   r   test_path_local_path  s
    z$TestExcelWriter.test_path_local_pathc             C   s   t jtjdtjdftjdtjdfg}ttjd|d}|j| tj|ddgddd	}|j	j
d
d |jd D d
d |jd D gddgdd |jjtj|_tj|| d S )NZ2018Z2018Q1Z2018Q2r)   )r>   r   r'   F)r,   rB   r   c             S   s   g | ]}t |qS r   )r   )rM   rK   r   r   r   rO   
  s    zCTestExcelWriter.test_merged_cell_custom_objects.<locals>.<listcomp>T)levelZinplace)r)   r)   )r	   r   r/   ZPeriodr   rp   Zonesr0   r1   r>   Z
set_levelsZlevelsr+   r   float64r   r2   )r3   r   r   mir4   r7   r   r   r   test_merged_cell_custom_objects  s    
&z/TestExcelWriter.test_merged_cell_custom_objectsr   c             C   s   |}t jd|d}t|g|d}tjtdd |j| W d Q R X |j }t|g|d}tjtdd |j| W d Q R X d S )NZ2019)tz)r   zExcel does not support)r   )r/   r   r   rk   r   r   r0   Zto_pydatetime)r3   r   Ztz_aware_fixturer   rQ  r  r6   r   r   r    test_raise_when_saving_timezones  s    z0TestExcelWriter.test_raise_when_saving_timezones)Tr   )FN)Ar   r   r   r   r   r   r   r   r   r   rk   r   r   rp   Zint8Zint16Zint32r   r   Zfloat16Zfloat32rN  r   Zbool8Zbool_r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r  r  r%  r&  r'  r+  r;  r=  rB  rD  rH  rI  rK  rL  rP  objectrR  r   r   r   r   r   )  sj   1	&"	3/	 3'
r   c            	   @   sn   e Zd Zejjdejedej	ddeje
dej	ddejedej	ddgdd	 Zd
d Zdd ZdS )TestExcelWriterEngineTestsz	klass,extz.xlsxr!   )r   r   z.xlsr    c          
   C   sR   t j|>}t|}|dkr6tjdr6t|tsDtnt||sDtW d Q R X d S )Nz.xlsxr!   )r   r   r   tdZsafe_import
isinstancer   r   )r3   klassr   r   rD   r   r   r   test_ExcelWriter_dispatch!  s
    	z4TestExcelWriterEngineTests.test_ExcelWriter_dispatchc          	   C   s&   t jtdd td W d Q R X d S )Nz	No engine)r   Znothing)rk   r   r   r   )r3   r   r   r    test_ExcelWriter_dispatch_raises2  s    z;TestExcelWriterEngineTests.test_ExcelWriter_dispatch_raisesc                s   g  g G  fdddt } fdd}tjddP t| t d}t||sXttjdd|fd	d
 |fdd
 W d Q R X d S )Nc                   s8   e Zd ZdZdZddgZdZ fddZfddZd	S )
zCTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClassFZxlsxZxlsr   c                s    j d d S )NT)append)r3   )called_saver   r   r   A  s    zHTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.savec                s    j d d S )NT)rZ  )r3   argskwargs)called_write_cellsr   r   write_cellsD  s    zOTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.write_cellsN)	r   r   r   r[  r^  Zsupported_extensionsr   r   r_  r   )r[  r^  r   r   
DummyClass;  s   r`  c                s>   |   t  dkstt dks&t d d = d d = d S )Nr'   )r   r   )func)r[  r^  r   r   check_calledG  s
    
zETestExcelWriterEngineTests.test_register_writer.<locals>.check_calledzio.excel.xlsx.writerr   zsomething.xlsxr'   c                  s
    j dS )Nzsomething.xlsx)r0   r   )r6   r   r   ry   S  s    zATestExcelWriterEngineTests.test_register_writer.<locals>.<lambda>c                  s    j dddS )Nzsomething.xlsr   )r   )r0   r   )r6   r   r   ry   T  s    )r   r/   Zoption_contextr   rV  r   r   rm   )r3   r`  rb  rD   r   )r[  r^  r6   r   test_register_writer6  s    z/TestExcelWriterEngineTests.test_register_writerN)r   r   r   rk   r   r   paramr   rU  
skip_if_nor   r   rX  rY  rc  r   r   r   r   rT     s   "rT  c               @   s   e Zd Zdd Zdd ZdS )
TestFSPathc             C   sR   t jd>}tdddgi}|j| t|}tj|}||ksDtW d Q R X d S )Nzfoo.xlsxr?   r'   r)   )r   r   r   r0   r   osfspathr   )r3   r   r6   r   r7   r   r   r   test_excelfile_fspathZ  s    

z TestFSPath.test_excelfile_fspathc          
   C   s8   t jd$}t|}tj|t|ks*tW d Q R X d S )Nzfoo.xlsx)r   r   r   rg  rh  r   r   )r3   r   rD   r   r   r   test_excelwriter_fspathb  s    z"TestFSPath.test_excelwriter_fspathN)r   r   r   ri  rj  r   r   r   r   rf  W  s   rf  ),r   r   r   	functoolsr   ior   rg  Znumpyrp   rk   Zpandas.util._test_decoratorsutilZ_test_decoratorsrU  Zpandasr/   r   r   r	   r
   r   Zpandas._testingZ_testingr   Zpandas.io.excelr   r   r   r   r   r   Zfixturer   r   r   r   rd  re  r#   Zusefixturesr   rT  rf  r   r   r   r   <module>   sb   
 
	& n       f7