B
    `f                 @   s  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	m
Z
mZmZ d dlmZ d dlm  m  mZ dZdd Zejdd	gd
dd Zejejd
dd Zejdddgdd Zdd Zdd Zdd Zejde	de didfe	ddgidfgd d! Z!d"d# Z"d$d% Z#ejd&e$ d'd(fe$d)d*d+d,fgd-d. Z%ejd/d0d)gd1d2 Z&ejd3d4d5d6d7gd8d9 Z'ejd:d;d<gd=d> Z(ejd?e	d d@gdAdBgdCdDgdEdFggdGdge dCdHdIdJdK idLfe	dMe dNd@d@e dNdAdAgidMdOdK idPfe	dQej)dRdSgdTdUidQdVdK idWfgdXdY Z*dZd[ Z+d\d] Z,ejd^d@dDgd_d` Z-dadb Z.ejdcdddegdfdg Z/ejdhddidK djfddkdK dlfd dmdK dlfd dndK dlfgdodp Z0ejjddgd0dqdrds Z1ejjdd	gd0dqdtdu Z2dvdw Z3dxdy Z4dzd{ Z5ejd|ej6e7e8e dA9dAe:e;dCdAd}d~gdddfe6e7e8e;dCe:e;dCdAddfgdd Z<dd Z=ejddddddgdd Z>dd Z?ejddddggdd Z@dd ZAdd ZBdd ZCejdd0d)gejdd0d)gejdd0d)gejde
d d@gdfe
d d@gdddfeDdgddggdfejDdgddggddgddfgejde
d d@gdfe
d d@gdddfeDdgddggdfejDdgddggddgddfgdd ZEejdd0d)gejdd0d)gejdd0d)gejde
e ddfe
e ddddfeDddgddgddggdfejDddgddgddggdGddgddfgejde
e ddfe
e ddddfeDddgddgddggdfejDddgddgddggdGddgddfgdd ZFejdd)d gdd ZGejdd)d gejdddgdd ZHejdd0d)gdd ZIddĄ ZJddƄ ZKejdddgdd˄ ZLejdddgddЄ ZMejddddK fdddK fgejdddddgddۄ ZNejdd0d gdd݄ ZOdd߄ ZPejdddddgdd ZQdd ZRejdddddgdd ZSdS )    )datetime)StringION)	DataFrameIndex
MultiIndexoption_contexta  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.c          	   C   sF   d |dg}| dddd|}t|dd}| }W dQ R X | S )	a.  
    Read HTML file from formats data directory.

    Parameters
    ----------
    datapath : pytest fixture
        The datapath fixture injected into a test by pytest.
    name : str
        The name of the HTML file without the suffix.

    Returns
    -------
    str : contents of HTML file.
    .htmlioformatsdatazutf-8)encodingN)joinopenreadrstrip)datapathnamefilenamefilepathfr	    r   S/home/dcms/DCMS/lib/python3.7/site-packages/pandas/tests/io/formats/test_to_html.pyexpected_html   s
    r   mixedempty)paramsc             C   s~   | j dkr\ttjdtddtdd}tj|j	dddf< tj|j	dddf< |S | j d	krzttdd}|S dS )
z8Fixture for a big mixed Dataframe and an empty Dataframer      )AB)indexN   r   r   r   )
paramr   nprandomrandntmZmakeStringIndexarangenanloc)requestdfr   r   r   biggie_df_fixture/   s    

r,   c             C   s   | j S )N)r"   )r*   r   r   r   justify?   s    r-   	col_space   2   c             C   sp   t tjjdd}|j| d}dd |dD }t|dksBtx(|D ] }d|ksXtt| |ksHtqHW d S )	N)      )size)r.   c             S   s   g | ]}t d |r|qS )z<th[>\s])research).0xr   r   r   
<listcomp>J   s    z/test_to_html_with_col_space.<locals>.<listcomp>z\nr   z	min-width)r   r#   r$   to_htmlsplitlenAssertionErrorstr)r.   r+   resulthdrshr   r   r   test_to_html_with_col_spaceD   s    
rA   c           	   C   s   t tjjdddddgd} d}tjt|d | jd	d
gd W d Q R X tjt|d | jd	d
ddgd W d Q R X d}tjt|d | jddddd W d Q R X d S )N)r2   r2   )r3   abc)columnszGCol_space length\(\d+\) should match DataFrame number of columns\(\d+\))matchr/   (   )r.   r0   <   zunknown columnfoo   "   )rB   rC   d)r   r#   r$   pytestraises
ValueErrorr9   )r+   msgr   r   r   2test_to_html_with_column_specific_col_space_raisesQ   s    rQ   c              C   s   t tjjdddddgd} | jddd	d
}dd |dD }d|d ksRtd|d ksbtd|d ksrt| jdddgd
}dd |dD }d|d kstd|d kstd|d kstd S )N)r2   r2   )r3   rB   rC   rD   )rE   Z2emrJ   )rB   rC   )r.   c             S   s   g | ]}t d |r|qS )z<th[>\s])r4   r5   )r6   r7   r   r   r   r8   g   s    z?test_to_html_with_column_specific_col_space.<locals>.<listcomp>
zmin-width: 2em;">a</th>r1   zmin-width: 23px;">b</th>   z
<th>c</th>r2   Z1emc             S   s   g | ]}t d |r|qS )z<th[>\s])r4   r5   )r6   r7   r   r   r   r8   m   s    zmin-width: 1em;">a</th>zmin-width: 2px;">b</th>zmin-width: 3px;">c</th>)r   r#   r$   r9   r:   r<   )r+   r>   r?   r   r   r   +test_to_html_with_column_specific_col_spacec   s    rT   c              C   sB   ddgddgddgd} t | ddg}| }d	|ks>td S )
NrB   rC    r1   rS   )c1c2r   rV   rW   Zrowspan)r   Z	set_indexr9   r<   )r   r+   r>   r   r   r   $test_to_html_with_empty_string_labels   s    rX   zdf,expectedu   σg      $@Z	unicode_1r   Z	unicode_2c             C   s"   t ||}|  }||kstd S )N)r   r9   r<   )r+   expectedr   r>   r   r   r   test_to_html_unicode{   s    
rZ   c          	   C   sL   |d }| j |dd tt|ddd}|   | ks>tW d Q R X d S )Nz	test.htmlgbk)r   r)r9   r   r=   r   r<   )float_frameZtmp_pathpathr   r   r   r   test_to_html_encoding   s    r_   c             C   s8   t ddddgi}|jdd}t| d}||ks4td S )Nr   g      @g@g@,)decimalZgh12031_expected_output)r   r9   r   r<   )r   r+   r>   rY   r   r   r   test_to_html_decimal   s    
rb   zkwargs,string,expectedz<type 'str'>escapedF)escapez<b>bold</b>Zescape_disabledc             C   sL   d}d}||||i||||id}t |jf | }t||}||ksHtd S )Nzstr<ing1 &amp;zstri>ng2 &amp;)zco<l1zco>l2)r   r9   r   r<   )kwargsstringrY   r   rB   rC   Z	test_dictr>   r   r   r   test_to_html_escaped   s    
rg   index_is_namedTc             C   s|   t tdtddtddtddd}tddgdd	gg|_| rVt|jjd
d|_|jdd}t	|d}||ksxt
d S )NrS   r2         )rB   rC   rD   rL   rB   rC   rD   rL   idx)r   F)r    Zgh8452_expected_output)r   ranger   from_productrE   r   r    valuesr9   r   r<   )rh   r   r+   r>   rY   r   r   r   #test_to_html_multiindex_index_false   s    &
ro   zmulti_sparse,expected)FZ(multiindex_sparsify_false_multi_sparse_1)FZ(multiindex_sparsify_false_multi_sparse_2)TZmultiindex_sparsify_1)TZmultiindex_sparsify_2c          	   C   s   t jddddgddddggdd gd}tddgddgddgd	d
gg|d}|drd|d d d |_td|  | }W d Q R X t||}||kstd S )Nr   r1   rI   )namesrS   r2      ri      rj   )r    2zdisplay.multi_sparse)	r   Zfrom_arraysr   endswithrE   r   r9   r   r<   )Zmulti_sparserY   r   r    r+   r>   r   r   r    test_to_html_multiindex_sparsify   s    
&$

ru   zmax_rows,expected)rH   Zgh14882_expected_output_1)8   Zgh14882_expected_output_2c          
   C   sr   t jdddgdddgddd	d
dddggdddgd}tdtt|i|d}|j| d}t||}||ksntd S )Nd   r   i,  
   r!   r/   r1   rS   r2   rq   ri   rr   rj   rB   rC   rD   )rp   n)r    )max_rows)r   rm   r   rl   r;   r9   r   r<   )rz   rY   r   r    r+   r>   r   r   r   )test_to_html_multiindex_odd_even_truncate   s    
0
r{   zdf,formatters,expectedr1   rS   r2   rq   ri   rr   rj   rI   )rE   r    	__index__c             C   s   d|  S )Nabcdr   )r7   r   r   r   <lambda>       r~   Zindex_formattermonthsi  c             C   s
   |  dS )Nz%Y-%m)strftime)r7   r   r   r   r~      r   Zdatetime64_monthformatterZhodz10:10:10.100z12:12:12.120z%H:%M:%S.%f)formatc             C   s
   |  dS )Nz%H:%M)r   )r7   r   r   r   r~      r   Zdatetime64_hourformatterc             C   s&   t ||}| j|d}||ks"td S )N)
formatters)r   r9   r<   )r+   r   rY   r   r>   r   r   r   test_to_html_formatters   s    
r   c              C   sP   t dddddgdddddgtjdtjdd} | jdgdgd	  d S )
NrB   rC   Z1eru   2èmeri   )u   clé1u   clé2u	   données1u	   données2u   clé1u   clé2)r    rE   )r   r#   r$   r%   Zpivot_table_repr_html_)r+   r   r   r   test_to_html_regression_GH6098  s    
r   c             C   sH   t jdddd}t|tdd}|jddd}t| d	}||ksDtd S )
NZ20010101Dr!   )startfreqZperiods)r    rE      rq   )rz   max_colstruncate)pdZ
date_ranger   rl   r9   r   r<   )r   r    r+   r>   rY   r   r   r   test_to_html_truncate  s
    
r   r3   c          	   C   sR   t dddgd}d}tjtt|| d |jdjg|  d W d Q R X d S )	NrB   rC   rD   )rE   zAFormatters length({}) should match DataFrame number of columns(3))rF   z{})r   )r   rM   rN   rO   r4   rd   r   r9   )r3   r+   rP   r   r   r   'test_html_invalid_formatters_arg_raises  s    r   c             C   sx   ddddddddd	dd
dddddddddg}t |}dd }||d d g}|j|dd}t| d}||ksttd S )Nr1   rS   r2   rq   )r   r   Cr   ri   rr   rj   r   	   rx                     c             S   s   t | d S )NZ_mod)r=   )r7   r   r   r   r~   +  r   z1test_to_html_truncate_formatter.<locals>.<lambda>)r   r   Ztruncate_formatter)r   r9   r   r<   )r   r   r+   fmtr   r>   rY   r   r   r   test_to_html_truncate_formatter!  s    
r   zsparsify,expected)TZtruncate_multi_index)FZtruncate_multi_index_sparse_offc          	   C   s^   ddddddddgddddddddgg}t ||d}|jdd| d	}t||}||ksZtd S )
NbarbazrI   Zquxonetwo)r    rE   rj   )rz   r   sparsify)r   r9   r   r<   )r   rY   r   Zarraysr+   r>   r   r   r   !test_to_html_truncate_multi_index2  s    
r   zoption,result,expectedc             C   s   |   S )N)r9   )r+   r   r   r   r~   D  r   1c             C   s   | j ddS )Nr   )Zborder)r9   )r+   r   r   r   r~   E  r   0c             C   s   |   S )N)r9   )r+   r   r   r   r~   F  r   c             C   s   |   S )N)r   )r+   r   r   r   r~   G  r   c          	   C   s\   t dddgi}| d kr"||}ntd|  ||}W d Q R X d| d}||ksXtd S )Nr   r1   rS   zdisplay.html.borderzborder="")r   r   r<   )optionr>   rY   r+   r   r   r   test_to_html_borderA  s    

r   )Zindirectc             C   s   | }|  }t }|j |d}|d ks*t| |ks:tt|tsHt|j ddgdd |j ddgddd id |j ddgtd	 |j ddgd
td d S )N)bufr   r      )rE   r.   c             S   s   | dS )Nz.1fr   )r7   r   r   r   r~   c  r   ztest_to_html.<locals>.<lambda>)rE   r   )rE   float_formatr   )rE   r.   r   )r9   r   r<   getvalue
isinstancer=   )r,   r+   sr   retvalr   r   r   test_to_htmlU  s    r   c             C   s   | }|   d S )N)r9   )r,   r+   r   r   r   test_to_html_empty_dataframei  s    r   c             C   s8   | }|  }|d}| | | }||ks4td S )Nz	test.html)r9   r   r   r<   )r,   Ztmpdirr+   rY   r^   r>   r   r   r   test_to_html_filenameo  s    

r   c              C   s>   t dtjdi} | jdd}||d }d|ks:td S )Nr7   ri   F)Z	bold_rowsz</thead>z<strong)r   r#   r$   r%   r9   findr<   )r+   r	   r>   r   r   r   test_to_html_with_no_boldx  s    r   c             C   s   | j dgd}d|kstd S )Nr   )rE   z
<th>B</th>)r9   r<   )r]   r>   r   r   r   test_to_html_columns_arg  s    r   zcolumns,justify,expectedZCL0ZCL1)rp   leftZmultiindex_1rightZmultiindex_2c             C   s>   t tdtdg| d}|j|d}t||}||ks:td S )Nr}   Zefgh)rE   )r-   )r   listr9   r   r<   )rE   r-   rY   r   r+   r>   r   r   r   test_to_html_multiindex  s    
r   c             C   sZ   t dddgdddgdddgdd	d
dgd}|j| d}t|dj| d}||ksVtd S )Nrr   i0u  rS   r1   ip ih r   )r   r   r   r   r   r   )rE   )r-   r-   )r   r9   r   r   r<   )r-   r   r+   r>   rY   r   r   r   test_to_html_justify  s    r   zsuper-rightz
small-leftZ	noinheritZtinypandasc          	   C   s4   t  }d}tjt|d |j| d W d Q R X d S )Nz#Invalid value for justify parameter)rF   )r-   )r   rM   rN   rO   r9   )r-   r+   rP   r   r   r   test_to_html_invalid_justify  s    r   c             C   s  dddg}t dddgddd	gd
dtjgddddg|d}t| d}| |ksTtt| d}|jdd}x|D ]}||ksptqpW ||ksttdddgdd|_t| d}| |kst|jdd|kstdddg}t	||_t| d}| |kst|jdd}xdD ]}||kstqW ||ks<ttj	|ddgd|_t| d }| |kslt|jdd|kstd S )!NrI   r   r   r1   rS   r2   g333333?g333333@gffffff@r   r   )r   r   r   r   r   r   )rE   r    Zindex_1Zindex_2F)r    rk   )r   Zindex_3)rI   car)rI   bike)r   r   Zindex_4)rI   r   r   r   Zidx1Zidx2)rp   Zindex_5)
r   r#   r(   r   r9   r<   r   r    r   from_tuples)r   r    r+   Zexpected_with_indexZexpected_without_indexr>   iZtuplesr   r   r   test_to_html_index  s8    








r   classeszsortable draggableZsortableZ	draggablec             C   s,   t  }t|d}|j| d}||ks(td S )NZwith_classes)r   )r   r   r9   r<   )r   r   r+   rY   r>   r   r   r   test_to_html_with_classes  s    
r   c             C   s<   t dddddgi}|jddd}t| d}||ks8td S )	Nr   r1   rS   r2   rq   F)r    rz   Zgh14998_expected_output)r   r9   r   r<   )r   r+   r>   rY   r   r   r   test_to_html_no_index_max_rows  s    
r   c             C   s   t dddgdddggddd	gddd	ggd
dgd}t dgdddggdddgddd	ggd dgd}tdtjtjgtjdtjgtjtjdgg}t|||}|jd	d}t| d}||kstd S )NbaZbbZbccacbccr   r1   rS   rC   rD   )levelscodesrp   rL   ZaaabacrB   g      ?g       @g      @)r   Zgh6131_expected_output)r   r#   arrayr(   r   r9   r   r<   )r   r    rE   r   r+   r>   rY   r   r   r    test_to_html_multiindex_max_cols  s    *
r   c             C   s   t tdtddtddtddd}tddgddgg|_tddgdddd	d
gg|_|jdd}t| d}||kstd S )Nrx   r!   )rB   rC   rD   rL   rB   rC   rD   rL   er   gF)r    Zgh22579_expected_output)	r   rl   r   rm   rE   r    r9   r   r<   )r   r+   r>   rY   r   r   r   &test_to_html_multi_indexes_index_false  s    &
r   index_namesheaderr    zcolumn_index, column_typeZunnamed_standardzcolumns.name)r   Znamed_standardrB   rC   rD   Zunnamed_multizcolumns.name.0zcolumns.name.1Znamed_multizrow_index, row_typez
index.namezindex.name.0zindex.name.1c             C   s   t tjdtd||d}|j|||d}	|s2d}n|sH|drHd| }|sRd}n|sh|drhd| }d| d	 | }
t| |
}|	|kstd S )
N)rS   rS   )Zdtype)r    rE   )r    r   r   nonenamedunZindex_	_columns_)r   r#   zerosintr9   
startswithr   r<   )r   	row_indexrow_typecolumn_indexcolumn_typer    r   r   r+   r>   r   rY   r   r   r   test_to_html_basic_alignment  s    #
r   r   rL   r   r   r   c             C   s   t tddd||d}|jdd|||d}	|s:d}n|sP|drPd| }|sZd}n|sp|drpd| }d	| d
 | }
t| |
}|	|kstd S )N@   r   )r    rE   rq   )rz   r   r    r   r   r   r   r   Ztrunc_df_index_r   )r   r#   r'   Zreshaper9   r   r   r<   )r   r   r   r   r   r    r   r   r+   r>   r   rY   r   r   r   &test_to_html_alignment_with_truncation@  s    )
r   c             C   sR   ddgddgddgddgd	d
gg}t |}|jd|d}t| d}||ksNtd S )Ng"9?g~,?gAGZQ?g&OY@gu!V?g5#Eg8N
g?ga_ÿg4iSulgL1AG?rq   )rz   r    Zgh15019_expected_output)r   r9   r   r<   )r   r    r   r+   r>   rY   r   r   r   ,test_to_html_truncation_index_false_max_rows}  s    

r   z col_index_named, expected_output)FZgh22783_expected_output)TZgh22783_named_columns_indexc             C   s`   dddddgdddd	d
gg}t |}|r8|jjddd |jd|d}t| |}||ks\td S )Ng"9?g~,?gAGZQ?g&OY@gu!V?g5#Eg8N
g?ga_ÿg4iSulgL1AG?zcolumns.nameT)Zinplacerq   )r   r    )r   rE   renamer9   r   r<   )r   r    Zcol_index_namedZexpected_outputr   r+   r>   rY   r   r   r   ,test_to_html_truncation_index_false_max_cols  s    

r   notebookc             C   sp   t ddddgi}|j| d}| rHd|ks.td|ks:td|ksltn$d|ksTtd|ks`td|ksltd S )	Nr   r1   rS   r2   )r   ztbody tr th:only-of-typezvertical-align: middle;zthead th)r   r9   r<   )r   r+   r>   r   r   r   test_to_html_notebook_has_style  s    r   c              C   s<   t dddgitddgddd} | jd	d
}d|ks8td S )Nr   r1   rS   rB   rC   myindexname)r   )r    F)r   )r   r   r9   r<   )r+   r>   r   r   r   #test_to_html_with_index_names_false  s     r   c              C   s>   t dddgitddgddd} | jd	d
d}d|ks:td S )Nr   r1   rS   rB   rC   r   )r   )r    FZTEST_ID)r   Ztable_idz id="TEST_ID")r   r   r9   r<   )r+   r>   r   r   r   test_to_html_with_id  s     r   zvalue,float_format,expected)gvöE?z%.3fZgh21625_expected_output)g      Y@z%.0fZgh22270_expected_outputc             C   s4   t d| gi}t||}|j|d}||ks0td S )Nr7   )r   )r   r   r9   r<   )valuer   rY   r   r+   r>   r   r   r   (test_to_html_float_format_no_fixed_width  s    	
r   zrender_links,expected)TZrender_links_true)FZrender_links_falsec             C   sL   dddgdddgg}t |ddd gd}|j| d}t||}||ksHtd S )	Nr   z$https://pandas.pydata.org/?q1=a&q2=bz
pydata.orgzwww.pydata.orgrI   r   )rE   )render_links)r   r9   r   r<   )r   rY   r   r   r+   r>   r   r   r   test_to_html_render_links  s    
r   zmethod,expectedr9   c             C   s   t S )N)lorem_ipsum)r7   r   r   r   r~     r   r   c             C   s   t d | d  d S )Nrq   z...)r   )r7   r   r   r   r~     r   max_colwidthrx   r!   rw   c          	   C   sF   t tg}td| t||  }W d Q R X ||}||ksBtd S )Nzdisplay.max_colwidth)r   r   r   r   getattrr<   )methodrY   r   r+   r>   r   r   r    test_ignore_display_max_colwidth  s
    

r   c          	   C   s4   t  }d}tjt|d |j| d W d Q R X d S )Nz(classes must be a string, list, or tuple)rF   )r   )r   rM   rN   	TypeErrorr9   )r   r+   rP   r   r   r   !test_to_html_invalid_classes_type  s    r   c           	   C   s\   t dgdgd} tdd | jdd}| jdd}W d Q R X d	|ksLtd
|ksXtd S )Nr1   g^)?)rE   zdisplay.precisionr2   F)r   Tz0.55555z0.556)r   r   r   r9   r<   )r+   r	   r   r   r   r   !test_to_html_round_column_headers  s    r   unitZ100pxz10%Z5em   c             C   s   t tjjdd}|j| d}|dd }dd |dD }t| trVt| d	 } x$|D ]}d
|  d}||ks\tq\W d S )N)r1   r2   )r3   )r.   tbodyr   c             S   s   g | ]}t d |r|qS )z<th[>\s])r4   r5   )r6   r7   r   r   r   r8   
  s    z5test_to_html_with_col_space_units.<locals>.<listcomp>rR   Zpxz<th style="min-width: z;">)	r   r#   r$   r9   r:   r   r   r=   r<   )r   r+   r>   r?   r@   rY   r   r   r   !test_to_html_with_col_space_units  s    

r   c             C   sd   t dtdi}| }t| d}||ks0tt dtdi}| }t| d}||ks`td S )NrB   r!   Z(html_repr_min_rows_default_no_truncation=   Z$html_repr_min_rows_default_truncated)r   r   rl   r   r   r<   )r   r+   r>   rY   r   r   r   test_html_repr_min_rows_default  s    

r   zmax_rows,min_rows,expected)rx   rq   Z html_repr_max_rows_10_min_rows_4)r   NZ#html_repr_max_rows_12_min_rows_None)rx   r   Z!html_repr_max_rows_10_min_rows_12)Nr   Z#html_repr_max_rows_None_min_rows_12c          	   C   sN   t dtdi}t| |}td|d| | }W d Q R X ||ksJtd S )NrB   r   zdisplay.max_rowszdisplay.min_rows)r   r   rl   r   r   r   r<   )r   rz   Zmin_rowsrY   r+   r>   r   r   r   test_html_repr_min_rows"  s
    
r   )Tr   r
   r   r4   numpyr#   rM   r   r   r   r   r   r   Zpandas._testingZ_testingr&   Zpandas.io.formats.formatr   r   r   r   r   Zfixturer,   Z_VALID_JUSTIFY_PARAMETERSr-   markZparametrizerA   rQ   rT   rX   r'   rZ   r_   rb   dictrg   ro   ru   r{   to_datetimer   r   r   r   r   r   r   r   r   r   r   r   r   r   ziprepeatmodrl   r   r   r   r   r   r   r   r   rm   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s>  
	




		$
"
'  
 


