o
    _~#gs                     @   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 rtej(j)Z*de+de+f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/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/pandas/tests/io/excel/test_writers.pyget_exp_unit*      r   c                 C   s   | dd S )z?
    Returns the first ten items in fixture "float_frame".
    N
   r   )float_framer   r   r   frame.   s   r   TF)paramsc                 C   s   | j S N)param)requestr   r   r   merge_cells6   s   r$   c                 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_pathr   r   r   r   ;   s   "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_engineD   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:   r7   i,  r:   r6   i  F
sheet_nameindexheaderr   rC   usecolsrE   r
   r%   r&   to_excelpd
read_excelassert_frame_equalselfr'   rE   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|}|j|dddd tj||d	g|d
}W d    n1 s5w   Y  t|| d S )Nwith_headerr9   r=   r@   rA   FTrB   r   rF   rH   rM   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|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>   barr7   bazabcolumnsData_no_headF)rC   rE   rD   Data_with_headrC   rD   AB)rC   rE   names)rC   	index_colrb   )
r
   r%   r&   r   rI   r\   r   rJ   rK   rL   )rN   r'   refdfpthwriterreaderxlsdf_no_head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|D}t|}| D ]\}}|j||d q'W d    n1 s=w   Y  tj||dd}|D ]}	t	||	 ||	  qLW d    d S 1 sdw   Y  d S )	Nc                 S   s"   g dg d}}t ||| gdS )N)      !   r;   r>   r7   r[   )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rr   r   r   
<listcomp>       zKTestRoundTrip.test_creating_and_reading_multiple_sheets.<locals>.<listcomp>rC   r   rC   rc   )
dictzipr%   r&   r   itemsrI   rJ   rK   rL   )
rN   r'   sheetsdfsre   ew	sheetnamerQ   dfs_returnedrw   r   rx   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;   r7      )OnexTwoXr   Y)Zeror:   )r   r   r   )r   zUnnamed: 4_level_1rE   rc   ))Begr:   Middler   Tailr   r   r   ))r   zUnnamed: 1_level_1r   r   r   r%   r&   r
   rI   rJ   rK   rL   )rN   r'   r   rQ   rO   actualr   r   r   &test_read_excel_multiindex_empty_level   sH   	
		
	"z4TestRoundTrip.test_read_excel_multiindex_empty_levelc_idx_namesrY   r_idx_namesrZ   c_idx_levelsr;   r_idx_levelsc                    s  t |}tp|dk}|dkrttd}	ntjdd t|D  fddt|D d}	|dkr;t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    d S 1 sw   Y  d S )Nr;   abcdec                 S      g | ]}t d qS    rangerv   _r   r   r   ry      rz   z@TestRoundTrip.test_excel_multindex_roundtrip.<locals>.<listcomp>c                       g | ]	}  d | qS -r   rv   rq   )r   r   r   ry          rb   ghijkc                 S   r   r   r   r   r   r   r   ry      rz   c                    r   r   r   r   )r   r   r   ry      r   皙?)r   r   r\   rD   )rc   rE   )check_namesr   )r%   r&   boolr   listr   from_arraysr   r
   nponesrI   rJ   rK   rL   naniloc)rN   r'   r   r   r   r   r#   re   r   r\   rD   rQ   actr   )r   r   r   test_excel_multindex_roundtrip   sV   








"z,TestRoundTrip.test_excel_multindex_roundtripc              	   C   s   t g dtdddd}| }|d jd|d< t|f}|| 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 scw   Y  t
|| tj	|dgddd}t
|| W d    d S 1 sw   Y  d S )Nrn   z
2012-01-01r7   )periods)coldate_stringsr   %m/%d/%Yr   rc   )parse_datesrc   c                 S   s   t | dS )Nr   )r   strptimer   r   r   r   <lambda>0  s    z;TestRoundTrip.test_read_excel_parse_dates.<locals>.<lambda>zuse 'date_format' insteadF)matchraise_on_extra_warnings)r   date_parserrc   )r   date_formatrc   )r
   r   copydtstrftimer%   r&   rI   rJ   rK   rL   assert_produces_warningFutureWarning)rN   r'   rQ   df2re   resr   r   r   r   test_read_excel_parse_dates  s<   

"z)TestRoundTrip.test_read_excel_parse_datesc                 C   s   t tdtjtddddg}ttd|d}t|}|	| tj
|ddgd}W d    n1 s8w   Y  ttdt tdg d	g}t|| d S )
Nr6   z
2020-01-016ME)startr   freqrD   r   r;   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   rJ   interval_range	Timestampr
   r%   r&   rI   rK   rL   )rN   r'   midxrQ   re   rR   rO   r   r   r   "test_multiindex_interval_datetimesB  s*   
z0TestRoundTrip.test_multiindex_interval_datetimes)__name__
__module____qualname__pytestmarkparametrizer
   r   r   rS   rU   rj   r   r   r   r   r   r   r   r   r   r5   S   s*    *
,
/8#r5   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 s5w   Y  tjt|d || W d    d S 1 sRw   Y  d S )Ni  i@  r;   )shapezsheet is too larger   )r   zerosr
   r   raises
ValueErrorrI   )	rN   r   breaking_row_countbreaking_col_countrow_arrcol_arrrow_df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 s'w   Y  t	
|| d}tjt|d t|d W d    d S 1 sMw   Y  d S )Nr>   r   r>   r   r|   zWorksheet named '0' not foundr   0)r
   r   randomdefault_rngstandard_normalrI   r   rJ   rK   r%   rL   r   r   r   )rN   r   gtxlrQ   r   r   r   r   test_excel_sheet_by_name_raise  s   

"z.TestExcelWriter.test_excel_sheet_by_name_raisec                 C   s   t |#}|j|dd | }|jd d d |_|j|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 s[w   Y  d S )NData1r{   r   Data2r   r|   )	r   rI   r   r\   r   rJ   rK   r%   rL   )rN   r   r   rf   frame2rg   found_df	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   r`   test1r{   ra   rC   r\   FrC   rE   r_   r   r|   NA)rC   na_rep)rC   rc   	na_values88X   g      V@Sheet1r   r   )r   r   r   r   r\   get_locrI   rJ   rK   r%   rL   rD   to_frame)rN   r   r   reconsrw   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 s&w   Y  t|| d S )NrW   rV   r   r{   r   r|   )r   rI   r   rJ   rK   r%   rL   )rN   r   r   mixed_framerg   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 sTw   Y  t|| d S )Nr>   r   r6   ABCD
2000-01-01r   ra   r   r   r   r   r   r{   r   r|   )r   r
   r   r   r   r   r   r   r   rJ   DatetimeIndexasarrayrD   as_unitrI   r   rK   r%   rL   )rN   r   unitrQ   rD   rO   rg   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   r`   r   r{   ra   r   Fr   r_   )r   r   r   r   r\   r  rI   )rN   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.w   Y  |	tj
}t|| tj|dd	d
}t|| d S )Nr>   r   r   sizedtyper   r{   r   r|   )r
   r   r   r   integersrI   r   rJ   rK   astypeint64r%   rL   )rN   r  r   rQ   rg   r  	int_frame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.w   Y  t	
|| d S )Nr>   r   r  r   r{   r   r|   )r
   r   r   r   rI   r   rJ   rK   r  r%   rL   )rN   r  r   rQ   rg   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 s+w   Y  t	|| d S )N)r;   r   TFr  r   r{   r   r|   )
r
   r   bool_rI   r   rJ   rK   r  r%   rL   rN   r   rQ   rg   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 s,w   Y  t|| d S )Nr;   )r>   r7   r   r   r{   r   r|   )	r
   r   infrI   r   rJ   rK   r%   rL   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 sw   Y  t|}t	j|ddd}	t||	 t	j|ddd}	W d    n1 sw   Y  t||	 dt|jksJ d|jd ksJ d|jd ksJ d S )Nr>   r  r	  r
  r   ra   r  r   r  r`   r   r{   r   Fr   r_   test2r   r|   r;   )r   r
   r   r   r   r   r   r   r   rJ   r  r  rD   r  r   r   r   r\   r  rI   r   r   rK   r%   rL   lensheet_names)
rN   r   r   r  tsframerD   rO   rf   rg   r  r   r   r   test_sheets.  s:   


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 sXw   Y  |  }||_t|| d S )Nr   r`   r   r{   ra   r   Fr   r_   )AAr   r   Zr   r|   )r   r   r   r   r\   r  rI   r   r   rJ   rK   r%   rL   )rN   r   r   col_aliasesrg   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 sew   Y  dg|j_|jj|jjksyJ 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 s5w   Y  t|| d S )Nr   r`   r   r{   ra   r   Fr   r_   r>   r   r   test)rC   index_labelr$   r|   )r0  dummydummy2)r`   ra   CD)rC   r\   rD   r$   r;   )r   r   r   r   r\   r  rI   r
   r   r   r   r   rJ   rK   r  r  rD   rb   r%   rL   r   	set_index)rN   r$   r   r   rQ   rg   r  r   r   r   test_roundtrip_indexlabelsc  sn   







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 s0w   Y  t|| |jjdksCJ d S )Nr>   )r   r6   rV   r$   r   r|   )r
   r   r   r   r   rD   namerI   r   rJ   rK   r'  r%   rL   )rN   r$   r   rQ   xfrR   r   r   r   test_excel_roundtrip_indexname  s   
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 sUw   Y  |d d  }	|	j||	_t|	| d S )Nr>   r  r	  r
  r   ra   r  r   r  c                 S   s   g | ]}|  qS r   )r   )rv   r   r   r   r   ry     rz   zATestExcelWriter.test_excel_roundtrip_datetime.<locals>.<listcomp>r   rC   r$   r   r|   )r   r
   r   r   r   r   r   r   r   rJ   r  r  rD   r   rI   r   rK   r  r%   rL   )
rN   r$   r   r  r(  rD   tsfrg   r  rO   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|y}t|}|j|dd W d    n1 sww   Y  t|ddd}|j|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         rm   r6   r>         DATEDATETIMEr   r   rD   r\   M8[]r   r{   z
DD.MM.YYYYzDD.MM.YYYY HH-MM-SS)r   datetime_formatr   r|   )r   r
   r   r   r  r%   r&   r   rI   r   rJ   rK   rL   )rN   r'   r   r  rQ   df_expected	filename2writer1writer2reader1rs1reader2rs2r   r   r   test_excel_date_datetime_format  sL   ""


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	|s+t
nd	|d< |j|d
d t|}tj|d
dd}W d    n1 sNw   Y  t|| d S )Nr>   r  r      r;   r  r  r   newzstring[pyarrow_numpy]r   r{   r|   )r
   r   r   r   r  r  r   rJ   cutr  strrI   r   rK   r%   rL   )rN   r   using_infer_stringrQ   rO   rg   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 sLw   Y  t|| d S )Nr>   r  r   rU  r  r  r   )
r`   ra   r4  r5  EFGHIJ)labelsrW  r   r{   r|   )r
   r   r   r   r  r  r   rJ   rX  Seriesr   rI   r   rK   r%   rL   )rN   r   rQ   rO   	intervalsrg   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 sKw   Y  t|| d S )Nr>   r  r   rU  r  r`   r\   r  c                 S   s
   t | dS )Nseconds)r   r   r   r   r   r   %  s   
 z9TestExcelWriter.test_to_excel_timedelta.<locals>.<lambda>rW  c                 S   s   t | d d S )Nrg  iQ )r   total_secondsr   r   r   r   r   '  s    r   r{   r   r|   )r
   r   r   r   r  r  r   applyrI   r   rJ   rK   r%   rL   )rN   r   rQ   rO   rg   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?w   Y  t||
d
 d S )Nr>   r  r	  r
  r   ra   r  r   MEMsht1r{   r   r|   )r
   r   r   r   r   r   r   r   resamplemean	to_periodrI   r   rJ   rK   r%   rL   )rN   r   rQ   r.  rg   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secondr   r   Fr   r`   ra   r   r<  r   r;   r|   )r   aranger&  rD   r  reshaper   r   rI   r   rJ   rK   r%   rL   )rN   r$   r   r   arrays	new_indexrg   rQ   r   r   r   test_to_excel_multiindex>  s   "
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)Nr>   r7   )r   rV     r>   r7   r`   ra   r4  r`   ra   r8  r   r;   r   )
r
   r   r   r   r6  rI   rJ   rK   r%   rL   )rN   r$   r   rQ   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 sQw   Y  |sj|j	jddd}
dd t|
 D |_	t||	 d S )Nr>   r  r   rs  rt  r   ))(   r;   )r~  r>   )2   r;   )r  r>   r   r;   r   r<  rC   rE   rc   F)sparsifyinclude_namesc                 S   s   g | ]
}d  tt|qS )r)   )joinmaprY  )rv   qr   r   r   ry   q  s    zATestExcelWriter.test_to_excel_multiindex_cols.<locals>.<listcomp>)r   ru  r&  rD   r  rv  r   r   from_tuplesr\   rI   r   rJ   rK   _format_multir~   r%   rL   )rN   r$   r   r   rw  rx  new_cols_indexrE   rg   rQ   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 sUw   Y  t|| |jjdkshJ d S )Nr>   r  r	  r
  r   ra   r  r   r  timerV   r   r   r<  r   r;   r|   )r  rV   )r   r
   r   r   r   r   r   r   r   r   r   rD   r  ru  r&  r  rI   r   rJ   rK   r%   rL   rb   )rN   r$   r   r  r(  rg   r  r   r   r   test_to_excel_multiindex_datest  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   rV  rz  r~  r  <   )rY   rZ   c)F   P   )Z   r<   r   Fr_   r{   )r
   r   r   r  rD   rI   r   rJ   rK   r%   rL   )rN   r   frame1r   multi_indexrg   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 s4w   Y  tj||d
d
d d S )N)r   r;   r>   r[   r   r;   r   r>   rH  r   r{   F)check_index_typecheck_dtype)	r
   r   r  rI   r   rJ   rK   r%   rL   )rN   r   rO   rQ   rg   rR   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@̤Ar`   ra   r   r   r+  rH  r   %.2frC   float_formatr   r|   gQ?gq=
ףp?g=
ףp=?gp=
ף(@r  r  )r
   rI   r   rJ   rK   r%   rL   )rN   r   rQ   rg   rR   rO   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    d S 1 s9w   Y  d S )N)u   ƒu   Ɠu   Ɣ)u   ƕu   Ɩu   Ɨu   Aƒra   )u   XƓr   r+  rH  z__tmp_to_excel_float_format__.	TestSheetr{   r   r|   rH   )rN   r'   rQ   rP   rR   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 systemr  r  r`   ra   r  rH  r   r  r  r   r|   r  r  )r%   r&   openUnicodeEncodeErrorr   skipr
   rI   r   rJ   rK   rL   )rN   r'   rP   rQ   rg   rR   rO   r   r   r   test_to_excel_unicode_filename  s4   
z.TestExcelWriter.test_to_excel_unicode_filenameuse_headersTFr_idx_nlevelsrn   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|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rgt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rd}tjt|d |||dd W d    d S 1 sw   Y  d S |||}|r|j| fksJ n|jd	 | fksJ 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)rE   r$   rD   r   r   )rI   r   rJ   rK   r'  )datarE   
parser_hdrrD   r:  )r$   r   r   r   	roundtrip  s   
$z;TestExcelWriter.test_excel_010_hemstring.<locals>.roundtrip)r;   r>   )r   r   r   r7   r;   c                 S      g | ]}d | qS )za-r   r   r   r   r   ry         z<TestExcelWriter.test_excel_010_hemstring.<locals>.<listcomp>r  c                       g | ]}t  qS r   r   r   )ncolsr   r   ry     rz   c                 S   r  zi-r   r   r   r   r   ry     r  r   c                 S   r  )zb-r   r   r   r   r   ry   	  r  c                    r  r   r   r   )nrowsr   r   ry     rz   c                 S   r  )zj-r   r   r   r   r   ry     r  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&  rD   r\   )rN   r$   r  r  r  r   r  parser_headerr   r\   rD   rQ   r   rr  r   )r$   r  r  r   r   test_excel_010_hemstring  sN   	"
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 )Nrn   )r`   ra   ra   r[   r   r{   )r`   ra   B.1r   r|   )r;   r>   r7   r6   )r      r      )r`   ra   r`   ra   )r`   ra   A.1r  FrB   r   r
   rI   rJ   rK   r%   rL   rN   r   rQ   rO   rR   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>   r`   ra   r   ra   r`   r   r   r   )r
   rI   rJ   rK   r%   assert_series_equal)rN   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 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   ra   r4  r   z.'passes columns are not ALL present dataframe'r5  )r
   r   r   KeyErrorrI   )rN   r   r  r   r   r   test_invalid_columnsT  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  )r7   r7   r7   r{  col_subset_bugr`   ra   )rC   r\   rD   r|   r  )rN   r   to_excel_indexread_excel_index_colr  rO   r  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#oner  twor  z#twor  test_cr{   r   r|   )r;   r   r;   r;   )r>   r;   #rC   commentrc   )r
   rI   rJ   rK   r   r%   rL   rN   r   rQ   result1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 )Nr  r  r  r  r{   )rC   r  r  r  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 )Nr  r  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)rY   rZ   Fr   r;   r>   r  )r  r  r  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  r;   rE  r>   r7   -   8   r6      1   r  *   r   9   #   r@  )   rD  rk            5      %   r      rV  4   r`   r  r{   r   rI  rJ  )	r   r   r
   rI   rJ   rK   r  r%   r  )rN   r   r  	datetimesr  r  rO   r   r   r   test_datetimes  s$   zTestExcelWriter.test_datetimesc              	   C   s   t  A}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 sGw   Y  d S )Nr>   r   r+   r   r   )r   r
   r   r   r   r   r   rI   seekrJ   rK   r%   rL   )rN   r+   biorQ   rf   	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rd	|d
< d	|d< |d
kr*tj|s*d|d
< tjtt	|| d |j
||ddid W d    d S 1 sLw   Y  d S )Nr;   r>   r  r7   r6   zBOpenDocumentSpreadsheet() got an unexpected keyword argument 'foo'z3__init__() got an unexpected keyword argument 'foo')r4   r/   r3   z<Workbook.__init__() got an unexpected keyword argument 'foo'r/   r3   z8load_workbook() got an unexpected keyword argument 'foo'r   rV   rW   )r+   engine_kwargs)r
   r   osr   existsr   r   	TypeErrorreescaperI   )rN   r+   r   rQ   msgsr   r   r   test_engine_kwargs  s4   "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 )NrY   rZ   r  er>   )rp   f)r;   r>   g      @)applebananacherry)mixednumericrY  r  r{   r   r  r  )r
   rI   rJ   rK   r   r  rj  rY  r  r  r%   rL   rN   r   rQ   readrO   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 )
Nr;   r>   r7   r6   )renderr  r  r{   r   r   r  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 s'w   Y  || tj|dgdgdd}t	|| d S )NrV   rW   col1col2rf  zfuture.no_silent_downcastingTF)rV   rW   r   r   )true_valuesfalse_valuesrc   )
r
   r  r   replacer  rI   rJ   rK   r%   rL   )rN   r   rQ   rO   r  r   r   r   !test_true_and_false_value_options  s   
z1TestExcelWriter.test_true_and_false_value_optionsc                 C   sJ   t ddgddggddgd}|j|dd	d
 tj|dd}t|| d S )Nr;   r>   r7   r6   r  r  r[   r  r  )rC   freeze_panesr   r   r  )rN   r   rO   rR   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   rz  r6   r	  c                 S   r  r  r   r   r   r   r   ry   &  r  z6TestExcelWriter.test_path_path_lib.<locals>.<listcomp>rz  r  r   r  r   r   rV   r   )r
   r   ru  rv  r   r   r   r  r   rI   rJ   rK   r%   round_trip_pathlibrL   rN   r+   r'   rQ   rf   rg   rR   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   r  r  r   r   r   r   r   ry   2  r  z8TestExcelWriter.test_path_local_path.<locals>.<listcomp>rz  r   r  r   r   rV   r   )r
   r   ru  rv  r   r   r   r   rI   rJ   rK   r%   round_trip_localpathrL   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 )N20182018Q12018Q2)r>   r>   r  r  r[   r   r;   r   c                 S   s   g | ]}t |qS r   )rY  r   r   r   r   ry   G  rz   zCTestExcelWriter.test_merged_cell_custom_objects.<locals>.<listcomp>)level)r   r  rJ   Periodr
   r   r   rI   rK   r\   
set_levelslevelsr%   rL   )rN   r   mirO   rR   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   )rJ   r   r
   r   r   r   rI   to_pydatetime)rN   r  tz_aware_fixturer   r'  r  rQ   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   r;   r   rk   r  )r`   ra   r`   Fr   )r   r   r   )r;   rk   r;   )r`   ra   r  r[   r  )rN   r   rQ   rR   rO   r   r   r   'test_excel_duplicate_columns_with_namesZ  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   r  r  r   )rN   r'   r   r  r   r   r   test_if_sheet_exists_raisesc  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
   rI   rJ   rK   rL   )rN   r+   r'   r   rf   rR   rO   r   r   r   test_excel_writer_empty_framek  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   )rN   r+   r'   r   rR   rO   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   int8int16int32r  r  float16float32float64r  r"  r$  r)  r/  r7  r;  r>  rT  r[  re  rk  rr  ry  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-  r/  r0  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.   r3   r1   r/   c              	   C   s   t |@}t|#}|dkrttdddrt|tsJ nt||s&J W d    n1 s0w   Y  W d    d S W d    d S 1 sHw   Y  d S )Nr.   r3   ignore)errors)r%   r&   r   r   r	   
isinstancer   )rN   klassr'   r   rf   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   rN   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U d}t|:}t |}t||s&J W d    n1 s0w   Y  tdgtdgdd	td
gdd	d}|| W d    n1 sVw   Y  |	  W d    n1 siw   Y  td}|j|dd W d    n1 sw   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xlsr2  c                 S   s   d S r!   r   r>  r   r   r   book  r   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                 _   rC  rD  )rE  called_write_cells)rN   argskwargsr   r   r   _write_cells  rH  zPTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass._write_cellsc                 S   rC  rD  )rE  called_sheetsr>  r   r   r   r     s   zJTestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.sheetsc                 S   s.   | j sJ | js
J | jrJ d| _ d| _d S )NF)rF  rI  rM  )clsr   r   r   assert_called_and_reset  s
   



z[TestExcelWriterEngineTests.test_register_writer.<locals>.DummyClass.assert_called_and_resetN)r   r   r   rF  rI  rM  _supported_extensions_enginerB  rG  rL  propertyr   classmethodrO  r   r   r   r   
DummyClass  s    
rT  zio.excel.xlsx.writerr2  zsomething.xlsxrY   rZ   rV   )r9  r  rW   r   zsomething.xlsr  )
r   r   r   r%   r&   r:  r
   r   rI   rO  )rN   rT  r   filepathrf   rQ   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?  rV  r   r   r   r   r7  }  s    
r7  c                   @   s$   e Zd Zd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.xlsxr`   r;   r>   )r%   r&   r
   rI   r   r  fspath)rN   r   rQ   r   rR   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 )NrZ  )r%   r&   r   r  r[  rY  )rN   r   rf   r   r   r   test_excelwriter_fspath  s   
"z"TestFSPath.test_excelwriter_fspathc                 C   sb   t dg di}d}tjt|d t }t|}||d W d    d S 1 s*w   Y  d S )NrY   rn   zwStarting with pandas version 3.0 all arguments of to_excel except for the argument 'excel_writer' will be keyword-only.r   Sheet_name_1)r
   r%   r   r   r   r   rI   )rN   rQ   r   bufrf   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   rY    s    rY  r;  c                 C   s6   dd t tD }dd t | D }||rJ d S )Nc                 S      h | ]	}| d s|qS r   
startswithrv   r9  r   r   r   	<setcomp>  r   z%test_subclass_attr.<locals>.<setcomp>c                 S   ra  rb  rc  re  r   r   r   rf    r   )dirr   symmetric_difference)r;  
attrs_baseattrs_klassr   r   r   test_subclass_attr  s   rk  )<r   r   r   	functoolsr   ior   r  r  numpyr   r   pandas.compatr   pandas.compat._constantsr   pandas.compat._optionalr	   pandas.util._test_decoratorsutil_test_decoratorsrW  pandasrJ   r
   r   r   r   r   pandas._testing_testingr%   pandas.io.excelr   r   r   r   r   pandas.io.excel._utilr   r   
single_cpu
pytestmarkrY  r   fixturer   r$   r   r-   r   r"   rX  r5   usefixturesr   r7  rY  valuesrk  r   r   r   r   <module>   s    



  
        H