a
    d                  	   @   sh  d dl mZ d dlmZ d dlmZmZ d dlZd dlm	Z	 d dl
Z
d dlZd dlmZ d dlZd dl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mZmZm Z m!Z! d dl"m#Z$ d d	l%m&Z&m'Z' d d
l(m)Z) ej*g dddd Z+dd Z,dd Z-dd Z.dd Z/ej01dej2de3de3dgdej2de3ddgG dd dZ4dS )    )Iterator)partial)BytesIOStringION)Path)URLError)is_platform_windows)	NA	DataFrame
MultiIndexSeries	Timestamp
date_rangeread_csv	read_htmlto_datetime)ArrowStringArrayStringArray)file_path_to_url)zchinese_utf-16.htmlzchinese_utf-32.htmlzchinese_utf-8.htmlzletz_latin1.html)paramsc                 C   s   |ddd| j S )z6Parametrized fixture for HTML encoding test filenames.iodataZhtml_encoding)param)requestdatapath r   b/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pandas/tests/io/test_html.pyhtml_encoding_file(   s    
r   c                 O   s   t | t |ks,J dt |  dt | d}ttdd | |}|sPJ |t| |D ]0\}}tj||g|R i | |jrZJ dqZd S )Nz*lists are not of equal size len(list1) == z, len(list2) == z$not all list elements are DataFramesc                 S   s   t | tot |tS N)
isinstancer
   )xyr   r   r   <lambda>>       z(assert_framelist_equal.<locals>.<lambda>zframes are both empty)lenallmapziptmassert_frame_equalempty)Zlist1Zlist2argskwargsmsgZboth_framesZframe_iZframe_jr   r   r   assert_framelist_equal5   s&    r.   c                 C   sj   t d}t d | |dd t jtdd& t|ddd	d
dd W d    n1 s\0    Y  d S )Nbs4html5lib__version__z4.2zPandas requires versionmatchr   r   html	spam.htmlflavor)pytestimportorskipsetattrraisesImportErrorr   )Zmonkeypatchr   r/   r   r   r   test_bs4_version_failsI   s
    

r=   c                  C   sX   d} d}d| d }t jt|d" tt| d|d W d    n1 sJ0    Y  d S )Nz
google.comzinvalid flavorz\{z \} is not a valid set of flavorsr2   googler3   r7   )r8   r;   
ValueErrorr   r   )urlr7   r-   r   r   r   test_invalid_flavorR   s
    rB   c                 C   sZ   t d t d t d | dddd}t|ddgd	}t|ddgd	}t|| d S )
Nr/   lxmlr0   r   r   r4   valid_markup.htmlr   )	index_colr7   )r8   r9   r   r.   )r   filenameZdfs_lxmlZdfs_bs4r   r   r   test_same_ordering[   s    


rG   r7   r/   r0   )ZmarksrC   c                   @   sL  e Zd Zdd Zejdd Zejdd Zejddd	d
 Zdd Z	dd Z
ejjejjdd Zejjejjdd Zejj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/d0 Zd1d2 Z d3d4 Z!d5d6 Z"d7d8 Z#d9d: Z$d;d< Z%ejjejjd=d> Z&ejjejjejjd?d@ Z'ejjdAdB Z(ejjdCdD Z)dEdF Z*ejjdGdH Z+ejjdIdJ Z,ejjdKdL Z-ejjdMdN Z.ejjdOdP Z/ejjdQdR Z0ejjdSdT Z1dUdV Z2ejdWdX Z3ejjejjdYdZ Z4ejjejjd[d\ Z5d]d^ Z6d_d` Z7dadb Z8dcdd Z9dedf Z:dgdh Z;ejjdidj Z<ejjdkdl Z=dmdn Z>dodp Z?dqdr Z@dsdt ZAdudv ZBdwdx ZCdydz ZDd{d| ZEd}d~ ZFdd ZGdd ZHdd ZIdd ZJejKdddgdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSejjdd ZTdd ZUdd ZVejKddeWdgdfdeWdgeWdgfgdd ZXejKdddgdd ZYejZddd Z[dd Z\dd Z]ejjejjdd Z^dd Z_dd Z`ejKdg ddd Zadd Zbdd Zcdd Zddd ZedS )TestReadHtmlc                 C   s@   d}t jt|d | d W d    n1 s20    Y  d S )NzPassing literal html to 'read_html' is deprecated and will be removed in a future version. To read from a literal string, wrap it in a 'StringIO' object.r2   a  <table>
                <thead>
                    <tr>
                        <th>A</th>
                        <th>B</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>1</td>
                        <td>2</td>
                    </tr>
                </tbody>
                <tbody>
                    <tr>
                        <td>3</td>
                        <td>4</td>
                    </tr>
                </tbody>
            </table>)r(   Zassert_produces_warningFutureWarningr   selfr-   r   r   r   test_literal_html_deprecationn   s    z*TestReadHtml.test_literal_html_deprecationc                 C   s   |ddddS )Nr   r   r4   r5   r   rK   r   r   r   r   	spam_data   s    zTestReadHtml.spam_datac                 C   s   |ddddS )Nr   r   r4   banklist.htmlr   rM   r   r   r   banklist_data   s    zTestReadHtml.banklist_dataT)Zautousec                 c   s   t t|d| _d V  d S )Nr6   )r   r   )rK   r7   r   r   r   set_defaults   s    zTestReadHtml.set_defaultsc                 C   sZ   t jdddd ddddjt}| }| jt|dd	id
dd
 }t 	|| d S )N      c                  W   s   t jd S )N   )nprandomdefault_rng)r+   r   r   r   r"      r#   z2TestReadHtml.test_to_html_compat.<locals>.<lambda>F)Z
data_gen_fZc_idx_namesZr_idx_namesz{:.3f}classZ	dataframer   )attrsrE   )
r(   ZmakeCustomDataframer&   formatZastypefloatto_htmlr   r   r)   )rK   dfoutresr   r   r   test_to_html_compat   s"    z TestReadHtml.test_to_html_compatc              
      s  t tdtjdgddtg dddtdtjdgddtg d	ddg d
g dg dg dd}|dkrttjg dtjd}ttjddtgtjd}n.t	dt
g d}t
g d}|jdd}td|& | jt||dd }W d    n1 s0    Y  t tdtjdgddtg dddtdtjdgddtg d	ddtddtgddtg ddd||d|dkrdd lddlm  t  fddjD t| d S )N   rS   ZInt64)dtype)ra   rT   rS         ?      @ZFloat64)rc   g       @rd   )TFN)TFTabc)rf   rg   N)rf   rg   rh   defghpythonrf   rg   pyarrowFindexzmode.string_storagedtype_backendr   Tboolean)ArrowExtensionArrayc                    s$   i | ]}| j | d dqS )T)Zfrom_pandas)array).0colru   expectedpar   r   
<dictcomp>   s   z3TestReadHtml.test_dtype_backend.<locals>.<dictcomp>)r
   r   rU   nanr   rv   Zobject_r	   r8   r9   r   r\   pdZoption_contextr   r   ro   Zpandas.arraysru   columnsr(   r)   )rK   Zstring_storagers   r]   Zstring_arrayZstring_array_nar^   resultr   ry   r   test_dtype_backend   sP    
6
zTestReadHtml.test_dtype_backendc                 C   sj   t |dd@}|j| d | j|jdd}| j|jdd}W d    n1 sR0    Y  t|| d S )Nutf-8encodingcontentFirst Federal Bank of Floridar2   Metcalf Bankopenserve_contentreadr   rA   r.   )rK   
httpserverrP   rk   df1df2r   r   r   test_banklist_url   s    $zTestReadHtml.test_banklist_urlc                 C   sj   t |dd@}|j| d | j|jdd}| j|jdd}W d    n1 sR0    Y  t|| d S )Nr   r   r   	.*Water.*r2   Unitr   )rK   r   rN   rk   r   r   r   r   r   test_spam_url   s
    .zTestReadHtml.test_spam_urlc                 C   s6   | j |dddid}| j |dddid}t|| d S )Nz.*Florida.*idtabler3   rY   r   r   r.   )rK   rP   r   r   r   r   r   test_banklist   s    zTestReadHtml.test_banklistc                 C   sV   | j |dd}| j |dd}t|| |d jd dks<J |d jd dksRJ d S )Nr   r2   r   r   r   r   
ProximatesZNutrient)r   r.   ilocr   rK   rN   r   r   r   r   r   	test_spam  s
    
zTestReadHtml.test_spamc                 C   s&   |  |}|D ]}t|tsJ qd S r   r   r   r
   )rK   rN   dfsr]   r   r   r   test_spam_no_match  s    
zTestReadHtml.test_spam_no_matchc                 C   s.   | j |ddid}|D ]}t|tsJ qd S )Nr   r   )rY   r   )rK   rP   r   r]   r   r   r   test_banklist_no_match  s    z#TestReadHtml.test_banklist_no_matchc                 C   s4   | j |dddd }|jd dks&J |jr0J d S )Nr   rT   r3   headerr   r   )r   r   r*   )rK   rN   r]   r   r   r   test_spam_header  s    zTestReadHtml.test_spam_headerc                 C   s.   | j |ddd}| j |ddd}t|| d S Nr   ra   r3   skiprowsr   r   r   r   r   r   test_skiprows_int  s    zTestReadHtml.test_skiprows_intc                 C   s6   | j |dtdd}| j |dtdd}t|| d S Nr   rT   r   r   )r   ranger.   r   r   r   r   test_skiprows_range$  s    z TestReadHtml.test_skiprows_rangec                 C   s6   | j |dddgd}| j |dddgd}t|| d S Nr   ra   rT   r   r   r   r   r   r   r   test_skiprows_list*  s    zTestReadHtml.test_skiprows_listc                 C   s6   | j |dddhd}| j |dddhd}t|| d S r   r   r   r   r   r   test_skiprows_set0  s    zTestReadHtml.test_skiprows_setc                 C   s.   | j |ddd}| j |ddd}t|| d S r   r   r   r   r   r   test_skiprows_slice6  s    z TestReadHtml.test_skiprows_slicec                 C   s6   | j |dtdd}| j |dtdd}t|| d S r   r   slicer.   r   r   r   r   test_skiprows_slice_short<  s    z&TestReadHtml.test_skiprows_slice_shortc                 C   s<   | j |dtddd}| j |dtdddd}t|| d S )	Nr   rT      r   r   rR   ra   r   r   r   r   r   test_skiprows_slice_longB  s    z%TestReadHtml.test_skiprows_slice_longc                 C   s:   | j |dtdd}| j |dtdd}t|| d S r   )r   rU   Zaranger.   r   r   r   r   test_skiprows_ndarrayH  s    z"TestReadHtml.test_skiprows_ndarrayc                 C   sB   t jtdd  | j|ddd W d    n1 s40    Y  d S )Nz%is not a valid type for skipping rowsr2   r   Zasdfr   )r8   r;   	TypeErrorr   )rK   rN   r   r   r   test_skiprows_invalidN  s    z"TestReadHtml.test_skiprows_invalidc                 C   s.   | j |ddd}| j |ddd}t|| d S Nr   r   r3   rE   r   r   r   r   r   r   
test_indexR  s    zTestReadHtml.test_indexc                 C   s2   | j |dddd}| j |dddd}t|| d S Nr   ra   r   )r3   r   rE   r   r   r   r   r   r   test_header_and_index_no_typesW  s    z+TestReadHtml.test_header_and_index_no_typesc                 C   s2   | j |dddd}| j |dddd}t|| d S r   r   r   r   r   r    test_header_and_index_with_types\  s    z-TestReadHtml.test_header_and_index_with_typesc                 C   s.   | j |ddd}| j |ddd}t|| d S r   r   r   r   r   r   test_infer_typesa  s    zTestReadHtml.test_infer_typesc                 C   s   t |dd}t| }W d    n1 s.0    Y  t |dd}t| }W d    n1 sf0    Y  | j|dd}| j|dd}t|| d S NzUTF-8r   r   r2   r   )r   r   r   r   r.   )rK   rN   rk   data1data2r   r   r   r   r   test_string_iog  s    **zTestReadHtml.test_string_ioc                 C   sf   t |dd}| }W d    n1 s*0    Y  | jt|dd}| jt|dd}t|| d S r   )r   r   r   r   r.   )rK   rN   rk   r   r   r   r   r   r   test_stringr  s
    &zTestReadHtml.test_stringc                 C   s   t |dd}| j|dd}W d    n1 s00    Y  t |dd}| j|dd}W d    n1 sj0    Y  t|| d S r   )r   r   r.   )rK   rN   rk   r   r   r   r   r   test_file_like{  s
    ,,zTestReadHtml.test_file_likec                 C   sN   |j ddd tjtdd | jddd W d    n1 s@0    Y  d S )Nz#urlopen error unknown url type: git  coder2   zgit://github.comr   )r   r8   r;   r   r   rK   r   r   r   r   test_bad_url_protocol  s    z"TestReadHtml.test_bad_url_protocolc                 C   sT   |j ddd tjttfdd  | j|jdd W d    n1 sF0    Y  d S )NzName or service not knownr   r   zHTTP Error 404: NOT FOUNDr2   r   )r   r8   r;   r   r@   r   rA   r   r   r   r   test_invalid_url  s    zTestReadHtml.test_invalid_urlc                 C   sN   |}| j ttj|dddid}t|ts2J |D ]}t|ts6J q6d S )NZFirstr   r   r   )r   r   ospathabspathr   listr
   rK   rP   rA   r   r]   r   r   r   test_file_url  s    zTestReadHtml.test_file_urlc                 C   sJ   |}t jtdd$ | j|dddid W d    n1 s<0    Y  d S )NzNo tables foundr2   r   r   Z	tasdfabler   r8   r;   r@   r   )rK   rP   rA   r   r   r   test_invalid_table_attrs  s
    
z%TestReadHtml.test_invalid_table_attrsc                 K   s   | j |fdddid|S )NMetcalfr   r   r   r   )rK   r   r,   r   r   r   
_bank_data  s    zTestReadHtml._bank_datac                 C   s*   | j |ddgdd }t|jts&J d S )Nr   ra   r   r   r   r   r   rK   rP   r]   r   r   r   test_multiindex_header  s    z#TestReadHtml.test_multiindex_headerc                 C   s*   | j |ddgdd }t|jts&J d S )Nr   ra   rE   )r   r   rq   r   r   r   r   r   test_multiindex_index  s    z"TestReadHtml.test_multiindex_indexc                 C   s@   | j |ddgddgdd }t|jts,J t|jts<J d S )Nr   ra   )r   rE   )r   r   r   r   rq   r   r   r   r   test_multiindex_header_index  s    z)TestReadHtml.test_multiindex_header_indexc                 C   s,   | j |ddgddd }t|jts(J d S Nr   ra   )r   r   r   r   r   r   r   &test_multiindex_header_skiprows_tuples  s    z3TestReadHtml.test_multiindex_header_skiprows_tuplesc                 C   s,   | j |ddgddd }t|jts(J d S r   r   r   r   r   r   test_multiindex_header_skiprows  s    z,TestReadHtml.test_multiindex_header_skiprowsc                 C   sB   | j |ddgddgddd }t|jts.J t|jts>J d S )Nr   ra   )r   rE   r   )r   r   rq   r   r   r   r   r   r   %test_multiindex_header_index_skiprows  s    z2TestReadHtml.test_multiindex_header_index_skiprowsc                 C   sZ   |}| j ttj|ttdddid}t|ts>J |D ]}t|t	sBJ qBd S )NZFloridar   r   r   )
r   r   r   r   r   recompiler   r   r
   r   r   r   r   test_regex_idempotency  s    z#TestReadHtml.test_regex_idempotencyc                 C   sF   d}t jt|d  | j|ddd W d    n1 s80    Y  d S )Nz\(you passed a negative value\)r2   ZWaterr   r   r   rK   rN   r-   r   r   r   test_negative_skiprows  s    z#TestReadHtml.test_negative_skiprowsc                 C   s   dS )Naf  
          <table class="contentstable" align="center"><tr>
            <td width="50%">
            <p class="biglink"><a class="biglink" href="whatsnew/2.7.html">What's new in Python 2.7?</a><br/>
                <span class="linkdescr">or <a href="whatsnew/index.html">all "What's new" documents</a> since 2.0</span></p>
            <p class="biglink"><a class="biglink" href="tutorial/index.html">Tutorial</a><br/>
                <span class="linkdescr">start here</span></p>
            <p class="biglink"><a class="biglink" href="library/index.html">Library Reference</a><br/>
                <span class="linkdescr">keep this under your pillow</span></p>
            <p class="biglink"><a class="biglink" href="reference/index.html">Language Reference</a><br/>
                <span class="linkdescr">describes syntax and language elements</span></p>
            <p class="biglink"><a class="biglink" href="using/index.html">Python Setup and Usage</a><br/>
                <span class="linkdescr">how to use Python on different platforms</span></p>
            <p class="biglink"><a class="biglink" href="howto/index.html">Python HOWTOs</a><br/>
                <span class="linkdescr">in-depth documents on specific topics</span></p>
            </td><td width="50%">
            <p class="biglink"><a class="biglink" href="installing/index.html">Installing Python Modules</a><br/>
                <span class="linkdescr">installing from the Python Package Index &amp; other sources</span></p>
            <p class="biglink"><a class="biglink" href="distributing/index.html">Distributing Python Modules</a><br/>
                <span class="linkdescr">publishing modules for installation by others</span></p>
            <p class="biglink"><a class="biglink" href="extending/index.html">Extending and Embedding</a><br/>
                <span class="linkdescr">tutorial for C/C++ programmers</span></p>
            <p class="biglink"><a class="biglink" href="c-api/index.html">Python/C API</a><br/>
                <span class="linkdescr">reference for C/C++ programmers</span></p>
            <p class="biglink"><a class="biglink" href="faq/index.html">FAQs</a><br/>
                <span class="linkdescr">frequently asked questions (with answers!)</span></p>
            </td></tr>
        </table>

        <p><strong>Indices and tables:</strong></p>
        <table class="contentstable" align="center"><tr>
            <td width="50%">
            <p class="biglink"><a class="biglink" href="py-modindex.html">Python Global Module Index</a><br/>
                <span class="linkdescr">quick access to all modules</span></p>
            <p class="biglink"><a class="biglink" href="genindex.html">General Index</a><br/>
                <span class="linkdescr">all functions, classes, terms</span></p>
            <p class="biglink"><a class="biglink" href="glossary.html">Glossary</a><br/>
                <span class="linkdescr">the most important terms explained</span></p>
            </td><td width="50%">
            <p class="biglink"><a class="biglink" href="search.html">Search page</a><br/>
                <span class="linkdescr">search this documentation</span></p>
            <p class="biglink"><a class="biglink" href="contents.html">Complete Table of Contents</a><br/>
                <span class="linkdescr">lists all sections and subsections</span></p>
            </td></tr>
        </table>
        r   rK   r   r   r   python_docs  s    zTestReadHtml.python_docsc                 C   s0   |j |d | j|jdd}t|dks,J d S )Nr   Pythonr2   ra   )r   r   rA   r$   )rK   r   r   r   r   r   r   test_multiple_matches  s    z"TestReadHtml.test_multiple_matchesc                 C   sB   |j |d | j|jdd}dd |D }t|ddgks>J d S )Nr   r   r2   c                 S   s   g | ]}|j d  dd qS )r   r   rR   )r   )rw   r]   r   r   r   
<listcomp>  r#   z7TestReadHtml.test_python_docs_table.<locals>.<listcomp>ZPythZWhat)r   r   rA   sorted)rK   r   r   r   zzr   r   r   test_python_docs_table  s    z#TestReadHtml.test_python_docs_tablec                 C   s&   d}|  t|}t|dks"J dS )z@
        Make sure that read_html ignores empty tables.
        a  
            <table>
                <thead>
                    <tr>
                        <th>A</th>
                        <th>B</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>1</td>
                        <td>2</td>
                    </tr>
                </tbody>
            </table>
            <table>
                <tbody>
                </tbody>
            </table>
        ra   N)r   r   r$   )rK   r4   r   r   r   r   test_empty_tables  s    zTestReadHtml.test_empty_tablesc                 C   s>   |  tdd }tddgddggddgd	}t|| d S )
Na  <table>
            <thead>
                <tr>
                    <th>A</th>
                    <th>B</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>1</td>
                    <td>2</td>
                </tr>
            </tbody>
            <tbody>
                <tr>
                    <td>3</td>
                    <td>4</td>
                </tr>
            </tbody>
        </table>r   ra   rT   rS   rR   ABr   r   r   r   r
   r(   r)   rK   r   rz   r   r   r   test_multiple_tbody6  s    z TestReadHtml.test_multiple_tbodyc                 C   s4   |  tdd }tddidgd}t|| dS )zt
        Don't fail with bs4 when there is a header and only one column
        as described in issue #9178
        a3  <table>
                <thead>
                    <tr>
                        <th>Header</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>first</td>
                    </tr>
                </tbody>
            </table>r   Headerfirstr   rq   Nr   r   r   r   r   test_header_and_one_columnV  s    z'TestReadHtml.test_header_and_one_columnc                 C   s8   |  tdd }tg dgg dd}t|| dS )zK
        Ensure parser adds <tr> within <thead> on malformed HTML.
        a  <table>
            <thead>
                <tr>
                    <th>Country</th>
                    <th>Municipality</th>
                    <th>Year</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Ukraine</td>
                    <th>Odessa</th>
                    <td>1944</td>
                </tr>
            </tbody>
        </table>r   )ZUkraineZOdessa  )ZCountryZMunicipalityZYearr   Nr   r   r   r   r   test_thead_without_trp  s    z"TestReadHtml.test_thead_without_trc                 C   s   d}t ddggddgd}t ddgddggddgd}|jd	d
}|jdd
}| t|d }| t|d }t|| t|| dS )zh
        Make sure that read_html reads tfoot, containing td or th.
        Ignores empty tfoot
        a  <table>
            <thead>
                <tr>
                    <th>A</th>
                    <th>B</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>bodyA</td>
                    <td>bodyB</td>
                </tr>
            </tbody>
            <tfoot>
                {footer}
            </tfoot>
        </table>ZbodyAZbodyBr   r   r   ZfootAZfootB )footerz%<tr><td>footA</td><th>footB</th></tr>r   N)r
   rZ   r   r   r(   r)   )rK   Zdata_templateZ	expected1Z	expected2r   r   Zresult1Zresult2r   r   r   test_tfoot_read  s    zTestReadHtml.test_tfoot_readc                 C   s8   | j tdddd }tddggdd}t|| d S )Na
  
            <table>
                <tr>
                    <td>S</td>
                    <td>I</td>
                </tr>
                <tr>
                    <td>text</td>
                    <td>1944</td>
                </tr>
            </table>
        r   r   textr   )SIr   r   r   r   r   r   &test_parse_header_of_non_string_column  s    z3TestReadHtml.test_parse_header_of_non_string_columnc                    s   ddl m   fdd}| j|dddidd }t|d	d
ddttdd}|j|jks\J g d}g d}||||}||}	|}
ddg}|
| t	|
|< t
|
|	 d S )Nr   _remove_whitespacec                    s&   z
 | W S  t y    |  Y S 0 d S r   )AttributeErrorr    r  r   r   try_remove_ws  s    
z8TestReadHtml.test_banklist_header.<locals>.try_remove_wsr   r   r   r   r   r   csvzbanklist.csv)Updated DateClosing Date
converters)
z,First Vietnamese American Bank In Vietnamesez"Westernbank Puerto Rico En Espanolz*R-G Premier Bank of Puerto Rico En EspanolzEurobank En EspanolzSanderson State Bank En EspanolzLWashington Mutual Bank (Including its subsidiary Washington Mutual Bank FSB)zSilver State Bank En Espanolz%AmTrade International Bank En EspanolzHamilton Bank, NA En Espanolz6The Citizens Savings Bank Pioneer Community Bank, Inc.)
zFirst Vietnamese American BankzWesternbank Puerto RicozR-G Premier Bank of Puerto RicoZEurobankzSanderson State BankzWashington Mutual BankzSilver State BankzAmTrade International BankzHamilton Bank, NAzThe Citizens Savings Bankr  r
  )Zpandas.io.htmlr  r   r   r   shaper&   replaceapplyr   r(   r)   )rK   rP   r   r  r]   Zground_trutholdnewZdfnewZgtnewZ	convertedZ	date_colsr   r  r   test_banklist_header  s     
z!TestReadHtml.test_banklist_headerc                 C   sp   d}t |dd}| }W d    n1 s.0    Y  ||v sDJ | j|dddidd }|| v slJ d S )NzGold Canyonr   r   r   r   r   r   )r   r   r   Z	to_string)rK   rP   gcrk   Zraw_textr]   r   r   r   test_gold_canyon  s    &zTestReadHtml.test_gold_canyonc                 C   s<   | j tdddd }| j tdddd }t|| d S )Na  <table>
                        <thead>
                            <tr style="text-align: right;">
                            <th></th>
                            <th>C_l0_g0</th>
                            <th>C_l0_g1</th>
                            <th>C_l0_g2</th>
                            <th>C_l0_g3</th>
                            <th>C_l0_g4</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                            <th>R_l0_g0</th>
                            <td> 0.763</td>
                            <td> 0.233</td>
                            <td> nan</td>
                            <td> nan</td>
                            <td> nan</td>
                            </tr>
                            <tr>
                            <th>R_l0_g1</th>
                            <td> 0.244</td>
                            <td> 0.285</td>
                            <td> 0.392</td>
                            <td> 0.137</td>
                            <td> 0.222</td>
                            </tr>
                        </tbody>
                    </table>r   r   a  <table>
                    <thead>
                        <tr style="text-align: right;">
                        <th></th>
                        <th>C_l0_g0</th>
                        <th>C_l0_g1</th>
                        <th>C_l0_g2</th>
                        <th>C_l0_g3</th>
                        <th>C_l0_g4</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                        <th>R_l0_g0</th>
                        <td> 0.763</td>
                        <td> 0.233</td>
                        </tr>
                        <tr>
                        <th>R_l0_g1</th>
                        <td> 0.244</td>
                        <td> 0.285</td>
                        <td> 0.392</td>
                        <td> 0.137</td>
                        <td> 0.222</td>
                        </tr>
                    </tbody>
                 </table>)r   r   r(   r)   )rK   rz   r   r   r   r   test_different_number_of_cols  s"     "$!z*TestReadHtml.test_different_number_of_colsc                 C   s8   |  tdd }tg dgg dd}t|| d S )NaZ  
            <table>
                <tr>
                    <th>A</th>
                    <th colspan="1">B</th>
                    <th rowspan="1">C</th>
                </tr>
                <tr>
                    <td>a</td>
                    <td>b</td>
                    <td>c</td>
                </tr>
            </table>
        r   re   )r   r   Cr  r   r   r   r   r   test_colspan_rowspan_1S  s    z#TestReadHtml.test_colspan_rowspan_1c                 C   s<   | j tdddd }tg dgg dd}t|| d S )Na  
            <table>
                <tr>
                    <td colspan="2">X</td>
                    <td>Y</td>
                    <td rowspan="2">Z</td>
                    <td>W</td>
                </tr>
                <tr>
                    <td>A</td>
                    <td colspan="2">B</td>
                    <td>C</td>
                </tr>
            </table>
        r   r   )r   r   r   Zr  )XzX.1Yr  Wr   r   r   r   r   r    test_colspan_rowspan_copy_valuesl  s    z-TestReadHtml.test_colspan_rowspan_copy_valuesc                 C   s<   | j tdddd }tg dgg dd}t|| d S )Na(  
            <table>
                <tr>
                    <td rowspan="2">A</td>
                    <td rowspan="2" colspan="3">B</td>
                    <td>C</td>
                </tr>
                <tr>
                    <td>D</td>
                </tr>
            </table>
        r   r   )r   r   r   r   D)r   r   zB.1zB.2r  r   r   r   r   r   r   test_colspan_rowspan_both_not_1  s    z,TestReadHtml.test_colspan_rowspan_both_not_1c                 C   s<   | j tdddd }tddggddgd}t|| d S )Nz
            <table>
                <tr>
                    <td>A</td>
                    <td rowspan="2">B</td>
                </tr>
                <tr>
                    <td>C</td>
                </tr>
            </table>
        r   r   r  r   r   r   r   r   r   r   r   test_rowspan_at_end_of_row  s    z'TestReadHtml.test_rowspan_at_end_of_rowc                 C   sB   | j tdddd }tddgddggddgd}t|| d S )Nz
            <table>
                <tr>
                    <td rowspan="3">A</td>
                    <td rowspan="3">B</td>
                </tr>
            </table>
        r   r   r   r   r   r   r   r   r   r   test_rowspan_only_rows  s    
z#TestReadHtml.test_rowspan_only_rowsc                 C   sX   |  tdd }tddgddggddgddggd}tdd	gg|d
}t|| d S )Nam  
            <table>
                <tr>
                    <th>A</th>
                    <th>B</th>
                </tr>
                <tr>
                    <th>a</th>
                    <th>b</th>
                </tr>
                <tr>
                    <td>1</td>
                    <td>2</td>
                </tr>
            </table>
        r   r   r   rf   rg   ra   levelscodesrT   r   r   r   r   r
   r(   r)   rK   r   r   rz   r   r   r   +test_header_inferred_from_rows_with_only_th  s    $z8TestReadHtml.test_header_inferred_from_rows_with_only_thc                 C   sl   t dtdddi}| }| jt|dgdd}t||d  | jt|dgdd}t||d  d S )Ndate1/1/2001
   Zperiodsra   r   Zparse_datesrE   )r
   r   r\   r   r   r(   r)   )rK   r]   rz   r_   r   r   r   test_parse_dates_list  s    z"TestReadHtml.test_parse_dates_listc                 C   sr   t tddd}t|dd |dd d}| jt| dd	d
gid	d}td|i}t||d  d S )Nr)  r*  r+  c                 S   s   t |  S r   )strr(  r  r   r   r   r"   	  r#   z7TestReadHtml.test_parse_dates_combine.<locals>.<lambda>c                 S   s   t |  S r   )r.  timer  r   r   r   r"   
  r#   )r(  r/  datetimera   rT   r,  r   )	r   r   r
   r&   r   r   r\   r(   r)   )rK   Z	raw_datesr]   r_   Znewdfr   r   r   test_parse_dates_combine  s    z%TestReadHtml.test_parse_dates_combinec                 C   s   |dddd}t j|s,J t| dt j|sJJ t| d| j|ddd	d
 }|jdkslJ d|jd v s~J |d jt	dksJ t	
|jd dsJ d S )Nr   r   r4   wikipedia_states.htmlz is not a filez is an empty fileArizonara   r   r   )<      Unnamedr   sq mifloat64)r   r7  HzPN$A)r   r   isfilereprgetsizer   r  r   rb   rU   allcloselocrK   r   r   r   r   r   r   test_wikipedia_states_table  s    z(TestReadHtml.test_wikipedia_states_tablec                 C   sp   |dddd}| j |dddd }|jdks0J d	|jd
 d v sFJ |jjdksVJ t|jd dslJ d S )Nr   r   r4   r2  r3  r   r   )r4     r6  r   ra   rT   )ZAlaska)zTotal area[2]r7  r9  )r   r  r   ZnlevelsrU   r=  r>  r?  r   r   r    test_wikipedia_states_multiindex  s    z-TestReadHtml.test_wikipedia_states_multiindexc                 C   sF   | j tdddgd}tddggtddgd	}t|d | d S )
NaK  
                <table>
                    <thead>
                        <tr><th></th><th></tr>
                        <tr><th>A</th><th>B</th></tr>
                    </thead>
                    <tbody>
                        <tr><td>a</td><td>b</td></tr>
                    </tbody>
                </table>
            r   ra   r   rf   rg   )Unnamed: 0_level_0r   )zUnnamed: 1_level_0r   r  )r   r   r
   r   from_tuplesr(   r)   r   r   r   r   %test_parser_error_on_empty_header_row%  s    z2TestReadHtml.test_parser_error_on_empty_header_rowc                 C   sP   | j tdddd }tddidgd}|d jtdks@J t|| d S )	Na  <html>
            <body>
             <table>
                <thead>
                    <tr>
                        <th>Header</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>1100#101</td>
                    </tr>
                </tbody>
            </table>
            </body>
        </html>#)decimalr   r   gClg0@r   r8  )r   r   r
   rb   rU   r(   r)   r   r   r   r   test_decimal_rows>  s    zTestReadHtml.test_decimal_rowsargFc                 C   sJ   t d}tjt|d | j||d W d    n1 s<0    Y  d S )NzPassing a bool to header is invalid. Use header=None for no header or header=int or list-like of ints to specify the row(s) making up the column namesr2   r   )r   escaper8   r;   r   r   )rK   rN   rI  r-   r   r   r   test_bool_header_arg[  s
    z!TestReadHtml.test_bool_header_argc                 C   s:   | j tddtidd }tdddgi}t|| d S )Na  <table>
                 <thead>
                   <tr>
                     <th>a</th>
                    </tr>
                 </thead>
                 <tbody>
                   <tr>
                     <td> 0.763</td>
                   </tr>
                   <tr>
                     <td> 0.244</td>
                   </tr>
                 </tbody>
               </table>rf   r  r   z0.763z0.244)r   r   r.  r
   r(   r)   r   r   r   r   test_convertersf  s    zTestReadHtml.test_convertersc                 C   s:   | j tddgdd }tddtjgi}t|| d S )Na  <table>
                 <thead>
                   <tr>
                     <th>a</th>
                   </tr>
                 </thead>
                 <tbody>
                   <tr>
                     <td> 0.763</td>
                   </tr>
                   <tr>
                     <td> 0.244</td>
                   </tr>
                 </tbody>
               </table>gZd;?)Z	na_valuesr   rf   g"~j?r   r   r
   rU   r}   r(   r)   r   r   r   r   test_na_values  s    zTestReadHtml.test_na_valuesc                 C   sp   d}t dddgi}| jt|ddd }t|| t dtjtjgi}| jt|ddd }t|| d S )	Na  <table>
                        <thead>
                            <tr>
                            <th>a</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                            <td> N/A</td>
                            </tr>
                            <tr>
                            <td> NA</td>
                            </tr>
                        </tbody>
                    </table>rf   zN/Ar	   F)Zkeep_default_nar   T)r
   r   r   r(   r)   rU   r}   )rK   Z	html_dataexpected_dfhtml_dfr   r   r   test_keep_default_na  s    z!TestReadHtml.test_keep_default_nac                 C   sB   |  tdd }tddgtjtjggddgd}t|| d S )Nak  
            <table>
                <tr>
                    <th>A</th>
                    <th>B</th>
                </tr>
                <tr>
                    <td>a</td>
                    <td>b</td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                </tr>
            </table>
        r   rf   rg   r   r   r   rM  r   r   r   r   test_preserve_empty_rows  s     z%TestReadHtml.test_preserve_empty_rowsc                 C   sX   |  tdd }tddgddggddgddggd}tdd	gg|d
}t|| d S )NaU  
            <table>
                <thead>
                    <tr><th></th><th></tr>
                    <tr><th>A</th><th>B</th></tr>
                    <tr><th>a</th><th>b</th></tr>
                </thead>
                <tbody>
                    <tr><td>1</td><td>2</td></tr>
                </tbody>
            </table>
        r   r   r   rf   rg   ra   r"  rT   r   r%  r&  r   r   r   ,test_ignore_empty_rows_when_inferring_header  s    $z9TestReadHtml.test_ignore_empty_rows_when_inferring_headerc                 C   sN   t g dd}g dg dg|_|jdd}| t|d }t|| d S )N))ZHillaryD   r  )ZBernieJ   r  )ZDonaldE   R)r   )rC  ZAgeZParty)NamezUnnamed: 1_level_1zUnnamed: 2_level_1Frp   r   )r
   r   r\   r   r   r(   r)   )rK   rO  r4   rP  r   r   r   test_multiple_header_rows  s    z&TestReadHtml.test_multiple_header_rowsc                 C   s@   |dddd}| j |dd}t|ts*J t|d ts<J d S )Nr   r   r4   rD   r   r   )r   r   r   r
   )rK   r   rF   r   r   r   r   test_works_on_valid_markup  s    z'TestReadHtml.test_works_on_valid_markupc                 C   s&   |dddd}| j |dddgd d S )	Nr   r   r4   rO   r   rC   r0   r?   r   )rK   r   rP   r   r   r   test_fallback_success  s    z"TestReadHtml.test_fallback_successc                 C   s>   t ddd}ttjdd|d}| }d|v s:J d S )Nz
2000-01-01r*  r+  rT   )r*  rR   rp   )r   r
   rU   rV   rW   Zstandard_normalr\   )rK   rngr]   r   r   r   r   test_to_html_timestamp  s    z#TestReadHtml.test_to_html_timestampc                 C   s   t dddg}| }|jdd}|jdd}|jdd}|jdd}|jdd}d|v s`J ||kslJ ||ksxJ ||ksJ d	|v sJ d
|vsJ d|vsJ ||ksJ d S )Nra   rT   r   r   T)Zborderr   Fz border="1"z border="2"z border="0"z border)r
   r\   )rK   r]   Zout_border_defaultZout_border_trueZout_border_explicit_defaultZout_border_nondefaultZout_border_zeroZout_border_falser   r   r   test_to_html_borderless  s    z$TestReadHtml.test_to_html_borderlesszdisplayed_only,exp0,exp1ZfooNzfoo  bar  baz  quxc                 C   sT   d}| j t||d}t|d | |d ur@t|d | nt|dksPJ d S )Na  <html>
          <body>
            <table>
              <tr>
                <td>
                  foo
                  <span style="display:none;text-align:center">bar</span>
                  <span style="display:none">baz</span>
                  <span style="display: none">qux</span>
                </td>
              </tr>
            </table>
            <table style="display: none">
              <tr>
                <td>foo</td>
              </tr>
            </table>
          </body>
        </html>displayed_onlyr   ra   )r   r   r(   r)   r$   )rK   ra  Zexp0Zexp1r   r   r   r   r   test_displayed_only  s    	z TestReadHtml.test_displayed_onlyra  c                 C   s>   d}t t||dd }tddgddgd}t|| d S )	NaW  
        <table>
            <tr>
                <th>A</th>
                <th>B</th>
            </tr>
            <tr>
                <td>1</td>
                <td>2</td>
            </tr>
            <tr>
                <td><span style="display:none"></span>4</td>
                <td>5</td>
            </tr>
        </table>
        r`  r   ra   rR   rT   r   r^  r   )rK   ra  Z
html_tabler   rz   r   r   r   &test_displayed_only_with_many_elements>  s    z3TestReadHtml.test_displayed_only_with_many_elementsz\ignore:You provided Unicode markup but also provided a value for from_encoding.*:UserWarningc           
      C   s"  t j|}t j|d }|d\}}zt|d(}| j| |dd }W d    n1 sd0    Y  t|d,}| jt	| |dd }W d    n1 s0    Y  | j||dd }	t
|| t
||	 W n: ty   t rd|v sd|v rt   Y n0 d S )Nr   _rb)r   rE   Z16Z32)r   r   basenamesplitextsplitr   r   r   popr   r(   r)   	Exceptionr   r8   skip)
rK   r   	base_pathrootrd  r   fobjZfrom_stringZfrom_file_likefrom_filenamer   r   r   test_encodeT  s,    
((
zTestReadHtml.test_encodec                 C   s~   | j jddkrtd G dd dt}|d}|  |sBJ tjtdd |  | W d    n1 sp0    Y  d S )	Nr7   rC   zNot applicable for lxmlc                   @   s   e Zd Zdd ZdS )zFTestReadHtml.test_parse_failure_unseekable.<locals>.UnseekableStringIOc                 S   s   dS NFr   r   r   r   r   seekable{  s    zOTestReadHtml.test_parse_failure_unseekable.<locals>.UnseekableStringIO.seekableN)__name__
__module____qualname__rr  r   r   r   r   UnseekableStringIOz  s   rv  z?
            <table><tr><td>spam<foobr />eggs</td></tr></table>z#passed a non-rewindable file objectr2   )r   keywordsgetr8   rk  r   r;   r@   )rK   rv  badr   r   r   test_parse_failure_unseekablet  s    
z*TestReadHtml.test_parse_failure_unseekablec                 C   s>   G dd d}|d}|d}|  |s,J |  |s:J d S )Nc                   @   sJ   e Zd ZddddZdddZdd Zd	d
 Zdd ZedddZ	dS )z9TestReadHtml.test_parse_failure_rewinds.<locals>.MockFileN)returnc                 S   s   || _ d| _d S rq  )r   at_end)rK   r   r   r   r   __init__  s    zBTestReadHtml.test_parse_failure_rewinds.<locals>.MockFile.__init__c                 S   s   | j r
dn| j}d| _ |S )Nr   T)r|  r   )rK   sizer   r   r   r   r     s    z>TestReadHtml.test_parse_failure_rewinds.<locals>.MockFile.readc                 S   s
   d| _ d S rq  )r|  )rK   offsetr   r   r   seek  s    z>TestReadHtml.test_parse_failure_rewinds.<locals>.MockFile.seekc                 S   s   dS )NTr   r   r   r   r   rr    s    zBTestReadHtml.test_parse_failure_rewinds.<locals>.MockFile.seekablec                 S   s   d S r   r   r   r   r   r   __next__  s    zBTestReadHtml.test_parse_failure_rewinds.<locals>.MockFile.__next__c                 S   s   | S r   r   r   r   r   r   __iter__  s    zBTestReadHtml.test_parse_failure_rewinds.<locals>.MockFile.__iter__)N)
rs  rt  ru  r}  r   r  rr  r  r   r  r   r   r   r   MockFile  s   
r  z/<table><tr><td>spam<br />eggs</td></tr></table>z2<table><tr><td>spam<foobr />eggs</td></tr></table>r   )rK   r  Zgoodry  r   r   r   test_parse_failure_rewinds  s
    z'TestReadHtml.test_parse_failure_rewindsc                 C   s   G dd dt j}|dddd}|| j|fd}|| j|fd}|  |  | sP| rbqPd |j  u rz|ju sn J d S )Nc                       s   e Zd Z fddZ  ZS )z@TestReadHtml.test_importcheck_thread_safety.<locals>.ErrorThreadc              
      sD   zt    W n* ty8 } z|| _W Y d }~nd }~0 0 d | _d S r   )superrunrj  err)rK   r  	__class__r   r   r    s
    zDTestReadHtml.test_importcheck_thread_safety.<locals>.ErrorThread.run)rs  rt  ru  r  __classcell__r   r   r  r   ErrorThread  s   r  r   r   r4   rD   )targetr+   )	threadingThreadr   startis_aliver  )rK   r   r  rF   Zhelper_thread1Zhelper_thread2r   r   r   test_importcheck_thread_safety  s    	z+TestReadHtml.test_importcheck_thread_safetyc                 C   sB   |dddd}t |}| |d }| |d }t|| d S )Nr   r   r4   r5   r   )r   r   r(   r)   )rK   r   Zfile_path_string	file_pathr   r   r   r   r   test_parse_path_object  s
    z#TestReadHtml.test_parse_path_objectc                 C   s4   |  tdd }tdggdgd}t|| d S )Nz
            <table>
                <tr>
                    <th>A</th>
                </tr>
                <tr>
                    <td>word1<br>word2</td>
                </tr>
            </table>
        r   zword1 word2r   r   r   r   r   r   r   test_parse_br_as_space  s    z#TestReadHtml.test_parse_br_as_space)r%   bodyr   r   c           	      C   s   d}g dg dg dg dg dg dd}|d	 }|d
 }|d }|dkrh|d }|d }|d }n4|dkrz|d }n"|dkr|d }n|dkr|d }| j t||dd }t||g|d}|tj}t|| d S )Na  
          <table>
            <tr>
              <th>HTTP</th>
              <th>FTP</th>
              <th><a href="https://en.wiktionary.org/wiki/linkless">Linkless</a></th>
            </tr>
            <tr>
              <td><a href="https://en.wikipedia.org/">Wikipedia</a></td>
              <td>SURROUNDING <a href="ftp://ftp.us.debian.org/">Debian</a> TEXT</td>
              <td>Linkless</td>
            </tr>
            <tfoot>
              <tr>
                <td><a href="https://en.wikipedia.org/wiki/Page_footer">Footer</a></td>
                <td>
                  Multiple <a href="1">links:</a> <a href="2">Only first captured.</a>
                </td>
              </tr>
            </tfoot>
          </table>
          )HTTPFTPLinkless))r  N)r  N)r  z'https://en.wiktionary.org/wiki/linkless)	WikipediaSURROUNDING Debian TEXTr  ))r  zhttps://en.wikipedia.org/)r  zftp://ftp.us.debian.org/)r  N)Footer$Multiple links: Only first captured.N))r  z)https://en.wikipedia.org/wiki/Page_footer)r  1N)head_ignorehead_extractbody_ignorebody_extractfooter_ignorefooter_extractr  r  r  r%   r  r  r  r  r   r   Zextract_linksr   r  )r   r   r
   ZfillnarU   r}   r(   r)   )	rK   rI  Zgh_13141_dataZgh_13141_expectedZdata_expZfoot_expZhead_expr   rz   r   r   r   test_extract_links  s2    


zTestReadHtml.test_extract_linksc                 C   sB   d}t jt|d t|dd W d    n1 s40    Y  d S )NzY`extract_links` must be one of {None, "header", "footer", "body", "all"}, got "incorrect"r2   Z	incorrectr  r   r   r   r   r   test_extract_links_bad%  s    z#TestReadHtml.test_extract_links_badc                 C   s6   d}| j t|ddd }tdgg}t|| d S )Nz
        <table>
          <tr>
            <td>
              <a href='https://google.com'>Google.com</a>
            </td>
          </tr>
        </table>
        r%   r  r   )z
Google.comzhttps://google.comr   rK   r   r   rz   r   r   r    test_extract_links_all_no_header-  s    	z-TestReadHtml.test_extract_links_all_no_headerc                 C   sB   d}t jt|d tddd W d    n1 s40    Y  d S )NzPdtype_backend numpy is invalid, only 'numpy_nullable' and 'pyarrow' are allowed.r2   testnumpyrr   r   rJ   r   r   r   test_invalid_dtype_backend<  s    z'TestReadHtml.test_invalid_dtype_backendc                 C   sB   d}|  t|d }tddgddggddgd	}t|| d S )
Na  
        <table>
            <tr>
                <th>
                    <style>.style</style>
                    A
                    </th>
                <th>B</th>
            </tr>
            <tr>
                <td>A1</td>
                <td>B1</td>
            </tr>
            <tr>
                <td>A2</td>
                <td>B2</td>
            </tr>
        </table>
        r   A1ZB1A2ZB2r   r   r   r   r  r   r   r   test_style_tagD  s    zTestReadHtml.test_style_tag)frs  rt  ru  rL   r8   fixturerN   rP   rQ   r`   r   marknetworkZ
single_cpur   r   Zslowr   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   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r   r!  r'  r-  r1  r@  rB  rE  rH  parametrizerK  rL  rN  rQ  rR  rS  rY  rZ  r[  r]  r_  r
   rb  rc  filterwarningsrp  rz  r  r  r  r  r  r  r  r  r  r   r   r   r   rH   f   s   



7
		
	








0  &
/
H# 






"
DrH   )5collections.abcr   	functoolsr   r   r   r   r   pathlibr   r   r  urllib.errorr   r  rU   r8   Zpandas.compatr   Zpandas.util._test_decoratorsutilZ_test_decoratorstdZpandasr~   r	   r
   r   r   r   r   r   r   r   Zpandas._testingZ_testingr(   Zpandas.core.arraysr   r   Zpandas.io.commonr   r  r   r.   r=   rB   rG   r  r  r   Z
skip_if_norH   r   r   r   r   <module>   s>   ,
		