a
    Pfs                     @   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Zd dlmZ d dlmZ d dlmZ d dlm  mZ d dlZd dlmZ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 rej(j)Z*e+e+dddZ,ej-dd Z.ej-ddgddd Z/ej-dd Z0ej-dd Z1ej(2dej3de4de4dgdej3de4de4dgdej3de4de4dgdej3d e4d!dgG d"d# d#Z5ej(2d$ej3dde4de4dgdej3dde4de4dgdej3dde4de4dgdej3d!d e4d!dgej(6dG d%d& d&Z7G d'd( d(Z8e4de4dG d)d* d*Z9ej(2d+e': d,d- Z;dS ).    )datedatetime	timedelta)partial)BytesION)is_platform_windows)PY310)import_optional_dependency)	DataFrameIndex
MultiIndex
date_rangeoption_context)	ExcelFileExcelWriter_OpenpyxlWriter_XlsxWriterregister_writer)_writers)pathreturnc                 C   s   dS )Nns r   r   r   [/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/tests/io/excel/test_writers.pyget_exp_unit*   s    r   c                 C   s   | dd S )z?
    Returns the first ten items in fixture "float_frame".
    N
   r   )Zfloat_framer   r   r   frame.   s    r   TF)paramsc                 C   s   | j S N)param)requestr   r   r   merge_cells6   s    r"   c                 c   s4   t | }|V  W d   n1 s&0    Y  dS )z9
    Fixture to open file for use in each test case.
    N)tmensure_clean)ext	file_pathr   r   r   r   ;   s    r   c                 c   sF   d| d d}t||  dV  W d   n1 s80    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%   Zoption_namer   r   r   
set_engineD   s    
r*   r%   .xlsxopenpyxlZxlrdZ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|6}|j||ddd tj||dg|d	}W d    n1 sj0    Y  t|| d S )
NZ	no_header    d   r4         r4   r2   i,  r4   r1   i  F
sheet_nameindexheaderr   r=   Zusecolsr?   r
   r#   r$   to_excelpd
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   s   d}t g dg dg dg dg}t|6}|j|dddd tj||d	g|d
}W d    n1 sj0    Y  t|| d S )NZwith_headerr3   r7   r:   r;   FTr<   r   r@   rA   rF   r   r   r   #test_read_one_empty_col_with_headerp   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|}t|2}|j|d
ddd |j|ddd W d    n1 sn0    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 s0    Y  t	|| t	|| W d    n1 s0    Y  d S )Nr5   foor8   barr2   ZbazabcolumnsZData_no_headF)r=   r?   r>   ZData_with_headr=   r>   AB)r=   r?   names)r=   	index_colrW   )
r
   r#   r$   r   rB   rS   r   rC   rD   rE   )rG   r%   ZrefdfpthwriterreaderZxlsdf_no_headZxlsdf_with_headr   r   r   "test_set_column_names_in_parameter   s(    "
.

$z0TestRoundTrip.test_set_column_names_in_parameterc           
   	      s   dd  g d} fdd|D }t t||}t|}t|0}| D ]\}}|j||d qNW d    n1 sz0    Y  tj||dd}|D ]}	t	||	 ||	  qW d    n1 s0    Y  d S )	Nc                 S   s"   g dg d }}t ||| gdS )N)      !   r5   r8   r2   rR   )r
   )Zcol_sheet_namedir   r   r   tdf   s    zDTestRoundTrip.test_creating_and_reading_multiple_sheets.<locals>.tdf)ZAAAZBBBZCCCc                    s   g | ]} |qS r   r   ).0src   r   r   
<listcomp>       zKTestRoundTrip.test_creating_and_reading_multiple_sheets.<locals>.<listcomp>r=   r   r=   rX   )
dictzipr#   r$   r   itemsrB   rC   rD   rE   )
rG   r%   sheetsdfsrY   ewZ	sheetnamerJ   Zdfs_returnedre   r   rf   r   )test_creating_and_reading_multiple_sheets   s    
.z7TestRoundTrip.test_creating_and_reading_multiple_sheetsc                 C   s
  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 || 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    n1 s0    Y  d S )
Nr   r5   r2      )ZOnexTwoXrv   Y)Zeror4   )rs   ru   rx   )rz   zUnnamed: 4_level_1r?   rX   ))Begr4   ZMiddlert   Tailrw   r   ry   ))r|   zUnnamed: 1_level_1r}   r~   r   r#   r$   r
   rB   rC   rD   rE   )rG   r%   r   rJ   rH   actualr   r   r   &test_read_excel_multiindex_empty_level   sF    		
		
z4TestRoundTrip.test_read_excel_multiindex_empty_levelc_idx_namesrP   r_idx_namesrQ   c_idx_levelsr5   r_idx_levelsc                    s  t |}tp|dk}|dkr4ttd}	n.tjdd t|D  fddt|D d}	|dkrxttd}
n.tjdd t|D fd	dt|D d}
td
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    n1 s0    Y  d S )Nr5   Zabcdec                 S   s   g | ]}t d qS    rangerd   _r   r   r   rg      rh   z@TestRoundTrip.test_excel_multindex_roundtrip.<locals>.<listcomp>c                    s   g | ]}  d | qS -r   rd   rb   )r   r   r   rg      rh   rW   Zghijkc                 S   s   g | ]}t d qS r   r   r   r   r   r   rg      rh   c                    s   g | ]}  d | qS r   r   r   )r   r   r   rg      rh   皙?)r   r   rS   r>   )rX   r?   )check_namesr   )r#   r$   boolr   listr   from_arraysr   r
   nponesrB   rC   rD   rE   naniloc)rG   r%   r   r   r   r   r!   rY   r   rS   r>   rJ   Zactr   )r   r   r   test_excel_multindex_roundtrip   sT    








z,TestRoundTrip.test_excel_multindex_roundtripc              	   C   s   t g dt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tddd$ tj	|dg|dd}W d    n1 s0    Y  t
|| tj	|dgddd}t
|| W d    n1 s0    Y  d S )Nr`   z
2012-01-01r2   )periods)coldate_stringsr   %m/%d/%Yr   rX   )parse_datesrX   c                 S   s   t | dS )Nr   )r   strptimert   r   r   r   <lambda>0  rh   z;TestRoundTrip.test_read_excel_parse_dates.<locals>.<lambda>zuse 'date_format' insteadF)matchZraise_on_extra_warnings)r   date_parserrX   )r   date_formatrX   )r
   r   copydtstrftimer#   r$   rB   rC   rD   rE   assert_produces_warningFutureWarning)rG   r%   rJ   Zdf2rY   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 sp0    Y  ttdt tdg d	g}t|| d S )
Nr1   z
2020-01-01Z6ME)startr   freqr>   r   r5   r   )z*(2020-01-31 00:00:00, 2020-07-31 00:00:00]z*(2020-07-31 00:00:00, 2021-01-31 00:00:00]z*(2021-01-31 00:00:00, 2021-07-31 00:00:00]z*(2021-07-31 00:00:00, 2022-01-31 00:00:00])r   r   r   rC   Zinterval_range	Timestampr
   r#   r$   rB   rD   rE   )rG   r%   ZmidxrJ   rY   rK   rH   r   r   r   "test_multiindex_interval_datetimesB  s(    
0z0TestRoundTrip.test_multiindex_interval_datetimes)__name__
__module____qualname__pytestmarkparametrizer
   r   r   rL   rM   r\   rq   r   r   r   r   r   r   r   r   r0   S   s(   *
,
/8#r0   z
engine,extc                   @   sN  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=dkdl Z>e
jdmdne?gdodp Z@dqdr ZAdsdt ZBdudv ZCdwdx ZDdnS )y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 sj0    Y  tjt|d || W d    n1 s0    Y  d S )Ni  i@  r5   )shapezsheet is too larger   )r   Zzerosr
   r   raises
ValueErrorrB   )	rG   r   Zbreaking_row_countZbreaking_col_countZrow_arrZcol_arrZrow_dfZcol_dfmsgr   r   r   test_excel_sheet_sizex  s    (z%TestExcelWriter.test_excel_sheet_sizec                 C   s   t tjdd}|| t| }tj|ddd}W d    n1 sN0    Y  t	
|| d}tjt|d t|d W d    n1 s0    Y  d S )Nr8   r   r8   r   rj   zWorksheet named '0' not foundr   0)r
   r   randomdefault_rngstandard_normalrB   r   rC   rD   r#   rE   r   r   r   )rG   r   gtxlrJ   r   r   r   r   test_excel_sheet_by_name_raise  s    

.z.TestExcelWriter.test_excel_sheet_by_name_raisec                 C   s   t |F}|j|dd | }|jd d d |_|j|dd W d    n1 sT0    Y  t|H}tj|ddd}tj|ddd}t|| t|| W d    n1 s0    Y  d S )NZData1ri   r   ZData2r   rj   )	r   rB   r   rS   r   rC   rD   r#   rE   )rG   r   r   rZ   frame2r[   Zfound_dfZ	found_df2r   r   r   !test_excel_writer_context_manager  s    
,
z1TestExcelWriter.test_excel_writer_context_managerc                 C   s  |  }tj|jd d|jdf< |j|dd |j|dddgd |j|ddd |j|ddd	 |j|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	
|| |j|dd tj|d
d}t	
|| |j|dd tj|d
d}t	
|| |d }|| tj|d
d}t	
| | d S )Nr   rU   test1ri   rV   r=   rS   Fr=   r?   rT   r   rj   ZNA)r=   Zna_rep)r=   rX   Z	na_valuesZ88X   g      V@Sheet1r   r   )r   r   r   r   rS   get_locrB   rC   rD   r#   rE   r>   Zto_frame)rG   r   r   reconsre   r   r   r   test_roundtrip  sD    
zTestExcelWriter.test_roundtripc                 C   sf   |  }d|d< |j|dd t| }tj|ddd}W d    n1 sL0    Y  t|| d S )NrO   rN   r   ri   r   rj   )r   rB   r   rC   rD   r#   rE   )rG   r   r   Zmixed_framer[   r   r   r   r   
test_mixed  s    
.zTestExcelWriter.test_mixedc                 C   s   t |}ttjddttdtddddd}t	j
t|jd d	}||_|d d  }|j||_|j|d
d t| }t	j|d
dd}W d    n1 s0    Y  t|| d S )Nr8   r   r1   ABCD
2000-01-01r   rV   r   r   r   r   r   ri   r   rj   )r   r
   r   r   r   r   r   r   r   rC   DatetimeIndexasarrayr>   as_unitrB   r   rD   r#   rE   )rG   r   unitrJ   r>   rH   r[   r   r   r   r   test_ts_frame  s    

.zTestExcelWriter.test_ts_framec                 C   sj   |  }tj|jd d|jdf< |j|dd |j|dddgd |j|ddd |j|ddd	 d S )
Nr   rU   r   ri   rV   r   Fr   rT   )r   r   r   r   rS   r   rB   )rG   r   r   r   r   r   test_basics_with_nan  s    z$TestExcelWriter.test_basics_with_nannp_typec                 C   s   t tjdjdddd|d}|j|dd t| }tj|dd	d
}W d    n1 s\0    Y  |	tj
}t|| tj|dd	d
}t|| d S )Nr8   r   r   sizedtyper   ri   r   rj   )r
   r   r   r   integersrB   r   rC   rD   astypeint64r#   rE   )rG   r   r   rJ   r[   r   Z	int_frameZrecons2r   r   r   test_int_types  s    
.zTestExcelWriter.test_int_typesc                 C   sv   t tjdd|d}|j|dd t|&}tj|ddd|}W d    n1 s\0    Y  t	
|| d S )Nr8   r   r   r   ri   r   rj   )r
   r   r   r   rB   r   rC   rD   r   r#   rE   )rG   r   r   rJ   r[   r   r   r   r   test_float_types  s    
"z TestExcelWriter.test_float_typesc                 C   sp   t g dtjd}|j|dd t|(}tj|dddtj}W d    n1 sV0    Y  t	|| d S )N)r5   r   TFr   r   ri   r   rj   )
r
   r   Zbool_rB   r   rC   rD   r   r#   rE   rG   r   rJ   r[   r   r   r   r   test_bool_types  s    
"zTestExcelWriter.test_bool_typesc                 C   sr   t dtjfddtj fg}|j|dd t| }tj|ddd}W d    n1 sX0    Y  t|| d S )Nr5   )r8   r2   r   r   ri   r   rj   )	r
   r   infrB   r   rC   rD   r#   rE   r   r   r   r   test_inf_roundtrip%  s
    
.z"TestExcelWriter.test_inf_roundtripc           
      C   s  t |}ttjddttdtddddd}t	j
t|jd d	}||_|d d  }|j||_| }tj|jd d|jd
f< |j|dd |j|dd
dgd |j|ddd |j|ddd t|,}|j|dd |j|dd W d    n1 s0    Y  t|<}t	j|ddd}	t||	 t	j|ddd}	W d    n1 sd0    Y  t||	 dt|jksJ d|jd ksJ d|jd ksJ d S )Nr8   r   r   r   r   rV   r   r   r   rU   r   ri   r   Fr   rT   Ztest2r   rj   r5   )r   r
   r   r   r   r   r   r   r   rC   r   r   r>   r   r   r   r   rS   r   rB   r   r   rD   r#   rE   lensheet_names)
rG   r   r   r   tsframer>   rH   rZ   r[   r   r   r   r   test_sheets.  s6    

.
0zTestExcelWriter.test_sheetsc                 C   s   |  }tj|jd d|jdf< |j|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 s0    Y  |  }||_t|| d S )Nr   rU   r   ri   rV   r   Fr   rT   )ZAArw   ry   Zr   rj   )r   r   r   r   rS   r   rB   r   r   rC   rD   r#   rE   )rG   r   r   Zcol_aliasesr[   rsxpr   r   r   test_colaliasesQ  s    
.zTestExcelWriter.test_colaliasesc                 C   s  |  }tj|jd d|jdf< |j|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 s0    Y  dg|j_|jj|jjksJ ttj	d

ddk}|j|dg d|d t|(}tj|dddtj}W d    n1 sZ0    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 s0    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 sp0    Y  t|| d S )Nr   rU   r   ri   rV   r   Fr   rT   r8   r   r   test)r=   Zindex_labelr"   rj   )r   dummyZdummy2)rU   rV   CD)r=   rS   r>   r"   r5   )r   r   r   r   rS   r   rB   r
   r   r   r   r   rC   rD   r   r   r>   rW   r#   rE   r   	set_index)rG   r"   r   r   rJ   r[   r   r   r   r   test_roundtrip_indexlabelsc  sf    

"

$

$

4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`0    Y  t|| |jjdksJ d S )Nr8   )r   r1   rN   r"   r   rj   )r
   r   r   r   r   r>   namerB   r   rC   rD   r   r#   rE   )rG   r"   r   rJ   xfrK   r   r   r   test_excel_roundtrip_indexname  s    
4z.TestExcelWriter.test_excel_roundtrip_indexnamec           
      C   s   t |}ttjddttdtddddd}t	j
t|jd d	}||_| }d
d |jD |_|j|d|d t| }t	j|ddd}W d    n1 s0    Y  |d d  }	|	j||	_t|	| d S )Nr8   r   r   r   r   rV   r   r   r   c                 S   s   g | ]}|  qS r   )r   )rd   rt   r   r   r   rg     rh   zATestExcelWriter.test_excel_roundtrip_datetime.<locals>.<listcomp>r   r=   r"   r   rj   )r   r
   r   r   r   r   r   r   r   rC   r   r   r>   r   rB   r   rD   r   r#   rE   )
rG   r"   r   r   r   r>   Ztsfr[   r   rH   r   r   r   test_excel_roundtrip_datetime  s     

.z-TestExcelWriter.test_excel_roundtrip_datetimec              
   C   s  t |}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}|d| d}t|}t|}|j|dd W d    n1 s0    Y  t|ddd}|j|dd W d    n1 s,0    Y  t	| }	t
j|	ddd}
W d    n1 sf0    Y  t	| }t
j|ddd}W d    n1 s0    Y  W d    n1 s0    Y  t|
| t|| d S )Ni  r5      i  	      i  r         r_   r1   r8         ZDATEZDATETIMErw   ry   r>   rS   M8[]r   ri   z
DD.MM.YYYYzDD.MM.YYYY HH-MM-SS)r   Zdatetime_formatr   rj   )r   r
   r   r   r   r#   r$   r   rB   r   rC   rD   rE   )rG   r%   r   r   rJ   Zdf_expected	filename2Zwriter1Zwriter2Zreader1Zrs1Zreader2Zrs2r   r   r   test_excel_date_datetime_format  s@    ""
,.
0
Pz/TestExcelWriter.test_excel_date_datetime_formatc                 C   s   t tjdjddddtjd}| }t|d d|d< t|d d	|sVt
nd	|d< |j|d
d t| }tj|d
dd}W d    n1 s0    Y  t|| d S )Nr8   r   r      r5   r   r   r   newzstring[pyarrow_numpy]r   ri   rj   )r
   r   r   r   r   r   r   rC   cutr   strrB   r   rD   r#   rE   )rG   r   Zusing_infer_stringrJ   rH   r[   r   r   r   r    test_to_excel_interval_no_labels  s    

.z0TestExcelWriter.test_to_excel_interval_no_labelsc                 C   s   t tjdjddddtjd}| }tj|d dg dd	}||d
< t	t
||d
< |j|dd t| }tj|ddd}W d    n1 s0    Y  t|| d S )Nr8   r   r   r  r   r   r   )
rU   rV   r   r   EFGHIJ)labelsr  r   ri   rj   )r
   r   r   r   r   r   r   rC   r  ZSeriesr   rB   r   rD   r#   rE   )rG   r   rJ   rH   Z	intervalsr[   r   r   r   r   test_to_excel_interval_labels  s    
.z-TestExcelWriter.test_to_excel_interval_labelsc                 C   s   t tjdjdddddgtjd}| }|d dd	 |d
< |d dd	 |d
< |j|dd t	| }t
j|ddd}W d    n1 s0    Y  t|| d S )Nr8   r   r   r  r   rU   rS   r   c                 S   s
   t | dS )Nseconds)r   r   r   r   r   r   %  rh   z9TestExcelWriter.test_to_excel_timedelta.<locals>.<lambda>r  c                 S   s   t | d d S )Nr  iQ )r   total_secondsr   r   r   r   r   '  rh   r   ri   r   rj   )r
   r   r   r   r   r   r   applyrB   r   rC   rD   r#   rE   )rG   r   rJ   rH   r[   r   r   r   r   test_to_excel_timedelta  s    
.z'TestExcelWriter.test_to_excel_timedeltac                 C   s   t tjddttdtddddd}|d		 
d
}|j|dd t| }tj|ddd}W d    n1 s~0    Y  t||
d
 d S )Nr8   r   r   r   r   rV   r   r   ZMEMZsht1ri   r   rj   )r
   r   r   r   r   r   r   r   ZresamplemeanZ	to_periodrB   r   rC   rD   r#   rE   )rG   r   rJ   r   r[   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 s0    Y  t|| d S )Nr8   r   r   firstsecondr   r   Fr   rU   rV   r   r  r   r5   rj   )r   aranger   r>   r   reshaper   r   rB   r   rC   rD   r#   rE   )rG   r"   r   r   arrays	new_indexr[   rJ   r   r   r   test_to_excel_multiindex>  s    "
2z(TestExcelWriter.test_to_excel_multiindexc                 C   sd   t g dg dtjddd}|ddg}|j||d tj|d	d
gd}t	|| d S )N)Nr8   r2   )r   r     r8   r2   rU   rV   r   rU   rV   r   r   r5   r   )
r
   r   r   r   r   rB   rC   rD   r#   rE   )rG   r"   r   rJ   Zdf1r   r   r   "test_to_excel_multiindex_nan_labelM  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 s0    Y  |s|j	jddd}
dd t|
 D |_	t||	 d S )Nr8   r   r   r'  r(  r   ))(   r5   )r1  r8   )2   r5   )r2  r8   r   r5   r   r  r=   r?   rX   F)ZsparsifyZinclude_namesc                 S   s   g | ]}d  tt|qS )r'   )joinmapr  )rd   qr   r   r   rg   q  rh   zATestExcelWriter.test_to_excel_multiindex_cols.<locals>.<listcomp>)r   r)  r   r>   r   r*  r   r   from_tuplesrS   rB   r   rC   rD   Z_format_multirl   r#   rE   )rG   r"   r   r   r+  r,  Znew_cols_indexr?   r[   rJ   fmr   r   r   test_to_excel_multiindex_cols^  s"    "
$z-TestExcelWriter.test_to_excel_multiindex_colsc                 C   s   t |}ttjddttdtddddd}t	j
|j|tjt|jtjd	gd
dgd|_|j|d|d t|$}tj|dddgd}W d    n1 s0    Y  t|| |jjdksJ d S )Nr8   r   r   r   r   rV   r   r   r   timerN   r   r   r  r   r5   rj   )r:  rN   )r   r
   r   r   r   r   r   r   r   r   r   r>   r   r)  r   r   rB   r   rC   rD   r#   rE   rW   )rG   r"   r   r   r   r[   r   r   r   r   test_to_excel_multiindex_datest  s"    


2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 st0    Y  t	
|| d S )Nr   r  r.  r1  r2  <   )rP   rQ   c)F   P   )Z   r6   r   FrT   ri   )r
   r   r   r7  r>   rB   r   rC   rD   r#   rE   )rG   r   Zframe1r   Zmulti_indexr[   Z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}|j|dd	 t|}tj|dd	}W d    n1 sh0    Y  tj||d
d
d d S )N)r   r5   r8   rR   r   r5   r   r8   r  r   ri   F)Zcheck_index_typeZcheck_dtype)	r
   r   r7  rB   r   rC   rD   r#   rE   )rG   r   rH   rJ   r[   rK   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 s`0    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@̤ArU   rV   rw   ry   r   r  r   %.2fr=   Zfloat_formatr   rj   gQ?gq=
ףp?g=
ףp=?gp=
ף(@rE  rF  )r
   rB   r   rC   rD   r#   rE   )rG   r   rJ   r[   rK   rH   r   r   r   test_to_excel_float_format  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    n1 sp0    Y  d S )N)u   ƒu   Ɠu   Ɣ)u   ƕu   Ɩu   Ɨu   AƒrV   )u   XƓry   r   r  z__tmp_to_excel_float_format__.Z	TestSheetri   r   rj   rA   )rG   r%   rJ   rI   rK   r   r   r   test_to_excel_output_encoding  s    z-TestExcelWriter.test_to_excel_output_encodingc              	   C   s  t d| }z.t|d W d    n1 s20    Y  W n tyZ   td Y n0 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 s0    Y  W d    n1 s0    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 systemrC  rD  rU   rV   rG  r  r   rH  rI  r   rj   rJ  rK  )r#   r$   openUnicodeEncodeErrorr   skipr
   rB   r   rC   rD   rE   )rG   r%   rI   rJ   r[   rK   rH   r   r   r   test_to_excel_unicode_filename  s(    "
L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sPJ dd|d	kr|td
d tD td}	n.tj	fddt|D dd t|D d}	|d	krtdd tD td}
n.tj	fddt|D dd t|D d}
t t
f|	|
d}|d	krbd}tjt|d |||dd W d    n1 sV0    Y  n|||}|r|j| fksJ n|jd	 | fksJ tt|jD ]6}tt|jD ] }|j||f tjusJ qȐqd S )NTr   c                    sT   | j | |d t&}tj||jd |dW  d    S 1 sF0    Y  d S )N)r?   r"   r>   r   r   )rB   r   rC   rD   r   )datar?   Z
parser_hdrr>   r   )r"   r   r   r   	roundtrip  s
    
z;TestExcelWriter.test_excel_010_hemstring.<locals>.roundtrip)r5   r8   )r   r   r   r2   r5   c                 S   s   g | ]}d | qS )za-r   r   r   r   r   rg     rh   z<TestExcelWriter.test_excel_010_hemstring.<locals>.<listcomp>r   c                    s   g | ]}t  qS r   r   r   )ncolsr   r   rg     rh   c                 S   s   g | ]}d | qS zi-r   r   r   r   r   rg     rh   r   c                 S   s   g | ]}d | qS )zb-r   r   r   r   r   rg   	  rh   c                    s   g | ]}t  qS r   r   r   )nrowsr   r   rg     rh   c                 S   s   g | ]}d | qS )zj-r   r   r   r   r   rg     rh   r   z_Writing to Excel with MultiIndex columns and no index \('index'=False\) is not yet implemented.r   Fr   )Tr   T)r
   r   r   r   r   r   r   objectr   r   r   r   r   NotImplementedErrorr   r>   rS   )rG   r"   rU  rT  rS  r   rW  Zparser_headerr   rS   r>   rJ   r   rr=  r   )r"   rX  rZ  r   r   test_excel_010_hemstring  sH    	
0
z(TestExcelWriter.test_excel_010_hemstringc                 C   s  t g dg dg dgg dd}|j|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}|j|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`   )rU   rV   rV   rR   r   ri   )rU   rV   B.1r   rj   )r5   r8   r2   r1   )r      rr      )rU   rV   rU   rV   )rU   rV   A.1r_  Fr<   r   r
   rB   rC   rD   r#   rE   rG   r   rJ   rH   rK   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r5   r5   r5   r8   r8   r8   rU   rV   r   rV   rU   r   r   r   )r
   rB   rC   rD   r#   assert_series_equal)rG   r   write_frame
read_framer   r   r   test_swapped_columnsJ  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 sN0    Y  tjtd
d$ |j|dddgd	 W d    n1 s0    Y  d S )Nrf  rg  rh  zNot all names specifiedr   r   rV   r   r   z.'passes columns are not ALL present dataframe'r   )r
   r   r   KeyErrorrB   )rG   r   rj  r   r   r   test_invalid_columnsT  s    2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 )
Nrf  rg  )r2   r2   r2   r/  Zcol_subset_bugrU   rV   )r=   rS   r>   rj   rc  )rG   r   Zto_excel_indexZread_excel_index_colrj  rH   rk  r   r   r   test_write_subset_columns`  s    	z)TestExcelWriter.test_write_subset_columnsc                 C   st   t g dg dd}|j|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#onerq  twors  z#tworh  test_cri   r   rj   )r5   r   r5   r5   )r8   r5   #r=   commentrX   )r
   rB   rC   rD   r   r#   rE   rG   r   rJ   Zresult1Zresult2r   r   r   test_comment_argu  s    


z TestExcelWriter.test_comment_argc                 C   sR   t g dg dd}|j|dd tj|dd}tj|dd d}t|| d S )Nrp  rr  rh  rt  ri   )r=   rx  rc  ry  r   r   r   test_comment_default  s
    z$TestExcelWriter.test_comment_defaultc                 C   s\   t g dg dd}|j|dd t g dg dd}tj|ddd	d
}t|| d S )Nrp  rr  rh  rt  ri   )rq  Nrq  )rs  NNrv  r   rw  rc  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)rP   rQ   Fr   r5   r8   rv  )rx  rc  rd  r   r   r   test_comment_empty_line  s
    z'TestExcelWriter.test_comment_empty_linec                 C   s  t |}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d  tj|ddd!}|d"| d#}t|d |d  d S )$Ni  r5   r
  r8   r2   -   8   r1      1   r`  *   rr   9   #   r  )   r	  r]            5      %   r      r  4   rU   r   ri   r   r  r  )	r   r   r
   rB   rC   rD   r   r#   ri  )rG   r   r   Z	datetimesrj  rk  rH   r   r   r   test_datetimes  s$    zTestExcelWriter.test_datetimesc              	   C   s   t  }ttjdd}t||d}|| W d    n1 sJ0    Y  |d t	j
|dd}t|| W d    n1 s0    Y  d S )Nr8   r   r)   r   r   )r   r
   r   r   r   r   r   rB   seekrC   rD   r#   rE   )rG   r)   ZbiorJ   rZ   Z	reread_dfr   r   r   test_bytes_io  s    (
zTestExcelWriter.test_bytes_ioc                 C   s   t ddddddg}dddd}tr8d	|d
< d	|d< |d
krTtj|sTd|d
< tjtt	|| d$ |j
||ddid W d    n1 s0    Y  d S )Nr5   r8   rh  r2   r1   zBOpenDocumentSpreadsheet() got an unexpected keyword argument 'foo'z3__init__() got an unexpected keyword argument 'foo')r/   r,   r.   z<Workbook.__init__() got an unexpected keyword argument 'foo'r,   r.   z8load_workbook() got an unexpected keyword argument 'foo'r   rN   rO   )r)   Zengine_kwargs)r
   r   osr   existsr   r   	TypeErrorreescaperB   )rG   r)   r   rJ   Zmsgsr   r   r   test_engine_kwargs  s2    z"TestExcelWriter.test_engine_kwargsc                 C   s|   t dddgdddgg dg dd	}|j|d
d tj|d
ddd}| }|jt|_|j	d|_t
|| d S )NrP   rQ   r=  er8   )ra   f)r5   r8   g      @)applebananaZcherry)mixednumericr  r   ri   r   r3  r   )r
   rB   rC   rD   r   r  r"  r  r  r   r#   rE   rG   r   rJ   readrH   r   r   r   test_write_lists_dict  s    z%TestExcelWriter.test_write_lists_dictc                 C   sH   t ddgddgd}|j|dd tj|ddd	}|}t|| d S )
Nr5   r8   r2   r1   )renderrV  r   ri   r   r   rc  r  r   r   r   test_render_as_column_name  s
    z*TestExcelWriter.test_render_as_column_namec                 C   s   t ddggddgtd}tdd& |ddd	d
}W d    n1 sN0    Y  || tj|dgdgdd}t	|| d S )NrN   rO   col1col2r  zfuture.no_silent_downcastingTF)rN   rO   r   r   )Ztrue_valuesZfalse_valuesrX   )
r
   r[  r   replacer   rB   rC   rD   r#   rE   )rG   r   rJ   rH   rk  r   r   r   !test_true_and_false_value_options  s    4
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 )Nr5   r8   r2   r1   r  r  rR   r   ru  )r=   Zfreeze_panesr   r   rc  )rG   r   rH   rK   r   r   r   test_freeze_panes  s    z!TestExcelWriter.test_freeze_panesc                 C   s~   t dtdd ttdtdd tdD tdd	}t|j	|d
}tt
jdd}tj||d| d}t|| d S )Nr   x   r.  r1   r   c                 S   s   g | ]}d | qS rY  r   r   r   r   r   rg   &  rh   z6TestExcelWriter.test_path_path_lib.<locals>.<listcomp>r.  r   r   r  r   r   rN   r   )r
   r   r)  r*  r   r   r   r[  r   rB   rC   rD   r#   Zround_trip_pathlibrE   rG   r)   r%   rJ   rZ   r[   rK   r   r   r   test_path_path_lib"  s    
z"TestExcelWriter.test_path_path_libc                 C   sz   t dtdd ttdtdd tdD d}t|j|d	}tt	j
d
d}tj||d| d}t|| d S )Nr   r  r  r   c                 S   s   g | ]}d | qS rY  r   r   r   r   r   rg   2  rh   z8TestExcelWriter.test_path_local_path.<locals>.<listcomp>r.  r   r  r   r   rN   r   )r
   r   r)  r*  r   r   r   r   rB   rC   rD   r#   Zround_trip_localpathrE   r  r   r   r   test_path_local_path.  s    
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 )NZ2018Z2018Q1Z2018Q2)r8   r8   r   r   rR   r   r5   r{   c                 S   s   g | ]}t |qS r   )r  r   r   r   r   rg   G  rh   zCTestExcelWriter.test_merged_cell_custom_objects.<locals>.<listcomp>)level)r   r7  rC   ZPeriodr
   r   r   rB   rD   rS   Z
set_levelsZlevelsr#   rE   )rG   r   mirH   rK   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 sN0    Y  | }t|g|d}tjtdd || W d    n1 s0    Y  d S )NZ2019)tzr   zExcel does not supportr   )rC   r   r
   r   r   r   rB   Zto_pydatetime)rG   r   Ztz_aware_fixturer   r  rV  rJ   r   r   r    test_raise_when_saving_timezonesL  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   r5   r   r]   rh  )rU   rV   rU   Fr   )r   r   r   )r5   r]   r5   )rU   rV   rb  rR   rc  )rG   r   rJ   rK   rH   r   r   r   'test_excel_duplicate_columns_with_namesZ  s
    
z7TestExcelWriter.test_excel_duplicate_columns_with_namesc              	   C   sr   d}t |P}tjtt|d t|dd W d    n1 sF0    Y  W d    n1 sd0    Y  d S )Nz7if_sheet_exists is only valid in append mode (mode='a')r   r  )Zif_sheet_exists)r#   r$   r   r   r   r  r  r   )rG   r%   r   r  r   r   r   test_if_sheet_exists_raisesc  s    z+TestExcelWriter.test_if_sheet_exists_raisesc              	   C   s   t |d}t||d}t | W d    n1 s:0    Y  t|}t }t || W d    n1 st0    Y  d S Nr  )r#   r$   r   r
   rB   rC   rD   rE   )rG   r)   r%   r   rZ   rK   rH   r   r   r   test_excel_writer_empty_framek  s    *
z-TestExcelWriter.test_excel_writer_empty_framec                 C   sZ   t |<}t j||d t|}t }t || W d    n1 sL0    Y  d S r  r   )rG   r)   r%   r   rK   rH   r   r   r   test_to_excel_empty_framet  s
    
z)TestExcelWriter.test_to_excel_empty_frame)Er   r   r   r   r   r   r   r   r   r   r   r   r   r   Zint8Zint16Zint32r   r   Zfloat16Zfloat32Zfloat64r   r   r   r   r   r   r  r  r  r  r  r#  r&  r-  r0  r9  r;  rA  rB  rL  rM  rR  r^  re  rl  rn  ro  rz  r{  r|  r  r  r  r  r  r  r  r  r  r  r  r[  r  r  r  r  r  r   r   r   r   r   a  s   1	

	#=/E

 
		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 |n}t|F}|dkr>ttdddr>t|tsLJ nt||sLJ W d    n1 s`0    Y  W d    n1 s~0    Y  d S )Nr+   r.   ignore)errors)r#   r$   r   r   r	   
isinstancer   )rG   klassr%   r   rZ   r   r   r   test_ExcelWriter_dispatch~  s    


z4TestExcelWriterEngineTests.test_ExcelWriter_dispatchc                 C   s:   t jtdd td W d    n1 s,0    Y  d S )Nz	No enginer   Znothing)r   r   r   r   rG   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 d}t|t}t |}t||sLJ W d    n1 s`0    Y  tdgtdgdd	td
gdd	d}|| W d    n1 s0    Y  |	  W d    n1 s0    Y  td}|j|dd W d    n1 s0    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)ZxlsxZxlsr   c                 S   s   d S r   r   r  r   r   r   book  s    zHTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.bookc                 S   s   dt | _d S NT)typecalled_saver  r   r   r   _save  s    zITestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass._savec                 _   s   dt | _d S r  )r  called_write_cells)rG   argskwargsr   r   r   _write_cells  s    zPTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass._write_cellsc                 S   s   dt | _d S 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  Z_supported_extensionsZ_enginer  r  r  propertyrn   classmethodr  r   r   r   r   
DummyClass  s   
r  zio.excel.xlsx.writerr   zsomething.xlsxrP   rQ   rN   )r   r=  rO   r   zsomething.xlsr  )
r   r   r   r#   r$   r  r
   r   rB   r  )rG   r  r   filepathrZ   rJ   r   r   r   test_register_writer  s"    
,(&.z/TestExcelWriterEngineTests.test_register_writerN)r   r   r   r   r   r   r    r   td
skip_if_nor   r  r  r  r   r   r   r   r  }  s   
r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )
TestFSPathc              	   C   s   t dh}tdddgi}|| t|}t|}W d    n1 sN0    Y  ||ksdJ W d    n1 sx0    Y  d S )Nfoo.xlsxrU   r5   r8   )r#   r$   r
   rB   r   r  fspath)rG   r   rJ   r   rK   r   r   r   test_excelfile_fspath  s    

(z TestFSPath.test_excelfile_fspathc              	   C   sl   t dN}t|&}t|t|ks,J W d    n1 s@0    Y  W d    n1 s^0    Y  d S )Nr  )r#   r$   r   r  r  r  )rG   r   rZ   r   r   r   test_excelwriter_fspath  s    
z"TestFSPath.test_excelwriter_fspathc                 C   s`   t dg di}d}tjt|d* t }t|}||d W d    n1 sR0    Y  d S )NrP   r`   zwStarting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.r   ZSheet_name_1)r
   r#   r   r   r   r   rB   )rG   rJ   r   bufrZ   r   r   r   "test_to_excel_pos_args_deprecation  s    z-TestFSPath.test_to_excel_pos_args_deprecationN)r   r   r   r  r  r  r   r   r   r   r    s   r  r  c                 C   s6   dd t tD }dd t | D }||r2J d S )Nc                 S   s   h | ]}| d s|qS r   
startswithrd   r   r   r   r   	<setcomp>  rh   z%test_subclass_attr.<locals>.<setcomp>c                 S   s   h | ]}| d s|qS r  r  r  r   r   r   r    rh   )dirr   symmetric_difference)r  Z
attrs_baseZattrs_klassr   r   r   test_subclass_attr  s    r  )<r   r   r   	functoolsr   ior   r  r  numpyr   r   Zpandas.compatr   Zpandas.compat._constantsr   Zpandas.compat._optionalr	   Zpandas.util._test_decoratorsutilZ_test_decoratorsr  ZpandasrC   r
   r   r   r   r   Zpandas._testingZ_testingr#   Zpandas.io.excelr   r   r   r   r   Zpandas.io.excel._utilr   r   Z
single_cpuZ
pytestmarkr  r   Zfixturer   r"   r   r*   r   r    r  r0   Zusefixturesr   r  r  valuesr  r   r   r   r   <module>   s   



  
        H